|
1 | 1 | using ControlPlots |
2 | 2 |
|
3 | | -function figure_eight_path(A, B, x0, y0, theta, num_points) |
| 3 | +function figure_eight_path(A, B, C, D, x0, y0, theta, num_points) |
4 | 4 | t = range(0, 2π, length=num_points) |
5 | | - x = A .* sin.(t) |
6 | | - y = B .* sin.(t) .* cos.(t) |
| 5 | + x = A * sin.(t) |
| 6 | + y = B * sin.(t) .* cos.(t) .+ C .* cos.(t) .+ D .* cos.(2t) |
7 | 7 | # Apply rotation |
8 | | - x_rot = x .* cos(theta) .- y .* sin(theta) |
| 8 | + x_rot = x .* cos(theta) .- y .* sin(theta) |
9 | 9 | y_rot = x .* sin(theta) .+ y .* cos(theta) |
| 10 | + y_rot = y_rot / (maximum(y_rot)/(B/2)) |
10 | 11 | # Apply translation |
11 | 12 | x_final = x_rot .+ x0 |
12 | 13 | y_final = y_rot .+ y0 |
|
16 | 17 | # Example usage: |
17 | 18 | A = 10.0 # width of the figure-eight |
18 | 19 | B = 5.0 # height of the figure-eight |
| 20 | +C = 0.0 # size of right part of the figure-eight |
| 21 | +D = -1.0 # asymmetry factor |
19 | 22 | x0 = 0.0 # center x-coordinate |
20 | 23 | y0 = 0.0 # center y-coordinate |
21 | | -theta = π/6 # rotation angle in radians |
| 24 | +theta = 0*π/6 # rotation angle in radians |
22 | 25 | num_points = 200 |
23 | 26 |
|
24 | | -x_path, y_path = figure_eight_path(A, B, x0, y0, theta, num_points) |
| 27 | +x_path, y_path = figure_eight_path(A, B, C, D, x0, y0, theta, num_points) |
25 | 28 |
|
26 | 29 | plt.figure("Figure-of-Eight Path") |
27 | 30 | ax = plt.gca() |
|
0 commit comments