Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


PhysicsMath

A set of mathematical operations that are useful for physics. These operations do not form a fully comprehensive mathematics library, they simply provide operations that are usually required when interacting with physics.
Read time 4 minutesLast updated 6 days ago

Definition

public readonly struct PhysicsMath : IEquatable<PhysicsMath>

Static Fields

Value

Description

EpsilonA small tolerance value used to test whether a value is close enough to zero to be treated as zero.

Static Properties

Property

Description

PIGet the value of PI used internally by the physics system. Using this will help with determinism.
TAUGet the value of tau (2 * PI) used internally by the physics system. Using this will help with determinism.

Static Methods

Method

Description

AngularVelocityToQuaternionCalculate a Quaternion given a 2D angular velocity and a time to integrate over using the selected transform plane.
Atan2Calculate the arc-tangent i.e. the angle of the provided slope y/x. This operates as deterministically as possible across platforms.
CosSinCalculate both the Cosine and Sine of the specified angle.
GetRelativeMatrixGet the relative transformation matrix between the two specified transforms using the specified transform plane.
GetRelativeMatrix2DGet the relative transformation matrix between the two specified transform matrix using the specified world's transform plane to transform into 2D space.
GetRelativePose2DGet the relative transformation pose (translation, rotation and scale) between the two specified transform matrix using the specified world's transform plane to transform into 2D space.
GetRotationAxesGet the used rotation axes, given the specified transform plane. This is the inverse of PhysicsMath.GetRotationIgnoredAxes. If PhysicsWorld.TransformPlane.Custom is used, PhysicsWorld.TransformPlane.XY will be used instead which may not provide the correct results.
GetRotationIgnoredAxesGet the ignored rotation axes, given the specified transform plane. This is the inverse of PhysicsMath.GetRotationAxes. If PhysicsWorld.TransformPlane.Custom is used, PhysicsWorld.TransformPlane.XY will be used instead which may not provide the correct results.
GetTranslationAxesGet the used translation axes, given the specified transform plane. This is the inverse of PhysicsMath.GetTranslationIgnoredAxes. If PhysicsWorld.TransformPlane.Custom is used, PhysicsWorld.TransformPlane.XY will be used instead which may not provide the correct results.
GetTranslationIgnoredAxesGet the ignored translation axes, given the specified transform plane. This is the inverse of PhysicsMath.GetTranslationAxes. If PhysicsWorld.TransformPlane.Custom is used, PhysicsWorld.TransformPlane.XY will be used instead which may not provide the correct results.
GetTranslationIgnoredAxisGet the ignored translation axis, given the specified transform plane. If PhysicsWorld.TransformPlane.Custom is used, PhysicsWorld.TransformPlane.XY will be used instead which may not provide the correct results.
IsFiniteGet whether both components of the specified vector are finite i.e. neither NaN nor infinite.
MaxAbsComponentGet the maximum absolute value component from the specified vector.
MinAbsComponentGet the minimum absolute value component from the specified vector.
SetTransformFast2DSet the Transform position and rotation using the specified world's transform plane. For position, only two axis will be updated with the others remaining unchanged. For rotation, only a single rotation axis will be changed with the others set to zero.
SetTransformSlow3DSet the Transform position and rotation using the specified world's transform plane. For position, only two axis will be updated with the others remaining unchanged. For rotation, only a single rotation axis will be changed with the others remaining unchanged.
SpringDamperCalculate a one-dimensional mass-spring-damper simulation which drives towards a zero translation. You can then compute the new position using: "translation += newSpeed * deltaTime;"
SwizzleTransform a Matrix position (with perspective divide) into a Matrix position using the selected transform plane. If PhysicsWorld.TransformPlane.Custom is used, PhysicsWorld.TransformPlane.XY will be used instead which may not provide the correct results.
ToDegreesConvert radians to degrees. This operates as deterministically as possible across platforms. See PhysicsMath.ToRadians.
ToPhysicsTransformTransform a 3D Transform position and rotation to a 2D PhysicsTransform using the specified world's transform plane. Scale is not part of a PhysicsTransform therefore it is ignored.
ToPosition2DTransform a Transform's world position into a 2D position using the specified world's transform plane.
ToPosition3DTransform a 2D position into a 3D position using the specified world's transform plane, taking the out-of-plane depth from a Transform.
ToRadiansConvert degrees to radians. This operates as deterministically as possible across platforms. See PhysicsMath.ToDegrees.
ToRotation2DTransform a 3D rotation into a 2D angle using the specified world's transform plane.
ToRotationFast3DTransform a 2D angle into a 3D rotation using the specified world's transform plane (Fast). The transformation is fast because the rotation is simplified by the fact that only a single axis of rotation is handled. All other axis rotations are reset to zero.
ToRotationSlow3DTransform a 2D angle into a 3D rotation using the specified world's transform plane (Slow). The transformation is slower because the rotation is more complex due to the fact that changing a single axis of rotation requires it to not affect any other axis rotations.
TryGetPlaneMatrix2DTry to get a matrix suitable for use with PhysicsMath.GetRelativeMatrix2D or PhysicsMath.GetRelativePose2D from the specified matrix, ignoring its scale on the transform plane's out-of-plane axis.
TryGetRelativeMatrix2DTry to get the relative transformation matrix between the two specified transform matrix using the specified world's transform plane, never returning a NaN result.