Struct Matrix4
4x4 matrix, typically used to describe a transformation (rotation and translation).
Namespace: ABB.Robotics.Math
Assembly: ABB.Robotics.Math.dll
Syntax
public struct Matrix4
Constructors
View SourceMatrix4(Matrix3, Vector3)
Constructs a matrix from a 3x3 orientation matrix and a translation.
Declaration
public Matrix4(Matrix3 orientation, Vector3 translation)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix3 | orientation | |
| Vector3 | translation |
Matrix4(Vector3)
Creates a matrix with unit rotation and a specified translation.
Declaration
public Matrix4(Vector3 translation)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | translation | Translation vector |
Matrix4(Vector3, Quaternion)
Creates a matrix from a translation vector and a quaternion.
Declaration
public Matrix4(Vector3 translation, Quaternion quat)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | translation | Translation vector |
| Quaternion | quat | Quaternion |
Matrix4(Vector3, Vector3)
Creates a matrix from a translation vector and Euler angles (zyx).
Declaration
public Matrix4(Vector3 translation, Vector3 eulerZYX)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | translation | Translation vector |
| Vector3 | eulerZYX | Euler angles (zyx order) |
Matrix4(Vector3, Vector3, Vector3, Vector3)
Creates an affine matrix from four vectors
Declaration
public Matrix4(Vector3 x0, Vector3 y0, Vector3 z0, Vector3 t0)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | x0 | X axis |
| Vector3 | y0 | Y axis |
| Vector3 | z0 | Z axis |
| Vector3 | t0 | Translation |
Matrix4(Vector3, double)
Creates a matrix from a rotation axis and angle, with unit translation.
Declaration
public Matrix4(Vector3 axis, double angle)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | axis | Rotation axis |
| double | angle | Rotation angle |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Invalid rotation axis |
Matrix4(Vector4, Vector4, Vector4, Vector4)
Creates a matrix from four column vectors.
Declaration
public Matrix4(Vector4 x0, Vector4 y0, Vector4 z0, Vector4 t0)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | x0 | First column |
| Vector4 | y0 | Second column |
| Vector4 | z0 | Third column |
| Vector4 | t0 | Fourth column |
Matrix4(double[], bool)
Creates a matrix from an array of 16 values.
Declaration
public Matrix4(double[] values, bool rowMajor)
Parameters
| Type | Name | Description |
|---|---|---|
| double[] | values | |
| bool | rowMajor |
Fields
View SourceIdentity
Identity matrix.
Declaration
public static readonly Matrix4 Identity
Field Value
| Type | Description |
|---|---|
| Matrix4 |
t
Column vector.
Declaration
public Vector4 t
Field Value
| Type | Description |
|---|---|
| Vector4 |
x
Column vector.
Declaration
public Vector4 x
Field Value
| Type | Description |
|---|---|
| Vector4 |
y
Column vector.
Declaration
public Vector4 y
Field Value
| Type | Description |
|---|---|
| Vector4 |
z
Column vector.
Declaration
public Vector4 z
Field Value
| Type | Description |
|---|---|
| Vector4 |
Properties
View SourceAxisAngle
Gets/sets the rotation as axis/angle
(represented by a 4-vector [axis,angle]).
Declaration
public Vector4 AxisAngle { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Invalid rotation axis |
Elements
Returns an array of all elements in column-first order.
Declaration
public double[] Elements { get; }
Property Value
| Type | Description |
|---|---|
| double[] |
EulerXYZ
Gets/sets the rotation as Euler angles (xyz order).
Declaration
public Vector3 EulerXYZ { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
EulerZYX
Gets/sets the rotation as Euler angles (zyx order).
Note: the vector contains the angles as [rx,ry,rz].
Declaration
public Vector3 EulerZYX { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
IsNaN
Returns a value indicating whether any elements evaluates to a value that is not a number (NaN).
Declaration
public bool IsNaN { get; }
Property Value
| Type | Description |
|---|---|
| bool |
this[int]
Column vector access.
Declaration
public Vector4 this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | index |
Property Value
| Type | Description |
|---|---|
| Vector4 |
Quaternion
Gets/sets the rotation as a quaternion.
Declaration
public Quaternion Quaternion { get; set; }
Property Value
| Type | Description |
|---|---|
| Quaternion |
Translation
Gets/sets the translation vector.
Declaration
public Vector3 Translation { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
UpperLeft
Gets/sets the rotation as a 3x3 matrix.
Declaration
public Matrix3 UpperLeft { get; set; }
Property Value
| Type | Description |
|---|---|
| Matrix3 |
Methods
View SourceAlign(Matrix4, Matrix4)
Rotates a matrix so that its rotation axes coincide with the closest arbitrary (negative or positive) rotation axes of a reference matrix.
Declaration
public static Matrix4 Align(Matrix4 matrix, Matrix4 reference)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | matrix | The matrix to rotate |
| Matrix4 | reference | Reference matrix |
Returns
| Type | Description |
|---|---|
| Matrix4 | The aligned matrix |
AlmostEquals(Matrix4)
Comparison method for matrices with default tolerance
Declaration
public bool AlmostEquals(Matrix4 rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | rhs | Matrix to compare with |
Returns
| Type | Description |
|---|---|
| bool | true if equals within tolerance |
AlmostEquals(Matrix4, double)
Comparison method for matrices with tolerance
Declaration
public bool AlmostEquals(Matrix4 rhs, double tolerance)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | rhs | Matrix to compare with |
| double | tolerance | tolerance |
Returns
| Type | Description |
|---|---|
| bool | true if equals within tolerance |
CheckRigid()
Throws an exception if this matrix is not rigid.
Declaration
public void CheckRigid()
Clean()
Zeroes any values smaller than Globals.EPS.
Declaration
public void Clean()
CleanRigid()
Ensures this is a valid rigid matrix
Declaration
public void CleanRigid()
Determinant()
Returns the determinant.
Declaration
public double Determinant()
Returns
| Type | Description |
|---|---|
| double |
FromAxis(Axis, Vector3, Vector3)
Returns a matrix with one given axis. The other two axes are arbitrarily chosen to form a right-handed coordinate system.
Declaration
public static Matrix4 FromAxis(Axis axis, Vector3 axisDirection, Vector3 translation)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis | axis | |
| Vector3 | axisDirection | |
| Vector3 | translation |
Returns
| Type | Description |
|---|---|
| Matrix4 |
FromThreePoint(Vector3, Vector3, Vector3)
Creates a matrix from three points.
Declaration
public static Matrix4 FromThreePoint(Vector3 x1, Vector3 x2, Vector3 y1)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | x1 | First point on x axis |
| Vector3 | x2 | Second point on x axis |
| Vector3 | y1 | Point on y axis |
Returns
| Type | Description |
|---|---|
| Matrix4 |
FromTwoAxes(Vector3, Vector3, DirectionAxis, Vector3, DirectionAxis)
Creates a matrix from a translation and two axis vectors
Declaration
public static Matrix4 FromTwoAxes(Vector3 translation, Vector3 axis1, DirectionAxis axis1Direction, Vector3 axis2, DirectionAxis axis2Direction)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | translation | Translation |
| Vector3 | axis1 | First axis |
| DirectionAxis | axis1Direction | |
| Vector3 | axis2 | Second axis |
| DirectionAxis | axis2Direction |
Returns
| Type | Description |
|---|---|
| Matrix4 |
FromTwoPointXY(Vector3, Vector3, Vector3)
Creates a matrix from a translation and two points
Declaration
public static Matrix4 FromTwoPointXY(Vector3 translation, Vector3 x1, Vector3 xy)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | translation | Translation |
| Vector3 | x1 | Point on x axis |
| Vector3 | xy | Point in x-y plane |
Returns
| Type | Description |
|---|---|
| Matrix4 |
FromTwoPointXZ(Vector3, Vector3, Vector3)
Creates a matrix from a translation and two points
Declaration
public static Matrix4 FromTwoPointXZ(Vector3 translation, Vector3 x1, Vector3 xz)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | translation | Translation |
| Vector3 | x1 | Point on x axis |
| Vector3 | xz | Point in x-z plane |
Returns
| Type | Description |
|---|---|
| Matrix4 |
GetAxisVector(Axis)
Gets the axis vector from the specified axis
Declaration
public Vector3 GetAxisVector(Axis axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Axis | axis | the axis whose vector to get |
Returns
| Type | Description |
|---|---|
| Vector3 | the axis vector |
GetAxisVector(DirectionAxis)
Gets the positive or negative axis vector from the specified axis
Declaration
public Vector3 GetAxisVector(DirectionAxis axis)
Parameters
| Type | Name | Description |
|---|---|---|
| DirectionAxis | axis | the axis whose vector to get |
Returns
| Type | Description |
|---|---|
| Vector3 | the axis vector |
Inverse()
Returns the inverse of a general matrix.
Declaration
public Matrix4 Inverse()
Returns
| Type | Description |
|---|---|
| Matrix4 | Inverted matrix |
InverseRigid()
Returns a an inverted copy of the matrix. If the matrix is non-rigid the result is undefined.
Declaration
public Matrix4 InverseRigid()
Returns
| Type | Description |
|---|---|
| Matrix4 | The inverse of the matrix. |
Invert()
Inverts a general matrix, using Cramer's rule.
Declaration
public void Invert()
InvertAffine()
Inverts an affine matrix.
Declaration
public void InvertAffine()
InvertRigid()
Inverts a rigid (pure translation+rotation) matrix.
Declaration
public void InvertRigid()
IsAffine()
Returns true if the matrix is affine.
Declaration
public bool IsAffine()
Returns
| Type | Description |
|---|---|
| bool |
IsEmpty()
Returns true if all elements in the matrix are zero.
Declaration
public bool IsEmpty()
Returns
| Type | Description |
|---|---|
| bool |
IsIdentity()
Returns true if the matrix is identity.
Declaration
public bool IsIdentity()
Returns
| Type | Description |
|---|---|
| bool |
IsRigid()
Returns true if this matrix is rigid (orthogonal), e.g. it represents a pure rotation and translation.
Declaration
public bool IsRigid()
Returns
| Type | Description |
|---|---|
| bool |
Multiply(Matrix4)
Matrix-Matrix multiplication method.
Declaration
public Matrix4 Multiply(Matrix4 rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | rhs |
Returns
| Type | Description |
|---|---|
| Matrix4 |
Multiply(Vector4)
Matrix-Vector4 multiplication method.
Declaration
public Vector4 Multiply(Vector4 rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | rhs |
Returns
| Type | Description |
|---|---|
| Vector4 |
MultiplyPoint(Vector3)
Matrix-Vector3 (interpreted as a point) multiplication.
Declaration
public Vector3 MultiplyPoint(Vector3 rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | rhs |
Returns
| Type | Description |
|---|---|
| Vector3 |
MultiplyVector(Vector3)
Matrix-Vector3 (interpreted as a direction) multiplication.
Declaration
public Vector3 MultiplyVector(Vector3 rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | rhs |
Returns
| Type | Description |
|---|---|
| Vector3 |
RelativeMatrix(Matrix4, Matrix4)
Returns a matrix representing the relative transform, between the two specified matrices.
Declaration
public static Matrix4 RelativeMatrix(Matrix4 from, Matrix4 to)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | from | |
| Matrix4 | to |
Returns
| Type | Description |
|---|---|
| Matrix4 |
Rotate(Vector3, Vector3, double)
Rotates the matrix around an axis through a point.
Declaration
public void Rotate(Vector3 point, Vector3 axis, double angle)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | point | |
| Vector3 | axis | |
| double | angle |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Invalid rotation axis |
Rotate(Vector3, double)
Rotates the matrix around an axis through the origin.
Declaration
public void Rotate(Vector3 axis, double angle)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | axis | |
| double | angle |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Invalid rotation axis |
Scale(Vector3)
Scale by vector about origin.
Declaration
public void Scale(Vector3 scalevec)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | scalevec |
Scale(Vector3, Vector3)
Scale by vector about a point.
Declaration
public void Scale(Vector3 scalevec, Vector3 point)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | scalevec | |
| Vector3 | point |
Scale(double)
Scale uniformly about origin.
Declaration
public void Scale(double amount)
Parameters
| Type | Name | Description |
|---|---|---|
| double | amount |
ToString()
Returns a string in the format[[x.x x.y x.z x.w] [y.x y.y y.z y.w] [z.x z.y z.z z.w] [t.x t.y t.z t.w]]
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
View SourceToString(IFormatProvider)
Returns a string in the format[[x.x x.y x.z x.w] [y.x y.y y.z y.w] [z.x z.y z.z z.w] [t.x t.y t.z t.w]]
Declaration
public string ToString(IFormatProvider formatProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IFormatProvider | formatProvider |
Returns
| Type | Description |
|---|---|
| string |
Translate(Vector3)
Translates the matrix by a vector.
Declaration
public void Translate(Vector3 translation)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | translation |
Translate(double, double, double)
Translates the matrix by x,y,z.
Declaration
public void Translate(double dx, double dy, double dz)
Parameters
| Type | Name | Description |
|---|---|---|
| double | dx | |
| double | dy | |
| double | dz |
TranslateLocal(Vector3)
Translates the matrix by a vector in its own coordinate system.
Declaration
public void TranslateLocal(Vector3 translation)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | translation |
TranslateLocal(double, double, double)
Translates the matrix by x,y,z in its own coordinate system.
Declaration
public void TranslateLocal(double dx, double dy, double dz)
Parameters
| Type | Name | Description |
|---|---|---|
| double | dx | |
| double | dy | |
| double | dz |
Transpose()
Transposes the matrix.
Declaration
public void Transpose()
TryParse(string, out Matrix4)
Converts the string representation to its Matrix4 equivalent.
Declaration
public static bool TryParse(string value, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | |
| Matrix4 | result |
Returns
| Type | Description |
|---|---|
| bool | A value indicating whether the conversion succeeded |
TryParse(string, IFormatProvider, out Matrix4)
Converts the string representation to its Matrix4 equivalent.
Declaration
public static bool TryParse(string value, IFormatProvider formatProvider, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | |
| IFormatProvider | formatProvider | |
| Matrix4 | result |
Returns
| Type | Description |
|---|---|
| bool | A value indicating whether the conversion succeeded |
WithEulerZYX(Vector3)
Returns a new Matrix4 with the given Euler ZYX orientation
Declaration
public Matrix4 WithEulerZYX(Vector3 eulerZYX)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | eulerZYX |
Returns
| Type | Description |
|---|---|
| Matrix4 |
WithTranslation(Vector3)
Returns a new Matrix4 with the given translation
Declaration
public Matrix4 WithTranslation(Vector3 translation)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | translation |
Returns
| Type | Description |
|---|---|
| Matrix4 |
Operators
View Sourceoperator *(Matrix4, Matrix4)
Matrix-Matrix multiplication operator.
Declaration
public static Matrix4 operator *(Matrix4 lhs, Matrix4 rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | lhs | |
| Matrix4 | rhs |
Returns
| Type | Description |
|---|---|
| Matrix4 |
operator *(Matrix4, Vector4)
Matrix-Vector4 multiplication operator.
Declaration
public static Vector4 operator *(Matrix4 lhs, Vector4 rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | lhs | |
| Vector4 | rhs |
Returns
| Type | Description |
|---|---|
| Vector4 |