psychopy.tools.mathtools.RigidBodyPose¶
- class psychopy.tools.mathtools.RigidBodyPose(pos=(0.0, 0.0, 0.0), ori=(0.0, 0.0, 0.0, 1.0), dtype=None)[source]¶
Class for representing rigid body poses.
This class is an abstract representation of a rigid body pose, where the position of the body in a scene is represented by a vector/coordinate and the orientation with a quaternion. Pose can be manipulated and interacted with using class methods and attributes. Rigid body poses assume a right-handed coordinate system (-Z is forward and +Y is up).
Poses can be converted to 4x4 transformation matrices with getModelMatrix. One can use these matrices when rendering to transform the vertices of a model associated with the pose by passing them to OpenGL. Matrices are cached internally to avoid recomputing them if pos and ori attributes have not been updated.
Operators * and ~ can be used on RigidBodyPose objects to combine and invert poses. For instance, you can multiply (*) poses to get a new pose which is the combination of both orientations and translations by:
newPose = rb1 * rb2
Likewise, a pose can be inverted by using the ~ operator:
invPose = ~rb
Multiplying a pose by its inverse will result in an identity pose with no translation and default orientation where pos=[0, 0, 0] and ori=[0, 0, 0, 1]:
identityPose = ~rb * rb
Warning
This class is experimental and may result in undefined behavior.
- Parameters:
pos (array_like) – Position vector [x, y, z] for the origin of the rigid body.
ori (array_like) – Orientation quaternion [x, y, z, w] where x, y, z are imaginary and w is real.
dtype (dtype or str, optional) – Data type for computations can either be ‘float32’ or ‘float64’. Default is None which uses the default data configured by setDefaultPrecision.
- __init__(pos=(0.0, 0.0, 0.0), ori=(0.0, 0.0, 0.0, 1.0), dtype=None)[source]¶
- Parameters:
pos (array_like) – Position vector [x, y, z] for the origin of the rigid body.
ori (array_like) – Orientation quaternion [x, y, z, w] where x, y, z are imaginary and w is real.
dtype (dtype or str, optional) – Data type for computations can either be ‘float32’ or ‘float64’. Default is None which uses the default data configured by setDefaultPrecision.
Methods
__init__([pos, ori, dtype])alignTo(alignTo)Align this pose to another point or pose.
clear()Clear the pose, setting position and orientation to zero.
copy()Get a new RigidBodyPose object which copies the position and orientation of this one.
distanceTo(v)Get the distance to a pose or point in scene units.
getModelMatrix([inverse, out])Get the present rigid body transformation as a 4x4 matrix.
getNormalMatrix([out])Get the present normal matrix.
getOriAxisAngle([degrees])Get the axis and angle of rotation for the rigid body.
getViewMatrix([inverse, out])Convert this pose into a view matrix.
getYawPitchRoll([degrees])Get the yaw, pitch and roll angles for this pose relative to the -Z world axis.
interp(end, s)Interpolate between poses.
invert()Invert this pose.
inverted()Get a pose which is the inverse of this one.
isEqual(other)Check if poses have similar orientation and position.
setIdentity()Clear rigid body transformations (alias for clear).
setOriAxisAngle(axis, angle[, degrees])Set the orientation of the rigid body using an axis and angle.
transform(v[, out])Transform a vector using this pose.
transformNormal(n)Rotate a normal vector with respect to this pose.
Attributes
atVector defining the forward direction (-Z) of this pose.
boundsBounding box associated with this pose.
dtypeData type used for computations and arrays (numpy.dtype).
inverseModelMatrixInverse of the pose as a 4x4 model matrix (read-only).
inverseViewMatrixThe inverse of the 4x4 view matrix for this pose (read-only).
modelMatrixPose as a 4x4 model matrix (read-only).
normalMatrixThe 4x4 normal transformation matrix (read-only).
oriOrientation quaternion (X, Y, Z, W).
posPosition vector (X, Y, Z).
posOriThe position (x, y, z) and orientation (x, y, z, w).
upVector defining the up direction (+Y) of this pose.
viewMatrixThe 4x4 view matrix for this pose (read-only).