Matrix4d Functions¶
API functions that utilize the Matrix4d class are grouped here. For details of the class, including member functions, see Matrix4d.
Matrix4d¶
Create a 4x4 identity matrix |
|
|
Translate the Matrix4d along the given axes values |
Translate the matrix by a vec3d. |
|
|
Rotate the Matrix4d about the X axis |
|
Rotate the Matrix4d about the Y axis |
|
Rotate the Matrix4d about the Z axis |
|
Rotate the Matrix4d about an arbitrary axis |
|
Rotate the matrix so that its X axis points along a given direction. |
Clear the translation part of the matrix, leaving the rotation and scaling alone. |
|
Perform an affine transform on the Matrix4d |
|
|
Multiply the Matrix4d by a scalar value |
|
Scale the matrix along X alone. |
|
Scale the matrix along Y alone. |
|
Scale the matrix along Z alone. |
Flip the matrix about the YZ plane, negating X. |
|
Load an identy Matrix4d and set the Y coordinate of the diagonal (index 5) to -1 |
|
Load an identy Matrix4d and set the Z coordinate of the diagonal (index 10) to -1 |
|
Load an identy Matrix4d and set the X coordinate of the diagonal (index 0) to -1 |
|
Transform the Matrix4d by the given vector |
|
|
Transform a point by the matrix, applying the rotation, the scaling and the translation. |
|
Transform a whole vector of points by the matrix, in place. |
|
Transform a grid of points by the matrix, in place. |
|
Transform a normal vector by the matrix. |
Transform a whole vector of normals by the matrix, in place, leaving the translation out. |
|
Transform a grid of normals by the matrix, in place. |
|
Calculate the Matrix4d's angles between the X, Y and Z axes |
|
Get the rotation as the arcball angles the GUI trackball uses. |
|
Get the translation part of the matrix. |
|
|
Translate the Matrix4d to a given position and rotate it a about a given center of rotation |
|
Get the three axis directions of the matrix. |
|
Set the rotation of the matrix from three axis directions. |
|
Reduce the matrix to a single rotation about an axis: the direction of the axis, a point on it, and the angle turned through in radians. |
Decompose the matrix into a rotation quaternion and a translation. |
- class openvsp.Matrix4d[source]¶
Matrix4d is typically used to perform rotations, translations, scaling, projections, and other transformations in 3D space.
- property thisown¶
The membership flag
- __repr__()¶
Return repr(self).
- loadIdentity()[source]¶
Create a 4x4 identity matrix
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor m.loadIdentity()
- translatef(x, y, z)[source]¶
Translate the Matrix4d along the given axes values
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadIdentity()
m.translatef( 1.0, 0.0, 0.0 )
- Parameters:
[in] – x Translation along the X axis
[in] – y Translation along the Y axis
[in] – z Translation along the Z axis
- translatev(v)[source]¶
Translate the matrix by a vec3d. The vec3d counterpart of translatef.
m = Matrix4d() m.loadIdentity() m.translatev( vec3d( 1.0, 2.0, 3.0 ) ) p = m.xform( vec3d( 0.0, 0.0, 0.0 ) ) assert abs( p.x() - 1.0 ) < 1e-12, "translatev did not move the origin" assert abs( p.z() - 3.0 ) < 1e-12, "translatev did not move in z"
See also: translatef, getTranslation :param [in]: v vec3d Translation to apply
- rotateX(ang)[source]¶
Rotate the Matrix4d about the X axis
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadIdentity()
m.rotateX( 90.0 )
- Parameters:
[in] – ang Angle of rotation (degrees)
- rotateY(ang)[source]¶
Rotate the Matrix4d about the Y axis
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadIdentity()
m.rotateY( 90.0 )
- Parameters:
[in] – ang Angle of rotation (degrees)
- rotateZ(ang)[source]¶
Rotate the Matrix4d about the Z axis
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadIdentity()
m.rotateZ( 90.0 )
- Parameters:
[in] – ang Angle of rotation (degrees)
- rotate(angle, axis)[source]¶
Rotate the Matrix4d about an arbitrary axis
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor PI = 3.14
m.loadIdentity()
m.rotate( PI / 4, vec3d( 0.0, 0.0, 1.0 ) ) # Radians
- Parameters:
[in] – angle Angle of rotation (rad)
[in] – axis Vector to rotate about
- rotatealongX(dir1)[source]¶
Rotate the matrix so that its X axis points along a given direction.
m = Matrix4d() m.loadIdentity() m.rotatealongX( vec3d( 0.0, 1.0, 0.0 ) ) p = m.xform( vec3d( 1.0, 0.0, 0.0 ) ) assert abs( p.y() - 1.0 ) < 1e-12, "rotatealongX did not take X onto the given direction"
- Parameters:
[in] – dir1 vec3d Direction the X axis should point along
- zeroTranslations()[source]¶
Clear the translation part of the matrix, leaving the rotation and scaling alone.
m = Matrix4d() m.loadIdentity() m.translatev( vec3d( 1.0, 2.0, 3.0 ) ) m.zeroTranslations() t = m.getTranslation() assert abs( t.x() ) < 1e-12 and abs( t.z() ) < 1e-12, "zeroTranslations left a translation behind"
See also: getTranslation, translatev
- affineInverse()[source]¶
Perform an affine transform on the Matrix4d
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadIdentity()
m.rotateY( 10.0 ) m.rotateX( 20.0 ) m.rotateZ( 30.0 )
c = m.xform( vec3d( 1.0, 1.0, 1.0 ) )
m.affineInverse()
- scale(scale)[source]¶
Multiply the Matrix4d by a scalar value
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadXZRef()
m.scale( 10.0 )
- Parameters:
[in] – scale Value to scale by
- scalex(scalex)[source]¶
Scale the matrix along X alone. Unlike scale, which scales all three axes together.
m = Matrix4d() m.loadIdentity() m.scalex( 2.0 ) p = m.xform( vec3d( 1.0, 1.0, 1.0 ) ) assert abs( p.x() - 2.0 ) < 1e-12, "scalex did not scale X" assert abs( p.y() - 1.0 ) < 1e-12, "scalex scaled an axis it should not have"
See also: scale :param [in]: scalex double Scale factor for X
- scaley(scaley)[source]¶
Scale the matrix along Y alone. Unlike scale, which scales all three axes together.
m = Matrix4d() m.loadIdentity() m.scaley( 2.0 ) p = m.xform( vec3d( 1.0, 1.0, 1.0 ) ) assert abs( p.y() - 2.0 ) < 1e-12, "scaley did not scale Y" assert abs( p.z() - 1.0 ) < 1e-12, "scaley scaled an axis it should not have"
See also: scale :param [in]: scaley double Scale factor for Y
- scalez(scalez)[source]¶
Scale the matrix along Z alone. Unlike scale, which scales all three axes together.
m = Matrix4d() m.loadIdentity() m.scalez( 2.0 ) p = m.xform( vec3d( 1.0, 1.0, 1.0 ) ) assert abs( p.z() - 2.0 ) < 1e-12, "scalez did not scale Z" assert abs( p.x() - 1.0 ) < 1e-12, "scalez scaled an axis it should not have"
See also: scale :param [in]: scalez double Scale factor for Z
- flipx()[source]¶
Flip the matrix about the YZ plane, negating X.
m = Matrix4d() m.loadIdentity() m.flipx() p = m.xform( vec3d( 1.0, 2.0, 3.0 ) ) assert abs( p.x() + 1.0 ) < 1e-12, "flipx did not negate x" assert abs( p.y() - 2.0 ) < 1e-12, "flipx disturbed y"
See also: loadYZRef
- matMult(*args)[source]¶
Multiply this matrix by another, this * m, and keep the result.
a = Matrix4d() b = Matrix4d() a.loadIdentity() a.translatev( vec3d( 1.0, 0.0, 0.0 ) ) b.loadIdentity() b.scale( 2.0 ) a.matMult( b ) p = a.xform( vec3d( 1.0, 0.0, 0.0 ) ) assert abs( p.x() - 3.0 ) < 1e-12, "matMult did not apply both transformations"
See also: postMult, initMat :param [in]: m Matrix4d Matrix to multiply by
- postMult(*args)[source]¶
Multiply another matrix by this one, m * this, and keep the result. The other order from matMult.
a = Matrix4d() b = Matrix4d() a.loadIdentity() a.translatev( vec3d( 1.0, 0.0, 0.0 ) ) b.loadIdentity() b.scale( 2.0 ) a.postMult( b ) p = a.xform( vec3d( 1.0, 0.0, 0.0 ) ) assert abs( p.x() - 4.0 ) < 1e-12, "postMult did not apply the transformations in the other order"
See also: matMult, initMat :param [in]: m Matrix4d Matrix to multiply by
- initMat(*args)[source]¶
Copy another matrix into this one, replacing whatever was here.
a = Matrix4d() b = Matrix4d() b.loadIdentity() b.translatev( vec3d( 5.0, 0.0, 0.0 ) ) a.initMat( b ) p = a.xform( vec3d( 0.0, 0.0, 0.0 ) ) assert abs( p.x() - 5.0 ) < 1e-12, "initMat did not copy the matrix"
See also: matMult, postMult :param [in]: m Matrix4d Matrix to copy
- loadXZRef()[source]¶
Load an identy Matrix4d and set the Y coordinate of the diagonal (index 5) to -1
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadXZRef()
b = m.xform( vec3d( 1, 2, 3 ) )
- loadXYRef()[source]¶
Load an identy Matrix4d and set the Z coordinate of the diagonal (index 10) to -1
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadXYRef()
b = m.xform( vec3d( 1, 2, 3 ) )
- loadYZRef()[source]¶
Load an identy Matrix4d and set the X coordinate of the diagonal (index 0) to -1
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadYZRef()
b = m.xform( vec3d( 1, 2, 3 ) )
- mirrory()[source]¶
Transform the Matrix4d by the given vector
#==== Test Matrix4d ==== m = Matrix4d() # Default Constructor
m.loadIdentity()
a = m.xform( vec3d( 1.0, 2.0, 3.0 ) )
- xform(_in)[source]¶
Transform a point by the matrix, applying the rotation, the scaling and the translation.
m = Matrix4d() m.loadIdentity() m.translatev( vec3d( 1.0, 2.0, 3.0 ) ) p = m.xform( vec3d( 0.0, 0.0, 0.0 ) ) assert abs( p.x() - 1.0 ) < 1e-12, "xform did not apply the translation"
See also: xformnorm, xformvec :param [in]: in vec3d Point to transform :rtype:
vec3d:return: vec3d Transformed point
- xformvec(_in)[source]¶
Transform a whole vector of points by the matrix, in place.
m = Matrix4d() m.loadIdentity() m.translatev( vec3d( 1.0, 0.0, 0.0 ) ) pts = Vec3dVec( [ vec3d( 0.0, 0.0, 0.0 ), vec3d( 1.0, 0.0, 0.0 ) ] ) m.xformvec( pts ) assert abs( pts[0].x() - 1.0 ) < 1e-12, "xformvec did not transform the first point" assert abs( pts[1].x() - 2.0 ) < 1e-12, "xformvec did not transform the second point"
See also: xform, xformmat :param [in,out]: in vector<vec3d> Points to transform, replaced by the result
- xformmat(_in)[source]¶
Transform a grid of points by the matrix, in place. The two dimensional counterpart of xformvec.
m = Matrix4d() m.loadIdentity() m.translatev( vec3d( 1.0, 0.0, 0.0 ) ) grid = Vec3dVecVec( [ Vec3dVec( [ vec3d( 0.0, 0.0, 0.0 ) ] ), Vec3dVec( [ vec3d( 1.0, 0.0, 0.0 ) ] ) ] ) m.xformmat( grid ) assert abs( grid[0][0].x() - 1.0 ) < 1e-12, "xformmat did not transform the first row" assert abs( grid[1][0].x() - 2.0 ) < 1e-12, "xformmat did not transform the second row"
See also: xformvec :param [in,out]: in vector<vector<vec3d>> Grid of points to transform, replaced by the result
- xformnorm(_in)[source]¶
Transform a normal vector by the matrix. Unlike xform this leaves the translation out, since a direction has no position.
m = Matrix4d() m.loadIdentity() m.translatev( vec3d( 1.0, 2.0, 3.0 ) ) n = m.xformnorm( vec3d( 1.0, 0.0, 0.0 ) ) assert abs( n.x() - 1.0 ) < 1e-12, "xformnorm changed the direction" assert abs( n.y() ) < 1e-12, "xformnorm applied the translation to a direction"
See also: xform, xformnormvec :param [in]: in vec3d Direction to transform :rtype:
vec3d:return: vec3d Transformed direction
- xformnormvec(_in)[source]¶
Transform a whole vector of normals by the matrix, in place, leaving the translation out.
m = Matrix4d() m.loadIdentity() m.translatev( vec3d( 1.0, 2.0, 3.0 ) ) norms = Vec3dVec( [ vec3d( 1.0, 0.0, 0.0 ) ] ) m.xformnormvec( norms ) assert abs( norms[0].y() ) < 1e-12, "xformnormvec applied the translation to a direction"
See also: xformnorm, xformnormmat :param [in,out]: in vector<vec3d> Directions to transform, replaced by the result
- xformnormmat(_in)[source]¶
Transform a grid of normals by the matrix, in place. The two dimensional counterpart of xformnormvec.
m = Matrix4d() m.loadIdentity() m.translatev( vec3d( 1.0, 2.0, 3.0 ) ) grid = Vec3dVecVec( [ Vec3dVec( [ vec3d( 1.0, 0.0, 0.0 ) ] ) ] ) m.xformnormmat( grid ) assert abs( grid[0][0].y() ) < 1e-12, "xformnormmat applied the translation to a direction"
See also: xformnormvec :param [in,out]: in vector<vector<vec3d>> Grid of directions to transform, replaced by the result
- getAngles()[source]¶
Calculate the Matrix4d’s angles between the X, Y and Z axes
mat = Matrix4d() PI = 3.14
mat.loadIdentity()
mat.rotate( PI / 4, vec3d( 0.0, 0.0, 1.0 ) ) # Radians
angles = mat.getAngles()
- Return type:
- Returns:
Angle measurement between each axis (degrees)
- getArcballAngles()[source]¶
Get the rotation as the arcball angles the GUI trackball uses.
m = Matrix4d() m.loadIdentity() a = m.getArcballAngles() assert abs( a.x() ) < 1e-12, "getArcballAngles found a rotation in an identity matrix"
See also: getAngles :rtype:
vec3d:return: vec3d Arcball angles
- getTranslation()[source]¶
Get the translation part of the matrix.
m = Matrix4d() m.loadIdentity() m.translatev( vec3d( 1.0, 2.0, 3.0 ) ) t = m.getTranslation() assert abs( t.x() - 1.0 ) < 1e-12, "getTranslation is wrong in x" assert abs( t.z() - 3.0 ) < 1e-12, "getTranslation is wrong in z"
See also: translatev, zeroTranslations :rtype:
vec3d:return: vec3d Translation
- buildXForm(pos, rot, cent_rot)[source]¶
Translate the Matrix4d to a given position and rotate it a about a given center of rotation
m = Matrix4d() m.loadIdentity() m.buildXForm( vec3d( 1.0, 0.0, 0.0 ), vec3d( 0.0, 0.0, 90.0 ), vec3d( 0.0, 0.0, 0.0 ) ) p = m.xform( vec3d( 1.0, 0.0, 0.0 ) ) assert abs( p.y() - 1.0 ) < 1e-9, "buildXForm did not rotate about the given center" assert abs( p.x() - 1.0 ) < 1e-9, "buildXForm did not translate to the given position"
See also: translatev, rotate :param [in]: pos Position to translate to :param [in]: rot Angle of rotation (degrees) :param [in]: cent_rot Center of rotation
- getBasis(xdir, ydir, zdir)[source]¶
Get the three axis directions of the matrix. The vec3d passed in are filled in rather than returned.
m = Matrix4d() m.loadIdentity() xdir = vec3d() ydir = vec3d() zdir = vec3d() m.getBasis( xdir, ydir, zdir ) assert abs( xdir.x() - 1.0 ) < 1e-12, "getBasis did not report the X axis" assert abs( zdir.z() - 1.0 ) < 1e-12, "getBasis did not report the Z axis"
See also: setBasis :param [out]: xdir vec3d X axis direction :param [out]: ydir vec3d Y axis direction :param [out]: zdir vec3d Z axis direction
- setBasis(xdir, ydir, zdir)[source]¶
Set the rotation of the matrix from three axis directions.
m = Matrix4d() m.loadIdentity() m.setBasis( vec3d( 0.0, 1.0, 0.0 ), vec3d( -1.0, 0.0, 0.0 ), vec3d( 0.0, 0.0, 1.0 ) ) p = m.xform( vec3d( 1.0, 0.0, 0.0 ) ) assert abs( p.y() - 1.0 ) < 1e-12, "setBasis did not take X onto the given direction"
See also: getBasis :param [in]: xdir vec3d X axis direction :param [in]: ydir vec3d Y axis direction :param [in]: zdir vec3d Z axis direction
- getRotationAxis(axis_dir, axis_pnt)[source]¶
Reduce the matrix to a single rotation about an axis: the direction of the axis, a point on it, and the angle turned through in radians.
import math m = Matrix4d() m.loadIdentity() m.rotateZ( 90.0 ) axis_dir = vec3d() axis_pnt = vec3d() angle = m.getRotationAxis( axis_dir, axis_pnt ) assert abs( abs( axis_dir.z() ) - 1.0 ) < 1e-9, "getRotationAxis did not find the Z axis" assert abs( abs( angle ) - 0.5 * math.pi ) < 1e-9, "getRotationAxis did not measure the angle"
See also: toQuat, getAngles :param [out]: axis_dir vec3d Direction of the rotation axis :param [out]: axis_pnt vec3d A point on the rotation axis :param [out]: angle_out double Angle turned through, in radians
- toQuat()[source]¶
Decompose the matrix into a rotation quaternion and a translation.
m = Matrix4d() m.loadIdentity() qw, qx, qy, qz, tx, ty, tz = m.toQuat() assert abs( qw - 1.0 ) < 1e-12, "toQuat did not give the identity quaternion" assert abs( qx ) + abs( qy ) + abs( qz ) < 1e-12, "toQuat found a rotation in an identity matrix" assert abs( tx ) + abs( ty ) + abs( tz ) < 1e-12, "toQuat found a translation in an identity matrix"
See also: getRotationAxis :param [out]: qw_out double Scalar part of the rotation quaternion :param [out]: qx_out double X part of the rotation quaternion :param [out]: qy_out double Y part of the rotation quaternion :param [out]: qz_out double Z part of the rotation quaternion :param [out]: tx_out double X translation :param [out]: ty_out double Y translation :param [out]: tz_out double Z translation