psychopy.tools.mathtools.transform

psychopy.tools.mathtools.transform(pos, ori, points, out=None, dtype=None)[source]

Transform points using a position and orientation. Points are rotated then translated.

Parameters
  • pos (array_like) – Position vector in form [x, y, z] or [x, y, z, 1].

  • ori (array_like) – Orientation quaternion in form [x, y, z, w] where w is real and x, y, z are imaginary components.

  • points (array_like) – Point(s) [x, y, z] to transform.

  • out (ndarray, optional) – Optional output array. Must be same shape and dtype as the expected output if out was not specified.

  • dtype (dtype or str, optional) – Data type for computations can either be ‘float32’ or ‘float64’. If out is specified, the data type of out is used and this argument is ignored. If out is not provided, ‘float64’ is used by default.

Returns

Transformed points.

Return type

ndarray

Examples

Transform points by a position coordinate and orientation quaternion:

# rigid body pose
ori = quatFromAxisAngle([0., 0., -1.], 90.0, degrees=True)
pos = [0., 1.5, -3.]
# points to transform
points = np.array([[0., 1., 0., 1.], [-1., 0., 0., 1.]])  # [x, y, z, 1]
outPoints = np.zeros_like(points)  # output array
transform(pos, ori, points, out=outPoints)  # do the transformation

You can get the same results as the previous example using a matrix by doing the following:

R = rotationMatrix(90., [0., 0., -1])
T = translationMatrix([0., 1.5, -3.])
M = concatenate([R, T])
applyMatrix(M, points, out=outPoints)

If you are defining transformations with quaternions and coordinates, you can skip the costly matrix creation process by using transform.

Notes

  • In performance tests, applyMatrix is noticeably faster than transform for very large arrays, however this is only true if you are applying the same transformation to all points.

  • If the input arrays for points or pos is Nx4, the last column is ignored.


Back to top