xopto.mcbase.mcutil.geometry module

rotation_matrix(a: Tuple[float, float, float], b: Tuple[float, float, float])Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]][source]

Computes a rotation matrix that rotates a unit vector a onto a unit vector b. :param a: A unit vector from which the rotation starts. :type a: (float, float, float) :param b: A unit vector onto which the vector a is rotated. :type b: (float, float, float)

Returns

T – Rotation matrix that rotates the unit vector a onto the unit vector b (b = T*a)

Return type

np.ndarray of shape (3, 3)

Note

The general solution fails if a == -b (rotation is not uniquely defined).

rotation_matrix_2d(a: Tuple[float, float], b: Tuple[float, float])[source]

Computes a rotation matrix that rotates a unit vector a onto a unit vector b.

Parameters
  • a ((float, float)) – A unit vector from which the rotation starts.

  • b ((float, float)) – A unit vector onto which the vector a is rotated.

Returns

T – Rotation matrix that rotates the unit vector a onto the unit vector b (b = T*a)

Return type

np.ndarray of shape (2, 2)

transform_base(vfrom: Tuple[float, float, float], vto: Tuple[float, float, float])Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]][source]

Create a matrix that transforms the orthogonal base defining the components of vectors vfrom and vto by rotating vector vfrom onto vector vto. Use the transformation matrix to transform coordinates defined in the transformed orthogonal base back to the initial orthogonal base that was used to define the components of vectors vfrom and vto.

Parameters
  • from_v ((float, float, float)) – Initial vector defined with the source orthogonal base.

  • to_v ((float, float, float)) – Target vector defined with the source orthogonal base.

Returns

transform – Transformation matrix.

Return type

np.ndarray of shape (3, 3)

Examples

Create a transformation from coordinate system with a standard z axis [0, 0, 1] to a coordinate system with a z axis [sin(10), 0, cos(10)]. This requires additional step that inverts the matrix returned by transform_base.

>>> Tinv = np.linalg.inv(transform_base([0, 0, 1], [np.sin(np.pi/18), 0, np.cos(np.pi/18)]))
>>> np.dot(Tinv, [[0], [0], [1]])