# klampt.math.so3 module¶

Operations for rigid rotations in Klampt. All rotations are represented by a 9-list specifying the entries of the rotation matrix in column major form.

In other words, given a 3x3 matrix:

[a11,a12,a13]
[a21,a22,a23]
[a31,a32,a33],


Klamp’t represents the matrix as a list [a11,a21,a31,a12,a22,a32,a13,a23,a33].

The reasons for this representation are 1) simplicity, and 2) a more convenient interface with C code.

klampt.math.so3.angle(R)[source]

Returns absolute deviation of R from identity

klampt.math.so3.apply(R, point)[source]

Applies the rotation to a point

klampt.math.so3.axis_angle(R)[source]

Returns the (axis,angle) pair representing R

klampt.math.so3.canonical(v)[source]

Given a unit vector v, finds R that defines a basis [x,y,z] such that x = v and y and z are orthogonal

klampt.math.so3.cross_product(w)[source]

Returns the cross product matrix associated with w.

The matrix [w]R is the derivative of the matrix R as it rotates about the axis w/||w|| with angular velocity ||w||.

klampt.math.so3.det(R)[source]

Returns the determinant of the 3x3 matrix R

klampt.math.so3.distance(R1, R2)[source]

Returns the absolute angle one would need to rotate in order to get from R1 to R2

klampt.math.so3.error(R1, R2)[source]

Returns a 3D “difference vector” that describes how far R1 is from R2. More precisely, this is the Lie derivative, which is the rotation vector representation of R1*R2^T.

klampt.math.so3.from_axis_angle(aa)[source]

Converts an axis-angle representation (axis,angle) to a 3D rotation matrix.

klampt.math.so3.from_matrix(mat)[source]

Returns an R corresponding to the 3x3 rotation matrix mat

klampt.math.so3.from_moment(w)

Converts a rotation vector representation w to a 3D rotation matrix.

klampt.math.so3.from_quaternion(q)[source]

Given a unit quaternion (w,x,y,z), produce the corresponding rotation matrix.

klampt.math.so3.from_rotation_vector(w)[source]

Converts a rotation vector representation w to a 3D rotation matrix.

klampt.math.so3.from_rpy(rollpitchyaw)[source]

Converts from roll,pitch,yaw angle triple to a rotation matrix. The triple is given in radians. The x axis is “roll”, y is “pitch”, and z is “yaw”.

klampt.math.so3.identity()[source]

Returns the identity rotation

klampt.math.so3.interpolate(R1, R2, u)[source]

Interpolate linearly between the two rotations R1 and R2.

klampt.math.so3.inv(R)[source]

Inverts the rotation

klampt.math.so3.is_rotation(R, tol=1e-05)[source]

Returns true if R is a rotation matrix, i.e. is orthogonal to the given tolerance and has + determinant

klampt.math.so3.matrix(R)[source]

Returns the 3x3 rotation matrix corresponding to R

klampt.math.so3.moment(R)

Returns the rotation vector w (exponential map) representation of R such that e^[w] = R. Equivalent to axis-angle representation with w/||w||=axis, ||w||=angle.

klampt.math.so3.mul(R1, R2)[source]

Multiplies two rotations.

klampt.math.so3.quaternion(R)[source]

Given a Klamp’t rotation representation, produces the corresponding unit quaternion (w,x,y,z).

klampt.math.so3.rotation(axis, angle)[source]

Given a unit axis and an angle in radians, returns the rotation matrix.

klampt.math.so3.rotation_vector(R)[source]

Returns the rotation vector w (exponential map) representation of R such that e^[w] = R. Equivalent to axis-angle representation with w/||w||=axis, ||w||=angle.

klampt.math.so3.rpy(R)[source]

Converts a rotation matrix to a roll,pitch,yaw angle triple. The result is given in radians.

klampt.math.so3.sample()[source]

Returns a uniformly distributed rotation matrix.

klampt.math.so3.trace(R)[source]

Computes the trace of the rotation matrix.

klampt.math.so3.vector_rotation(v1, v2)[source]

Finds the minimal-angle matrix that rotates v1 to v2. v1 and v2 are assumed to be nonzero