Auki::Ark::MathHelpers
Collection of helper functions.
Public Types
Name | |
---|---|
enum class | PoseAxis { Right = 0, Up = 1, Forward = 2} Defines common directions. |
Public Functions
Name | |
---|---|
float | XY2Deg(float x, float y) Returns angle for point with coordinates X and Y in degrees. |
float | NominalYRotation(Matrix4x4 m) Returns Y rotation of a specific Matrix4x4 in degrees. |
void | LogMatrix(Matrix4x4 m, string label) Logs a Matrix4x4 in the Unity console. |
string | PoseConstructorString(Pose p) Converts a Pose to string format. |
string | MatrixConstructorString(Matrix4x4 m, string name) Converts a Matrix4x4 to string format. |
float | AngleIn(Quaternion q) Gives sum of rotation around all axes of a quaternion in degrees. |
float | AngleBetween(Quaternion q1, Quaternion q2) Gives angle between 2 quaternion rotations in degrees. |
Quaternion float amountOfRectificationInDegrees | ClosestRotationWithSameAngleToUp(Quaternion toImitate, Quaternion toRectify) |
Matrix4x4 | PoseLocalToWorldMatrix(Pose pose) Constructs a local to world matrix for a pose. |
Matrix4x4 | PoseWorldToLocalMatrix(Pose pose) Constructs a world to local matrix for a pose. |
Matrix4x4 | Pose1ToPose2Matrix(Pose p1, Pose p2) Converts a pose 1 to pose 2 transform matrix. |
Matrix4x4 float upError | ComputeCalibrationMatrixWhileRestrictingRotationToYAxis(Pose officialPose, Pose observedPose, bool observedPoseIsAlreadyRectified =false) |
Vector3 | ExtractScaleFromMatrix(Matrix4x4 matrix) Extracts scale in Vector3 format from a matrix. |
Matrix4x4 | TransformParentToLocalMatrix(Transform t) Constructs a transformation matrix that converts from parent to local coordinate system. |
Matrix4x4 | TransformLocalToParentMatrix(Transform t) Constructs a transformation matrix that converts from local to parent coordinate system. |
void | SetTransformByMatrix(Transform transform, Matrix4x4 matrix, bool skipLocalScale =true) Given a matrix m sets a transform t's rotation and position and scale so that t's local coordinate transformation (from node to parent) is m. |
void | LeftMultiplyTransform(Transform transform, Matrix4x4 matrix, bool skipLocalScale =true) Multiplies input transform by a specified transformation matrix (i.e. T*M). |
Pose float rectificationAmount | SnapPoseAxisTo(Pose pose, PoseAxis axis, Vector3 direction) |
Vector3 | SelectAxis(Pose pose, PoseAxis axis) Given a Pose and PoseAxis, returns the corresponding axis of the pose. |
Pose float PoseAxis Vector3 verticalDirection | SnapPoseToNearestVertical(Pose pose) |
Quaternion | RestrictQuaternionToY(Quaternion q) Keeps rotation only around the Y-axis. |
Public Attributes
Name | |
---|---|
Quaternion | rectifiedRotation Returns a pose that has as close as possible angle to up as the 'toImitate' pose and also the absolute amount of rotation correction that was needed to achieve it. |
Matrix4x4 | calibrationMatrix 0. takes the observed pose of an object and the official pose, in some other coordinate system |
Pose | rectifiedPose Returns a new pose that has a specific axis pointing in a given direction and the absolute amount of rotation correction needed to achieve this. |
Pose float | amountOfRectificationInDegrees |
Pose float PoseAxis | axis |
Public Types Documentation
enum PoseAxis
Enumerator | Value | Description |
---|---|---|
Right | 0 | Right direction. |
Up | 1 | Up direction. |
Forward | 2 | Forward direction. |
Defines common directions.
Public Functions Documentation
function XY2Deg
static float XY2Deg(
float x,
float y
)
Returns angle for point with coordinates X and Y in degrees.
Parameters:
- x X coordinate
- y Y coordinate
Return: Angle in degrees
function NominalYRotation
static float NominalYRotation(
Matrix4x4 m
)
Returns Y rotation of a specific Matrix4x4 in degrees.
Parameters:
- m Input matrix
Return: Angle in degrees
function LogMatrix
static void LogMatrix(
Matrix4x4 m,
string label
)
Logs a Matrix4x4 in the Unity console.
Parameters:
- m Matrix to print
- label Label before data
function PoseConstructorString
static string PoseConstructorString(
Pose p
)
Converts a Pose to string format.
Parameters:
- p Input pose
Return: String representation of input pose
function MatrixConstructorString
static string MatrixConstructorString(
Matrix4x4 m,
string name
)
Converts a Matrix4x4 to string format.
Parameters:
- m Input matrix
- name Name of matrix in string
Return: String representation of input matrix
function AngleIn
static float AngleIn(
Quaternion q
)
Gives sum of rotation around all axes of a quaternion in degrees.
Parameters:
- q Input rotation quaternion
Return: Angle in degrees
function AngleBetween
static float AngleBetween(
Quaternion q1,
Quaternion q2
)
Gives angle between 2 quaternion rotations in degrees.
Parameters:
- q1 Rotation quaternion 1
- q2 Rotation quaternion 2
Return: Angle in degrees
function ClosestRotationWithSameAngleToUp
static Quaternion float amountOfRectificationInDegrees ClosestRotationWithSameAngleToUp(
Quaternion toImitate,
Quaternion toRectify
)
function PoseLocalToWorldMatrix
static Matrix4x4 PoseLocalToWorldMatrix(
Pose pose
)
Constructs a local to world matrix for a pose.
Parameters:
- pose Input pose
Return: Local to world matrix for input pose
function PoseWorldToLocalMatrix
static Matrix4x4 PoseWorldToLocalMatrix(
Pose pose
)
Constructs a world to local matrix for a pose.
Parameters:
- pose Input pose
Return: World to local matrix for input pose
function Pose1ToPose2Matrix
static Matrix4x4 Pose1ToPose2Matrix(
Pose p1,
Pose p2
)
Converts a pose 1 to pose 2 transform matrix.
Parameters:
- p1 Pose to convert from
- p2 Pose to convert to
Return: Pose 1 to pose 2 transformation matrix
function ComputeCalibrationMatrixWhileRestrictingRotationToYAxis
static Matrix4x4 float upError ComputeCalibrationMatrixWhileRestrictingRotationToYAxis(
Pose officialPose,
Pose observedPose,
bool observedPoseIsAlreadyRectified =false
)
function ExtractScaleFromMatrix
static Vector3 ExtractScaleFromMatrix(
Matrix4x4 matrix
)
Extracts scale in Vector3 format from a matrix.
Parameters:
- matrix Input matrix
Return: Vector3 with scale values
function TransformParentToLocalMatrix
static Matrix4x4 TransformParentToLocalMatrix(
Transform t
)
Constructs a transformation matrix that converts from parent to local coordinate system.
Parameters:
- t Local
Return:
function TransformLocalToParentMatrix
static Matrix4x4 TransformLocalToParentMatrix(
Transform t
)
Constructs a transformation matrix that converts from local to parent coordinate system.
Parameters:
- t Local space transformation matrix
Return: Parent space transformation matrix
function SetTransformByMatrix
static void SetTransformByMatrix(
Transform transform,
Matrix4x4 matrix,
bool skipLocalScale =true
)
Given a matrix m sets a transform t's rotation and position and scale so that t's local coordinate transformation (from node to parent) is m.
Parameters:
- transform Transform to multiply
- matrix Matrix to multiply by
- skipLocalScale A boolean to skip the computation of localScale, defaults to true
function LeftMultiplyTransform
static void LeftMultiplyTransform(
Transform transform,
Matrix4x4 matrix,
bool skipLocalScale =true
)
Multiplies input transform by a specified transformation matrix (i.e. T*M).
Parameters:
- transform Transform to multiply
- matrix Matrix to multiply by
- skipLocalScale A boolean to skip the computation of localScale, defaults to true
function SnapPoseAxisTo
static Pose float rectificationAmount SnapPoseAxisTo(
Pose pose,
PoseAxis axis,
Vector3 direction
)
function SelectAxis
static Vector3 SelectAxis(
Pose pose,
PoseAxis axis
)
Given a Pose and PoseAxis, returns the corresponding axis of the pose.
Parameters:
- pose
- axis
Return: A Vector3 that is either pose.forward, pose.right, or pose.up
function SnapPoseToNearestVertical
static Pose float PoseAxis Vector3 verticalDirection SnapPoseToNearestVertical(
Pose pose
)
function RestrictQuaternionToY
static Quaternion RestrictQuaternionToY(
Quaternion q
)
Keeps rotation only around the Y-axis.
Parameters:
- q Rotation quaternion
Return: New rotation quaternion that has only rotation around the Y-axis
Public Attributes Documentation
variable rectifiedRotation
static Quaternion rectifiedRotation;
Returns a pose that has as close as possible angle to up as the 'toImitate' pose and also the absolute amount of rotation correction that was needed to achieve it.
Parameters:
- toImitate Pose whose up axis will be used as reference
- toRectify Pose to rectify
Return: Pose that has as close as possible angle to up as 'toImitate' and absolute amount of rotation correction
variable calibrationMatrix
static Matrix4x4 calibrationMatrix;
- takes the observed pose of an object and the official pose, in some other coordinate system
Parameters:
- officialPose
- observedPose
- observedPoseIsAlreadyRectified
Return: the latter matrix and the angle difference between observedPose and rectifiedObservedPose
- adjusts the observed pose to a new pose "rectifiedObservedPose" that only differs from the from the official pose by a rotation about the Y axis and a translation (i.e., rectifiedObservedPose has "the same angle to up" as officialPose)
- compute the matrix that maps rectifiedObservedPose to officialPose, zeroes out things in the matrix that should be 0 but for floating point errors if the observed pose rotational component is known to already be a rotation around the Y axis of the official pose, one can set the third optional argument to true
variable rectifiedPose
static Pose rectifiedPose;
Returns a new pose that has a specific axis pointing in a given direction and the absolute amount of rotation correction needed to achieve this.
Parameters:
- pose Starting pose
- axis Axis that should be pointing in direction
- direction Direction that the axis should point in
- pose Pose to snap to nearest vertical
Return:
- New pose with given axis pointing in given direction plus the absolute amount of rotation correction
- Snapped pose, total amount of rotation that was needed for the rectification, axis which was snapped to the vertical and vertical direction to which the snapping occured (either Vector3.up or Vector3.down)
Returns a 'rectified' form of the input pose that is 'snapped' to the nearest vertical axis.
variable amountOfRectificationInDegrees
static Pose float amountOfRectificationInDegrees;
variable axis
static Pose float PoseAxis axis;