Skip to content

Commit 29d796f

Browse files
author
ujinf74
committed
Release 0.2.0: add high/low arc selection
1 parent 4a234c2 commit 29d796f

File tree

13 files changed

+147
-155
lines changed

13 files changed

+147
-155
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ Thumbs.db
4949
# Python
5050
__pycache__/
5151
*.py[cod]
52-
52+
**/*.egg-info/
53+
.venv/
54+
venv/

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.16)
22

33
project(ballistic_solver
4-
VERSION 0.1.0
4+
VERSION 0.2.0
55
LANGUAGES CXX
66
)
77

@@ -25,6 +25,8 @@ add_library(ballistic_c SHARED
2525
src/ballistic_c_api.cpp
2626
)
2727

28+
target_compile_definitions(ballistic_c PRIVATE BALLISTIC_C_EXPORTS)
29+
2830
target_link_libraries(ballistic_c
2931
PRIVATE
3032
ballistic

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ This project instead **simulates the projectile** and **solves the intercept num
5959
* **Explicit success / failure reporting**
6060
* **Stable C ABI for multi-language use**
6161
* **Header-only C++ core**
62+
* **Low / High arc selection (v0.2.0)**
63+
64+
---
65+
66+
## Arc mode (v0.2.0)
67+
68+
The solver can be guided to converge to either the **low arc** or the **high arc** solution.
69+
70+
C ABI convention:
71+
72+
* `arcMode = 0` → Low
73+
* `arcMode = 1` → High
6274
6375
---
6476

examples/basic.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
#include <iostream>
2+
#include <chrono>
23
#include "ballistic/ballistic_solver.hpp"
34

5+
#ifndef M_PI
6+
#define M_PI 3.141592653589793238462643383279502884
7+
#endif
8+
49
int main()
510
{
611
// Target state relative to the projectile at t = 0
712
Vec3 relPos0 = { 100.0, 30.0, 10.0 };
8-
Vec3 relVel = { 10.0, -30.0, 0.0 };
13+
Vec3 relVel = { 5.0, -10.0, 0.0 };
914

1015
// Projectile parameters
1116
double v0 = 80.0; // initial speed magnitude
1217
double kDrag = 0.005; // drag coefficient
1318

1419
// Solver configuration
1520
BallisticParams P;
21+
P.arcMode = ArcMode::Low; // or ArcMode::High
22+
P.g = 9.80665; // gravity
1623
P.dt = 0.01; // integration step
1724
P.tMax = 20.0; // max simulation time
18-
P.tolMiss = 1e-4; // success tolerance
25+
P.tolMiss = 1e-2; // success tolerance
1926

2027
// Solve launch angles
28+
auto t0 = std::chrono::steady_clock::now();
2129
SolverResult r = solve_launch_angles(relPos0, relVel, v0, kDrag, P);
30+
auto t1 = std::chrono::steady_clock::now();
2231

2332
// Output results
2433
std::cout << "success : " << r.success << "\n";
@@ -31,5 +40,8 @@ int main()
3140
std::cout << "message : " << r.report.message
3241
<< " (status : " << static_cast<int>(r.report.status) << ")\n";
3342

43+
double ms = std::chrono::duration<double, std::milli>(t1 - t0).count();
44+
std::cout << "elapsed : " << ms << " ms\n";
45+
3446
return 0;
3547
}

examples/csharp/BallisticCSharp/BallisticCSharp.csproj renamed to examples/csharp/BallisticCSharp.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<None Include="ballistic_c.dll">
11+
<None Include="..\..\build\$(Configuration)\ballistic_c.dll">
12+
<Link>ballistic_c.dll</Link>
1213
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1314
</None>
1415
</ItemGroup>
15-
</Project>
16+
17+
</Project>

examples/csharp/BallisticCSharp/Program.cs

Lines changed: 0 additions & 76 deletions
This file was deleted.

examples/csharp/Program.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.InteropServices;
3+
using System.Text;
34

45
[StructLayout(LayoutKind.Sequential, Pack = 8)]
56
public struct BallisticInputs
@@ -13,6 +14,9 @@ public struct BallisticInputs
1314
public double v0;
1415
public double kDrag;
1516

17+
public Int32 arcMode;
18+
public double g;
19+
1620
public double dt;
1721
public double tMax;
1822
public double tolMiss;
@@ -33,19 +37,25 @@ public struct BallisticOutputs
3337
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
3438
public double[] relMissAtStar;
3539

36-
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
37-
public string message;
40+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
41+
public byte[] message;
3842
}
3943

4044
public static class BallisticNative
4145
{
42-
// Windows: ballistic_c.dll must be in the executable directory or PATH
4346
[DllImport("ballistic_c.dll", CallingConvention = CallingConvention.Cdecl)]
4447
public static extern Int32 ballistic_solve(ref BallisticInputs input, out BallisticOutputs output);
4548
}
4649

4750
public class Program
4851
{
52+
private static string CStr(byte[] bytes)
53+
{
54+
int n = Array.IndexOf(bytes, (byte)0);
55+
if (n < 0) { n = bytes.Length; }
56+
return Encoding.UTF8.GetString(bytes, 0, n);
57+
}
58+
4959
public static void Main()
5060
{
5161
var input = new BallisticInputs
@@ -54,6 +64,10 @@ public static void Main()
5464
relVel = new double[] { 2.0, -1.0, 0.0 },
5565
v0 = 90.0,
5666
kDrag = 0.002,
67+
68+
arcMode = 0, // Low
69+
g = 9.80665, // default gravity
70+
5771
dt = 0.01,
5872
tMax = 30.0,
5973
tolMiss = 0.5,
@@ -71,6 +85,6 @@ public static void Main()
7185
Console.WriteLine($"miss={output.miss}");
7286
Console.WriteLine($"tStar={output.tStar}");
7387
Console.WriteLine($"relMiss=[{output.relMissAtStar[0]}, {output.relMissAtStar[1]}, {output.relMissAtStar[2]}]");
74-
Console.WriteLine($"message={output.message}");
88+
Console.WriteLine($"message={CStr(output.message)}");
7589
}
76-
}
90+
}

include/ballistic/ballistic_c_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ typedef struct BallisticInputs
2323
double v0;
2424
double kDrag;
2525

26+
int32_t arcMode; // 0=Low, 1=High
27+
double g;
2628
double dt;
2729
double tMax;
2830
double tolMiss;

0 commit comments

Comments
 (0)