Matrix44 (hwx.common.math)#

class Matrix44(values=None, origin=None, angles=None, degrees=False, scale=None, xv=None, yv=None, zv=None, xvyv=None, xvzv=None, yvxv=None, yvzv=None, zvxv=None, zvyv=None, xp=None, yp=None, zp=None, xpyp=None, xpzp=None, ypxp=None, ypzp=None, zpxp=None, zpyp=None, eulerParameters=None)#

Bases: list

A 4x4 orthonormal Matrix.

Attribute Table#

Name

Type

angles

property

location

property

origin

property

x

property

y

property

z

property

Method Table#

Name

Description

copy (self)

Creates a copy of self.

divide (self, other)

Returns the result of the multiplication with the inverse of other.

format (self, format=’%s’)

Formats as a string.

getAxisAndAngleOfRotation (self)

Returns the axis and angle from the rotation matrix

getDeterminant (self)

Returns the matrix determinant.

getEulerAngles (self, degrees=False)

Returns the Euler angles.

getTrace (self)

getTranslation (self)

Returns the position as a Point.

invert (self)

Computes the inverse.

isIdentity (self)

Returns True if self is the identity matrix, False otherwise.

multiply (self, other)

Multiplies with other.

multiplyPoint (self, x, y=None, z=None)

Multiplies with a Point.

multiplyVector (self, x, y=None, z=None)

Multiplies with the Vector specified with x, y, z.

orientFromAxes (self, axes, dir1, dir2=(1, 0, 0))

Orients with the specified axes.

orientFromEulerAngles (self, e1, e2=None, e3=None, degrees=False)

Orients with the specified Euler angles.

orientFromEulerParameters (self, e0, e1=None, e2=None, e3=None)

Orients with the specified Euler parameters.

orthogonalize (self)

Orthogonalizes the axes (x, y, z).

multiplyPoint (self, x, y=None, z=None)

Multiplies with a Point.

pts (self, pts)

Returns the result of multiplying each Point in the specified list of

rotate (self, axis, angle, degrees=True)

Rotates around the specified axis.

rotateAroundAxis (self, axis, angle, degrees=True)

Rotates around the axis.

rotx (self, angle, degrees=True)

Rotates around the x-axis.

roty (self, angle, degrees=True)

Rotates around the y-axis.

rotz (self, angle, degrees=True)

Rotates around the z-axis.

scale (self, x, y=None, z=None)

Scales by the specified amount in x, y, z.

setTranslation (self, x, y=None, z=None)

Sets the position as a Point.

translate (self, x=0, y=None, z=None)

Translates by the specified distance each x, y, z vector.

transpose (self)

Returns the transpose.

update (self, other)

Copies the data from other to self.

multiplyVector (self, x, y=None, z=None)

Multiplies with the Vector specified with x, y, z.

zeroSmallValues (self, zero=1e-10)

Sets all components that are less than the specified value to zero.

Example

Define and use Matrices.#
from hwx.common.math import Matrix44

# Constructor using values
mtx = Matrix44(
values=(
   [1, 0, 0, 0],
   [0, 1, 0, 0,  0],
   [0, 0, 1, 0],
   [0.29283,  1.04139,  0.95395, 1]
)
)

print(mtx.format("%.2f"))
print("Location of the matrix as a point is {}, which is equal to the origin {}".format(
mtx.location, mtx.origin))

# Constructor using location and angles
mtx = Matrix44(
origin=[1, 2, 3],
angles=(90, 0, 0),
degrees=True
)
print(mtx)
print("The orientation of the matrix is given by the Euler Angles in radians {}".format(
mtx.angles))
print("A vector along the x axis {}".format(mtx.x))
print("A vector along the y axis {}".format(mtx.y))
print("A vector along the z axis {}".format(mtx.z))
copy()#

Creates a copy of self.

Returns:

The newly created Matrix44.

Return type:

Matrix44

update(other)#

Copies the data from other to self.

Parameters:

other (Matrix44) – The Matrix44 to copy values from.

Returns:

A reference to the instance Matrix44 object on which it was called.

Return type:

Matrix44

orthogonalize()#

Orthogonalizes the axes (x, y, z).

Raises:

RuntimeError – If Matrix44 can not be orthogonalized.

Returns:

A Matrix44 with x, y, z being orthogonal.

Return type:

Matrix44

format(format='%s')#

Formats as a string.

Parameters:

format (str) – The format style to use.

Returns:

A string represantation of the instance Matrix44 object on which it was called.

Return type:

str

isIdentity()#

Returns True if self is the identity matrix, False otherwise.

property angles#

The Euler angles (Body313) in radians.

orientFromEulerAngles(e1, e2=None, e3=None, degrees=False)#

Orients with the specified Euler angles.

Parameters:
  • e1 (float) – Rotation around x-axis.

  • e2 (float) – Rotation around y-axis.

  • e3 (float) – Rotation around z-axis.

  • degrees (bool) – Determines if the angle values are in degrees or not.

Returns:

A reference to the instance Matrix44 object on which it was called.

Return type:

Matrix44

getEulerAngles(degrees=False)#

Returns the Euler angles.

Parameters:

degrees (bool) – Determines if the angle values are in degrees or not.

Returns:

The Euler angles.

Return type:

list

orientFromEulerParameters(e0, e1=None, e2=None, e3=None)#

Orients with the specified Euler parameters.

Parameters:
  • e0 (float) – Euler parameter.

  • e1 (float) – Euler parameter.

  • e2 (float) – Euler parameter.

  • e3 (float) – Euler parameter.

Returns:

A reference to the instance Matrix44 object on which it was called.

Return type:

Matrix44

orientFromAxes(axes, dir1, dir2=(1, 0, 0))#

Orients with the specified axes.

Parameters:
  • axes (str) – The axis to orient by: Valid choices are ‘x’, ‘y’, ‘z’, ‘xy’, ‘xz’, ‘yx’, ‘yz’, ‘zx’, ‘zy’.

  • dir1 (Vector | list[float]) – The vector for the first axis.

  • dir2 (Vector | list[float]) – The vector for the second axis.

Raises:

RuntimeError – In case of unsupported axes specification

Returns:

A reference to the instance Matrix44 object on which it was called.

Return type:

Matrix44

property location#

Returns or sets the location/origin value.

property origin#

Returns or sets the location/origin value.

translate(x=0, y=None, z=None)#

Translates by the specified distance each x, y, z vector.

If y is None, x is assumed to be a list of 3 floats.

Parameters:
  • x (float) – The distance to translate the ‘x’ vector.

  • y (float) – The distance to translate the ‘y’ vector.

  • z (float) – The distance to translate the ‘z’ vector.

Returns:

A reference to the instance Matrix44 object on which it was called.

Return type:

Matrix44

setTranslation(x, y=None, z=None)#

Sets the position as a Point.

If y is None, x is assumed to be a list of 3 floats.

Parameters:
  • x (float) – The vector to set the ‘x’ vector.

  • y (float) – The vector to set the ‘y’ vector.

  • z (float) – The vector to set the ‘z’ vector.

Returns:

A reference to the instance Matrix44 object on which it was called.

Return type:

Matrix44

getTranslation()#

Returns the position as a Point.

scale(x, y=None, z=None)#

Scales by the specified amount in x, y, z.

If y is None, x is assumed to be a list of 3 floats.

Parameters:
  • x (float) – The factor to multiply the ‘x’ vector with.

  • y (float) – The factor to multiply the ‘y’ vector with.

  • z (float) – The factor to multiply the ‘z’ vector with.

Returns:

A newly created Matrix44.

Return type:

Matrix44

rotate(axis, angle, degrees=True)#

Rotates around the specified axis.

This is a body rotation.

Parameters:
  • axis (Vector | str) – The rotation axis. Valid choices are “x”, “y”, “z” or any Vector.

  • angle (float) – The rotation angle.

  • degrees (bool) – Determines if angles is in degrees or not.

Returns:

A newly created Matrix44.

Return type:

Matrix44

rotx(angle, degrees=True)#

Rotates around the x-axis.

This is a body rotation.

Parameters:
  • angle (float) – The rotation angle.

  • degrees (bool) – Determines if angles is in degrees or not.

Returns:

A newly created Matrix44.

Return type:

Matrix44

roty(angle, degrees=True)#

Rotates around the y-axis.

This is a body rotation.

Parameters:
  • angle (float) – The rotation angle.

  • degrees (bool) – Determines if angles is in degrees or not.

Returns:

A newly created Matrix44.

Return type:

Matrix44

rotz(angle, degrees=True)#

Rotates around the z-axis.

This is a body rotation.

Parameters:
  • angle (float) – The rotation angle.

  • degrees (bool) – Determines if angles is in degrees or not.

Returns:

A newly created Matrix44.

Return type:

Matrix44

rotateAroundAxis(axis, angle, degrees=True)#

Rotates around the axis.

This is a body rotation.

Parameters:
  • axis (Vector) – The rotation axis.

  • angle (float) – The rotation angle.

  • degrees (bool) – Determines if angles is in degrees or not.

Returns:

A newly created Matrix44.

Return type:

Matrix44

transpose()#

Returns the transpose.

multiply(other)#

Multiplies with other.

Parameters:

other (float | Point | Vector | Matrix44) – The other to multiply with.

Returns:

The result of the multiplication.

Return type:

Matrix44 | Vector | Point

divide(other)#

Returns the result of the multiplication with the inverse of other.

Parameters:

other (Matrix44) – The Matrix44 to inverse and multiply with.

Returns:

The result of the multiplication with the inverse.

Return type:

Matrix44

invert()#

Computes the inverse.

Returns:

The inverse of the instance Matrix44 object on which it was called.

Return type:

Matrix44

getDeterminant()#

Returns the matrix determinant.

getAxisAndAngleOfRotation()#

Returns the axis and angle from the rotation matrix

zeroSmallValues(zero=1e-10)#

Sets all components that are less than the specified value to zero.

Parameters:

zero (float) – The tolerance on what to zero.

Returns:

A reference to the instance Matrix44 object on which it was called.

Return type:

Matrix44

multiplyPoint(x, y=None, z=None)#

Multiplies with a Point.

Points are represented as mathematical column points and have a one in the fourth position, which includes translation operations.

Parameters:
  • x (Point | list[float] | float) – An itetable of 3 or the x value of a Point.

  • y (float) – The y value of a Point.

  • z (float) – The z value of a Point.

Returns:

The result of the multiplication.

Return type:

Point

pt(x, y=None, z=None)#

Multiplies with a Point.

Points are represented as mathematical column points and have a one in the fourth position, which includes translation operations.

Parameters:
  • x (Point | list[float] | float) – An itetable of 3 or the x value of a Point.

  • y (float) – The y value of a Point.

  • z (float) – The z value of a Point.

Returns:

The result of the multiplication.

Return type:

Point

pts(pts)#

Returns the result of multiplying each Point in the specified list of Points with self.

Parameters:

pts (Point | list[float]) – A Point (or list).

Returns:

The result of the pieswise multiplication.

Return type:

list[Point]

multiplyVector(x, y=None, z=None)#

Multiplies with the Vector specified with x, y, z.

Vectors are represented as mathematical column vectors and have a zero in the fourth position, which does not include translation operations.

Parameters:
  • x (Vector | list[float] | float) – An itetable of 3 or the x value of a Vector.

  • y (float) – The y value of a Vector.

  • z (float) – The z value of a Vector.

Returns:

The result of the multiplication.

Return type:

Vector

vec(x, y=None, z=None)#

Multiplies with the Vector specified with x, y, z.

Vectors are represented as mathematical column vectors and have a zero in the fourth position, which does not include translation operations.

Parameters:
  • x (Vector | list[float] | float) – An itetable of 3 or the x value of a Vector.

  • y (float) – The y value of a Vector.

  • z (float) – The z value of a Vector.

Returns:

The result of the multiplication.

Return type:

Vector

property x#

The vector along the x-axis.

property y#

The vector along the y-axis.

property z#

The vector along the z-axis.

zp(pt1, pt2=None)#

Depricated