Skip to content

Commit 9b8fcf2

Browse files
committed
add quat construction about unique access
1 parent 216e94e commit 9b8fcf2

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/gncpy/math/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,30 @@ def euler_to_quat(roll, pitch, yaw):
905905
return np.array([qw, qx, qy, qz])
906906

907907

908+
def quat_unique_axis(theta, axis):
909+
"""Create a quaternion representing a rotation about a unique axis.
910+
911+
Parameters
912+
----------
913+
theta : float
914+
Rotation angle in radians.
915+
axis : numpy array
916+
3D unit vector representing the axis of rotation.
917+
918+
Returns
919+
-------
920+
numpy array
921+
Quaternion [qw, qx, qy, qz] representing the rotation.
922+
"""
923+
half_theta = theta / 2.0
924+
qw = np.cos(half_theta)
925+
sin_half_theta = np.sin(half_theta)
926+
qx = axis[0] * sin_half_theta
927+
qy = axis[1] * sin_half_theta
928+
qz = axis[2] * sin_half_theta
929+
return np.array([qw, qx, qy, qz])
930+
931+
908932
def quat_slerp(q1, q2, t):
909933
"""Spherical linear interpolation between two quaternions.
910934

0 commit comments

Comments
 (0)