Elements.pyECSS.math_utilities

Utilities and helper functions for basic computer graphics linear/quaternion algebra & real-time rendering components

Elements.pyECSS (Entity Component Systems in a Scenegraph) package @Copyright 2021-2022 Dr. George Papagiannakis

Most methods have been tested against glm equivalent methods: https://github.com/Zuzu-Typ/PyGLM/tree/master/wiki/function-reference

Functions

calculateNormals(p1, p2, p3)

distance(point_a, point_b)

eulerAnglesToRotationMatrix(theta)

Utility function to calculate a 4x4 Rotation Transformation matrix from a vector of euler angles

frustum(xmin, xmax, ymin, ymax, zmin, zmax)

Alternative Perspective projection matrix creation function, where the viewing volume is a truncated pyramid.

identity([rank])

generate a numpy identity matrix

inverse(matrix)

call numpy linalg.inv(a)[source] to compute the inverse of a numpy matrix

lerp(point_a, point_b, fraction)

standard linear interpolation between two vectors and a fraction value

lookat(eye, target, up)

Utility function to calculate a 4x4 camera lookat matrix, based on the eye, target and up camera vectors: based on the gluLookAt() convenience method of https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml and the implementation of https://github.com/g-truc/glm/blob/master/glm/ext/matrix_transform.inl and https://github.com/Zuzu-Typ/PyGLM/blob/master/wiki/function-reference/stable_extensions/matrix_transform.md#lookAt-function

lookatLH(eye, target, up)

Utility function to calculate a 4x4 camera lookat matrix, based on the eye, target and up camera vectors: based on the gluLookAt() convenience method of https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml and the implementation of https://github.com/g-truc/glm/blob/master/glm/ext/matrix_transform.inl and https://github.com/Zuzu-Typ/PyGLM/blob/master/wiki/function-reference/stable_extensions/matrix_transform.md#lookAt-function

normalise(vector)

standard vector normalization over any numpy array

ortho(left, right, bottom, top, near, far)

Orthographic projection matrix creation function, where the viewing volume is a rectangular parallelepiped, or more informally, a box.

perspective(fovy, aspect, near, far)

Perspective projection matrix creation function, where the viewing volume is a truncated pyramid.

quaternion([x, y, z, w])

Generate a quaternion array from 4 values or a vec3 for vector and w for scalar parts (scalar-last list scipy) It has been tested against: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.transform.Rotation.html#scipy.spatial.transform.Rotation

quaternion_from_axis_angle(axis[, degrees, …])

Generate a quaternion from a rotation axis and an angle, scalar-last like scipy # https://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm # https://en.wikipedia.org/wiki/Axis–angle_representation#Rotation_vector

quaternion_from_euler([pitch, yaw, roll, …])

Create a quaternion out of euler angles (pitch = x, yaw = y, roll = z), scalar-last like scipy https://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm

quaternion_matrix(q)

Compute and return a 4x4 matrix from the quaternion q, scalar-last like scipy https://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/index.htm

quaternion_mul(q1, q2)

Compute and return a new quaternion which is the product of two quaternions, scalar-last like scipy https://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/arithmetic/index.htm

quaternion_slerp(q0, q1, fraction)

Spherical linear interpolation from unit q0 to unit q1 based on fraction f: https://en.wikipedia.org/wiki/Slerp#Quaternion_Slerp https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.transform.Slerp.html#scipy.spatial.transform.Slerp http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/

rotate([axis, angle, radians])

From a euclidean axis vector and a rotation angle, generate a standard 4x4 Rotation Transformation matrix based on the original OpenGL formulas defined in: http://www.glprogramming.com/red/appendixf.html and axis-angle theoretical matrix specification: https://en.wikipedia.org/wiki/Rotation_matrix

scale(x[, y, z])

Convert a euclidean scaling vector in homogeneous coordinates to a standard 4x4 Scaling Transformation matrix based on the original OpenGL formulas defined in: http://www.glprogramming.com/red/appendixf.html and OpenGL 1.0 specification.

sincos([degrees, radians])

Utility function to calculate with one call sine and cosine of an angle in radians or degrees If there is one argument, then assumes that single input is in degrees, otherwise ignores first value and takes second for radians (needs two in that case) It returns the value in radians, first sin then cos

translate([x, y, z])

Convert a euclidean translation vector in homogeneous coordinates to a standard 4x4 Translation Transformation matrix based on the original OpenGL formulas defined in: http://www.glprogramming.com/red/appendixf.html and OpenGL 1.0 specification.

vec(*iterable)

return a numpy vector out of any iterable (list, tuple…) as column-major (‘F’)