EntitiesSamples/Docs/cheatsheet/mathematics.src.md
Most of the methods in Mathematics have many overloads for different combinations of types. For example, math.abs() takes vector arguments, not just scalars, e.g. math.abs(new int3(5, -7, -1)) returns new int3(5, 7, 1). This cheat sheet does not exhaustively demonstrate all of the overloads. Consult the API reference for the full list.
In this page:
math | Class containing many static mathematical constants and methods. |
noise | Class containing static methods for generating noise. |
quaternion | Struct representing a rotation. |
Random | Struct for generating random numbers. |
RigidTransform | Struct representing a transform matrix. |
half | A 16-bit floating-point number. |
bool2, bool3, bool4 |
int2, int3, int4 |
uint2, uint3, uint4 |
float2, float3, float4 |
half2, half3, half4 |
double2, double3, double4 |
The vector and matrix operators (+, -, *, /, %, --, ++, ==, !=, <, >, <=, >=) operate upon corresponding component pairs:
The integer vector and matrix types also have bitwise operators: &, |, ~, <<, >>.
math.fmod | The floating point remainder of x/y. |
math.mad | Componentwise (a * b + c) on three scalars or vectors. |
math.modf | Modulus and fractional component. |
math.csum | Horizontal sum of components of a vector. |
math.rcp | Reciprocal (1 divided by the value). |
math.ceillog2 | Ceiling of the base-2 logarithm. |
math.ceilpow2 | Smallest power of two greater than or equal to the input. |
math.exp | The constant e raised to a power. |
math.exp10 | The value 10 raised to a power. |
math.exp2 | The value 2 raised to a power. |
math.floorlog2 | Floor of the base-2 logarithm. |
math.log | Natural logarithm. |
math.log10 | Base-10 logarithm |
math.log2 | Base-2 logarithm. |
math.pow | Raised to a power. |
math.rsqrt | Reciprocal of the square root. |
math.sqrt | Square root. |
math.abs | Absolute value. |
math.ceil | Round up. |
math.floor | Round down. |
math.round | Round to nearest. |
math.sign | The sign of a value: +1, 0 , or -1 |
math.isfinite | Is finite floating-point value? |
math.isinf | Is infinite floating-point value? |
math.isnan | Is NaN? |
math.ispow2 | Is power of 2? |
math.asdouble | Reinterpret the bits of a 64-bit integer as a double. |
math.asfloat | Reinterpret the bits of a 32-bit integer as a float. |
math.asint | Reinterpret the bits of a float or uint as an int. |
math.aslong | Reinterpret the bits of a double or 64-bit integer as a long. |
math.asulong | Reinterpret the bits of a double or 64-bit integer as a ulong. |
math.asuint | Reinterpret the bits of a float or uint as a uint. |
math.f16tof32 | The floating point representation of a half-precision floating-point value. |
math.f32tof16 | Nearest half-precision floating-point representation of a floating-point value. |
math.frac | Fractional part of a floating-point value. |
math.trunc | Integral part of a floating-point value (rounded towards zero). |
math.clamp | Clamp a value into an interval. |
math.lerp | Linear interpolation between two values. |
math.nlerp | Normalized linear interpolation between two quaternions. |
math.remap | Non-clamping, linear remapping of a value from a source range to a destination range. |
math.saturate | Clamp a value into the interval [0, 1]. |
math.slerp | Spherical interpolation between two quaternions. |
math.smoothstep | Smooth Hermite interpolation between 0.0f and 1.0f. |
math.step | Return 1.0f if x >= y, otherwise returns 0.0f. |
math.unlerp | Normalize a value into a range. (Opposite of lerp.) |
math.shuffle | Pick one or more specific components from two vectors. |
math.select | Pick between two values based on a boolean. Similar to the ternary operator, but you can also pick specific components of two vectors. |
math.cmax | Largest component of a vector. |
math.cmin | Smallest component of a vector. |
math.max | Largest of two values. |
math.min | Smallest of two values. |
See the Collections package for more hashing options.
math.hash | Hash of a value. |
math.hashwide | When hashing multiple values together, it's often more efficient to separately pass them to hashwide(), combine the results, then hash() the combination. |
math.all | True if all booleans are true. |
math.any | True if any boolean is true. |
math.bitmask | Bitmask of a bool4: one bit per component (4 bits in total) in LSB order (lower to higher). |
math.countbits | Count of the 1-bits. |
math.compress | Packs mask-enabled components of a vector to the left. |
math.lzcnt | Leading zero count of the bits. |
math.reversebits | Reverse the order of the bits. |
math.rol | Rotate bits left. |
math.ror | Rotate bits right. |
math.tzcnt | Trailing zero count of the bits. |
math.acos | Arccosine. |
math.asin | Arcsine. |
math.atan | Arctangent |
math.atan2 | Arctangent for 2 arguments. |
math.cos | Cosine. |
math.cosh | Hyperbolic cosine. |
math.math.degrees | Degrees from radians. |
math.radians | Radians from degrees. |
math.sin | Sine. |
math.sincos | Sinecosine. |
math.sinh | Hyberbolic sine. |
math.tan | Tangent. |
math.tanh | Hyberbolic tangent. |
math.cross | Cross product. |
math.distance | Distance between two points (1 to 4 dimensions). |
math.distancesq | Square root of distance between two points (1 to 4 dimensions). |
math.dot | Dot product. |
math.faceforward | Flips a vector if two other vectors point in the same direction (i.e. the angle between them is less than or equal to 90 degrees). |
math.length | Distance of a point from the origin. |
math.lengthsq | Square root of the distance of a point from the origin. |
math.normalize | Normalized vector. |
math.normalizesafe | Normalized vector. Returns the default value if the normalized vector is not finite. |
math.project | Project a vector on to another. |
math.projectsafe | Project a vector on to another. Returns the default value if the projected vector is not finite. |
math.reflect | Reflection of an incident vector and a normal vector. |
math.refract | Refraction of an incident vector and a normal vector. |
math.transform | Transform a 3-dimensional vector with a 4x4 matrix. |
math.forward | The forward axis in Unity coordinates. |
math.back | The back axis in Unity coordinates. |
math.up | The up axis in Unity coordinates. |
math.down | The down axis in Unity coordinates. |
math.left | The left axis in Unity coordinates. |
math.right | The right axis in Unity coordinates. |
math.determinant | Determinant of a matrix. |
math.fastinverse | Fast matrix inverse for rigid transforms (orthonormal basis and translation). |
math.inverse | Inverse of a matrix or quaternion. |
math.mul | Matrix multiplication. |
math.transpose | Transpose of a matrix. |
math.unitlog | Natural logarithm of a unit length quaternion. |
math.conjugate | Conjugate a quaternion. (Flips the signs of x, y, and z but not w.) |
math.orthonormalize | Orthonormalize a float3x3 matrix. |
math.rotate | Rotate a vector by a unit quaternion. |
math.unitexp | Natural exponent of a quaternion. (Assumes w is zero.) |
quaternion.AxisAngle | Quaternion representation of an axis-angle rotation. |
quaternion.Euler | Quaternion representation of an Euler angle rotation (axis order specified by argument). |
quaternion.EulerXYZ | Quaternion representation of an Euler angle rotation (axis order XYZ). |
quaternion.EulerXZY | Quaternion representation of an Euler angle rotation (axis order XZY). |
quaternion.EulerYXZ | Quaternion representation of an Euler angle rotation (axis order YXZ). |
quaternion.EulerYZX | Quaternion representation of an Euler angle rotation (axis order YZX). |
quaternion.EulerZXY | Quaternion representation of an Euler angle rotation (axis order ZXY). |
quaternion.EulerZYX | Quaternion representation of an Euler angle rotation (axis order ZYX). |
quaternion.LookRotation | Quaternion representing a rotation derived from a unit-length forward vector and a unit-length upwards vector. |
quaternion.LookRotationSafe | Quaternion representing a rotation derived from a forward vector and an upwards vector. |
quaternion.RotateX | Quaternion representation of a rotation around the X axis. |
quaternion.RotateY | Quaternion representation of a rotation around the Y axis. |
quaternion.RotateZ | Quaternion representation of a rotation around the Z axis. |
float4x4.LookAt | View matrix derived from an eye position, a target point, and a uni-length upwards vector. |
float4x4.Ortho | Orthographic projection matrix |
float4x4.OrthoOffCenter | Off-center orthographic projection matrix. |
float4x4.PerspectiveFov | Perspective projection matrix based on field of view. |
float4x4.PerspectiveOffCenter | Off-center perspective projection matrix |
float4x4.Scale | Matrix representing a scale transform. |
float4x4.Translate | Matrix representing a translation transform. |
float4x4.TRS | Matrix representing a combined translation, rotation, and scale transform. |
float3x3.Scale | Matrix representing a scale transform. |
RigidTransform.Translate | Matrix representing a translation transform. |
RigidTransform, float3x3, and float4x4 also have most of the same rotation methods as quaternion.
noise.cellular(float2) | 2D Cellular noise ("Worley noise") with standard 3x3 search window for good feature point values. |
noise.cellular(float3) | 3D Cellular noise ("Worley noise") with 3x3x3 search region for good F2 everywhere, but a lot slower than the 2x2x2 version. |
noise.cellular2x2 | 2D Cellular noise ("Worley noise") with a 2x2 search window. |
noise.cellular2x2x2 | 3D Cellular noise ("Worley noise") with a 2x2x2 search window. |
noise.cnoise | Classic Perlin noise. |
noise.pnoise | Classic Perlin noise, periodic variant. |
noise.psrdoise | 2-D tiling simplex noise with fixed or rotating gradients and analytical derivative. |
noise.psrnoise | 2-D tiling simplex noise with fixed or rotating gradients, but without the analytical derivative. |
noise.snoise | Simplex noise. |
noise.srdnoise | 2-D non-tiling simplex noise with fixed or rotating gradients and analytical derivative. |
noise.srnoise | 2-D non-tiling simplex noise with fixed or rotating gradients, without the analytical derivative. |