Skip to content

Commit 18c8ce2

Browse files
committed
Added Pre-Defined Scenarios and Example Scripts
- Created 4 pre-defined radar plotting scenarios - Added example - Added example with radar plot - All scenarios use consistent data format
1 parent f20d80a commit 18c8ce2

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

examples/animated_plot.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Plotting Example: Displays a radar plot solution. with matplotlib
3+
4+
Author: Omar Younis
5+
Date: 30/10/2025 [dd/mm/yyyy]
6+
"""
7+
8+
from radar_plotter.models import RadarPoint, RadarProblem
9+
from radar_plotter.solver import solver_radar_problem
10+
from radar_plotter.plotting.radar_plot import plot_radar_solution
11+
12+
13+
def main():
14+
# Defines a problem
15+
problem = RadarProblem (
16+
our_course=0.0,
17+
our_speed=10.0,
18+
maneuver_dist=5.0,
19+
new_cpa_dist=2.5,
20+
r_point=RadarPoint(45.0, 11.5, "14:00"),
21+
m_point=RadarPoint(43.0, 9.0, "14:06")
22+
)
23+
24+
# Solution to the problem
25+
solution = solver_radar_problem(problem)
26+
27+
# Plot the solution (this will display the plot with the vector arrows)
28+
plot_radar_solution(problem, solution, show=True)
29+
30+
31+
if __name__ == "__main__":
32+
main()

examples/basic_calculation.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Basic example: Calculate a radar plotting solution.
3+
4+
Author: Omar Younis
5+
Date: 30/10/2025 [dd/mm/yyyy]
6+
"""
7+
8+
from radar_plotter.models import RadarPoint, RadarProblem
9+
from radar_plotter.solver import solver_radar_problem
10+
11+
12+
def main():
13+
# Define the problem to solve
14+
problem = RadarProblem(
15+
our_course=0.0,
16+
our_speed=10.0,
17+
maneuver_dist=5.0,
18+
new_cpa_dist=2.5,
19+
r_point=RadarPoint(45.0, 11.5, "14:00"),
20+
m_point=RadarPoint(43.0, 9.0, "14:06")
21+
)
22+
23+
# Solve the problem
24+
solution = solver_radar_problem(problem)
25+
26+
# Print results
27+
print("===== Collision Avoidance Radar Plot Solution =====\n")
28+
print(f"CPA: {solution.cpa_range:.1f} NM at bearing {solution.cpa_bearing:06.2f}°")
29+
print(f"Time to CPA: {solution.cpa_time.strftime('%H:%M')}")
30+
print("\nRelative Motion:")
31+
print(f" SRM: {solution.srm:.1f} kts")
32+
print(f" DRM: {solution.drm:06.2f}°")
33+
print("\nRecommended Maneuver:")
34+
print(f" New Course: {solution.new_course:06.2f}°")
35+
print(f" New Speed: {solution.new_speed:.1f} kts")
36+
37+
38+
if __name__ == "__main__":
39+
main()

src/radar_plotter/scenarios.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Pre-defined radar plotting scenarios for testing and examples.
3+
4+
Author: Omar Younis
5+
Date: 30/10/2025 [dd/mm/yyyy]
6+
"""
7+
8+
from .models import RadarProblem, RadarPoint
9+
10+
11+
# Example scenario from the default values from the Streamlit app
12+
SCENARIO_1 = RadarProblem(
13+
our_course=0.0,
14+
our_speed=10.0,
15+
maneuver_dist=5.0,
16+
new_cpa_dist=5.0,
17+
r_point=RadarPoint(45.0, 11.5, "14:00"),
18+
m_point=RadarPoint(43.0, 9.0, "14:06")
19+
)
20+
21+
# Another scenario
22+
SCENARIO_2 = RadarProblem(
23+
our_course=90.0,
24+
our_speed=15.0,
25+
maneuver_dist=6.0,
26+
new_cpa_dist=3.0,
27+
r_point=RadarPoint(45.0, 12.0, "10:00"),
28+
m_point=RadarPoint(42.0, 9.5, "10:08")
29+
)
30+
31+
# Head-on scenario
32+
SCENARIO_3 = RadarProblem(
33+
our_course=0.0,
34+
our_speed=18.0,
35+
maneuver_dist=4.0,
36+
new_cpa_dist=2.5,
37+
r_point=RadarPoint(0.0, 10.0, "08:00"),
38+
m_point=RadarPoint(358.0, 7.5, "08:05")
39+
)
40+
41+
# Crossing bow scenario
42+
SCENARIO_4 = RadarProblem(
43+
our_course=270.0,
44+
our_speed=12.0,
45+
maneuver_dist=5.5,
46+
new_cpa_dist=3.0,
47+
r_point=RadarPoint(315.0, 8.0, "16:00"),
48+
m_point=RadarPoint(320.0, 6.0, "16:10")
49+
)
50+
51+
# List of all scenarios
52+
ALL_SCENARIOS = [SCENARIO_1, SCENARIO_2, SCENARIO_3, SCENARIO_4]

0 commit comments

Comments
 (0)