Skip to content

Commit f366a70

Browse files
committed
frenet frame
1 parent 55c0a16 commit f366a70

File tree

3 files changed

+408
-0
lines changed

3 files changed

+408
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ressources/
1818
data/*.h5
1919
venv/
2020
.venv/
21+
.conda/
2122

2223
################################
2324
########### PYTHON #############

examples/frenet_frame_ex.py

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
"""
2+
Examples demonstrating the computation and visualization of Frenet frames.
3+
4+
This module contains implementations of examples for various trajectories
5+
including helicoidal and circular paths, with and without tool orientation.
6+
"""
7+
8+
import matplotlib.pyplot as plt
9+
import numpy as np
10+
11+
from interpolatepy.frenet_frame import circular_trajectory_with_derivatives
12+
from interpolatepy.frenet_frame import compute_trajectory_frames
13+
from interpolatepy.frenet_frame import helicoidal_trajectory_with_derivatives
14+
from interpolatepy.frenet_frame import plot_frames
15+
from mpl_toolkits.mplot3d import Axes3D # noqa: F401
16+
17+
18+
def example_8_5() -> None:
19+
"""Recreate Example 8.5 using the general approach."""
20+
print("Example 8.5: Helicoidal trajectory with Frenet frames")
21+
22+
# Parameters from the example
23+
r = 2.0
24+
d = 0.5
25+
u_values = np.linspace(0, 4 * np.pi, 100)
26+
27+
# Get helicoidal trajectory function
28+
def helix_func(u: float) -> tuple:
29+
return helicoidal_trajectory_with_derivatives(u, r, d)
30+
31+
# Compute Frenet frames
32+
points, frames = compute_trajectory_frames(helix_func, u_values)
33+
34+
# Visualize
35+
fig = plt.figure(figsize=(10, 8))
36+
ax = fig.add_subplot(111, projection="3d")
37+
plot_frames(ax, points, frames, scale=0.5, skip=10)
38+
ax.set_title("Helicoidal Trajectory with Frenet Frames")
39+
ax.set_xlabel("x")
40+
ax.set_ylabel("y")
41+
ax.set_zlabel("z")
42+
ax.set_box_aspect([1, 1, 1])
43+
44+
plt.tight_layout()
45+
plt.show()
46+
47+
48+
def example_8_6() -> None:
49+
"""Recreate Example 8.6."""
50+
print("Example 8.6: Circular trajectory with tool orientation")
51+
52+
# Parameters from the example
53+
r = 2.0
54+
alpha = np.radians(30) # 30 degrees rotation about binormal axis
55+
u_values = np.linspace(0, 2 * np.pi, 100)
56+
57+
# Get circular trajectory function
58+
def circle_func(u: float) -> tuple:
59+
return circular_trajectory_with_derivatives(u, r)
60+
61+
# Compute Frenet frames
62+
points, frenet_frames = compute_trajectory_frames(circle_func, u_values)
63+
64+
# Compute tool frames with orientation alpha
65+
_, tool_frames = compute_trajectory_frames(circle_func, u_values, tool_orientation=alpha)
66+
67+
# Visualize
68+
fig = plt.figure(figsize=(12, 6))
69+
70+
# Plot Frenet frames
71+
ax1 = fig.add_subplot(121, projection="3d")
72+
plot_frames(ax1, points, frenet_frames, scale=0.5, skip=8)
73+
ax1.set_title("Circular Trajectory with Frenet Frames")
74+
ax1.set_xlabel("x")
75+
ax1.set_ylabel("y")
76+
ax1.set_zlabel("z")
77+
78+
# Plot tool frames
79+
ax2 = fig.add_subplot(122, projection="3d")
80+
plot_frames(ax2, points, tool_frames, scale=0.5, skip=8)
81+
ax2.set_title("Circular Trajectory with Tool Frames (α = 30°)") # noqa: RUF001
82+
ax2.set_xlabel("x")
83+
ax2.set_ylabel("y")
84+
ax2.set_zlabel("z")
85+
86+
# Set equal aspect ratio with more space for z
87+
for ax in [ax1, ax2]:
88+
ax.set_box_aspect([1, 1, 0.5])
89+
ax.set_zlim(-1, 1)
90+
91+
plt.tight_layout()
92+
plt.show()
93+
94+
95+
def example_rot() -> None:
96+
"""Recreate Example Rotations."""
97+
print("Example with RPY rotations: Circular trajectory with tool orientation")
98+
99+
# Parameters from the example
100+
r = 2.0
101+
alpha = np.radians(30) # Roll angle
102+
beta = np.radians(60) # Pitch angle
103+
gamma = np.radians(0) # Yaw angle
104+
u_values = np.linspace(0, 2 * np.pi, 100)
105+
106+
# Get circular trajectory function
107+
def circle_func(u: float) -> tuple:
108+
return circular_trajectory_with_derivatives(u, r)
109+
110+
# Compute Frenet frames
111+
points, frenet_frames = compute_trajectory_frames(circle_func, u_values)
112+
113+
# Compute tool frames with RPY orientation
114+
_, tool_frames = compute_trajectory_frames(
115+
circle_func, u_values, tool_orientation=(alpha, beta, gamma)
116+
)
117+
118+
# Visualize
119+
fig = plt.figure(figsize=(12, 6))
120+
121+
# Plot Frenet frames
122+
ax1 = fig.add_subplot(121, projection="3d")
123+
plot_frames(ax1, points, frenet_frames, scale=0.5, skip=8)
124+
ax1.set_title("Circular Trajectory with Frenet Frames")
125+
ax1.set_xlabel("x")
126+
ax1.set_ylabel("y")
127+
ax1.set_zlabel("z")
128+
129+
# Plot tool frames
130+
ax2 = fig.add_subplot(122, projection="3d")
131+
plot_frames(ax2, points, tool_frames, scale=0.5, skip=8)
132+
ax2.set_title("Circular Trajectory with Tool Frames Rotated")
133+
ax2.set_xlabel("x")
134+
ax2.set_ylabel("y")
135+
ax2.set_zlabel("z")
136+
137+
# Set equal aspect ratio with more space for z
138+
for ax in [ax1, ax2]:
139+
ax.set_box_aspect([1, 1, 0.5])
140+
ax.set_zlim(-1, 1)
141+
142+
plt.tight_layout()
143+
plt.show()
144+
145+
146+
if __name__ == "__main__":
147+
print()
148+
print("Frenet Frame and Tool Orientation Implementation")
149+
print("=" * 60)
150+
print()
151+
152+
example_8_5()
153+
print("=" * 60)
154+
print()
155+
156+
example_8_6()
157+
print("=" * 60)
158+
print()
159+
160+
example_rot()
161+
print("=" * 60)
162+
print()

0 commit comments

Comments
 (0)