Skip to content

Commit 6c228e9

Browse files
committed
Add create_flight_path.jl
1 parent 9c90c41 commit 6c228e9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/create_flightpath.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using ControlPlots
2+
3+
function figure_eight_path(A, B, x0, y0, theta, num_points)
4+
t = range(0, 2π, length=num_points)
5+
x = A .* sin.(t)
6+
y = B .* sin.(t) .* cos.(t)
7+
# Apply rotation
8+
x_rot = x .* cos(theta) .- y .* sin(theta)
9+
y_rot = x .* sin(theta) .+ y .* cos(theta)
10+
# Apply translation
11+
x_final = x_rot .+ x0
12+
y_final = y_rot .+ y0
13+
return x_final, y_final
14+
end
15+
16+
# Example usage:
17+
A = 10.0 # width of the figure-eight
18+
B = 5.0 # height of the figure-eight
19+
x0 = 0.0 # center x-coordinate
20+
y0 = 0.0 # center y-coordinate
21+
theta = π/6 # rotation angle in radians
22+
num_points = 200
23+
24+
x_path, y_path = figure_eight_path(A, B, x0, y0, theta, num_points)
25+
26+
plt.figure("Figure-of-Eight Path")
27+
ax = plt.gca()
28+
plt.plot(x_path, y_path)
29+
plt.grid(true)
30+
ax.set_aspect("equal")

0 commit comments

Comments
 (0)