Version 3.3.0.1

MathUtilities class

Namespace: Sirenix.Utilities
Assembly: Sirenix.Utilities
public static class MathUtilities
Collection of math function.
Inheritance
  • System.Object
  • MathUtilities

Methods

Abs(Vector3)
Returns a Vector2 with each element set to their respective sign.
public static Vector3 Abs(this Vector3 v)
Parameters
UnityEngine.Vector3 v

The vector to sign.

Returns
UnityEngine.Vector3

Bounce(Single)
Returns a value that bounces between 0 and 1 based on value.
public static float Bounce(float value)
Parameters
System.Single value

The value to bounce.

Returns
System.Single

BounceEaseInFastOut(Single)
Returns a value based on t, that bounces faster and faster.
public static float BounceEaseInFastOut(float t)
Parameters
System.Single t

The value to bounce.

Returns
System.Single

Clamp(Vector2, Vector2, Vector2)
Clamps the value of a Vector2.
public static Vector2 Clamp(this Vector2 value, Vector2 min, Vector2 max)
Parameters
UnityEngine.Vector2 value

The vector to clamp.

UnityEngine.Vector2 min

The min value.

UnityEngine.Vector2 max

The max value.

Returns
UnityEngine.Vector2

Clamp(Vector3, Vector3, Vector3)
Clamps the value of a Vector3.
public static Vector3 Clamp(this Vector3 value, Vector3 min, Vector3 max)
Parameters
UnityEngine.Vector3 value

The vector to clamp.

UnityEngine.Vector3 min

The min value.

UnityEngine.Vector3 max

The max value.

Returns
UnityEngine.Vector3

ClampWrapAngle(Single, Single, Single)
Clamps and wraps an angle between two values.
public static float ClampWrapAngle(float angle, float min, float max)
Parameters
System.Single angle

System.Single min

System.Single max

Returns
System.Single

ComputeByteArrayHash(Byte[])
Computes a hash for a byte array.
public static int ComputeByteArrayHash(byte[] data)
Parameters
System.Byte[] data

The byte array.

Returns
System.Int32

DiscardLeastSignificantDecimal(Double)
Discards the least significant demicals.
public static double DiscardLeastSignificantDecimal(double v)
Parameters
System.Double v

The value of insignificant decimals.

Returns
System.Double

Value with significant decimals.

EaseInElastic(Single, Single, Single)
Returns a value that eases in elasticly.
public static float EaseInElastic(float value, float amplitude = 0.25F, float length = 0.6F)
Parameters
System.Single value

The value to ease in elasticly.

System.Single amplitude

The amplitude.

System.Single length

The length.

Returns
System.Single

EaseInOut(Single)
Returns a smooth value betweeen that peaks at t=0.5 and then comes back down again.
public static float EaseInOut(float t)
Parameters
System.Single t

A value between 0 and 1.

Returns
System.Single

EaseOutElastic(Single, Single, Single)
Returns a value that eases out elasticly.
public static float EaseOutElastic(float value, float amplitude = 0.25F, float length = 0.6F)
Parameters
System.Single value

The value to ease out elasticly.

System.Single amplitude

The amplitude.

System.Single length

The length.

Returns
System.Single

Fract(Single)
Returns the fractional of the value.
public static float Fract(float value)
Parameters
System.Single value

The value to get the fractional of.

Returns
System.Single

Fract(Vector2)
Returns the fractional of the value.
public static Vector2 Fract(Vector2 value)
Parameters
UnityEngine.Vector2 value

The value to get the fractional of.

Returns
UnityEngine.Vector2

Fract(Vector3)
Returns the fractional of the value.
public static Vector3 Fract(Vector3 value)
Parameters
UnityEngine.Vector3 value

The value to get the fractional of.

Returns
UnityEngine.Vector3

Hermite(Single, Single, Single)
Returns a smooth value between start and end based on t.
public static float Hermite(float start, float end, float t)
Parameters
System.Single start

First point.

System.Single end

Second point.

System.Single t

Position between 0 and 1.

Returns
System.Single

Hermite01(Single)
Returns a smooth value between 0 and 1 based on t.
public static float Hermite01(float t)
Parameters
System.Single t

Position between 0 and 1.

Returns
System.Single

InfiniteLineIntersect(Vector2, Vector2, Vector2, Vector2)
Returns the collision point between two infinite lines.
public static Vector2 InfiniteLineIntersect(Vector2 ps1, Vector2 pe1, Vector2 ps2, Vector2 pe2)
Parameters
UnityEngine.Vector2 ps1

UnityEngine.Vector2 pe1

UnityEngine.Vector2 ps2

UnityEngine.Vector2 pe2

Returns
UnityEngine.Vector2

InterpolatePoints(Vector3[], Single)
Gives a smooth path between a collection of points.
public static Vector3 InterpolatePoints(Vector3[] path, float t)
Parameters
UnityEngine.Vector3[] path

The collection of point.

System.Single t

The current position in the path. 0 is at the start of the path, 1 is at the end of the path.

Returns
UnityEngine.Vector3

LerpUnclamped(Vector2, Vector2, Single)
Returns an unclamped linear interpolation of two vectors.
public static Vector2 LerpUnclamped(Vector2 from, Vector2 to, float amount)
Parameters
UnityEngine.Vector2 from

The first vector.

UnityEngine.Vector2 to

The second vector.

System.Single amount

The interpolation factor.

Returns
UnityEngine.Vector2

LerpUnclamped(Vector3, Vector3, Single)
Returns an unclamped linear interpolation of two vectors.
public static Vector3 LerpUnclamped(Vector3 from, Vector3 to, float amount)
Parameters
UnityEngine.Vector3 from

The first vector.

UnityEngine.Vector3 to

The second vector.

System.Single amount

The interpolation factor.

Returns
UnityEngine.Vector3

LinearStep(Single, Single, Single)
Interpolates t between a and b to a value between 0 and 1.
public static float LinearStep(float a, float b, float t)
Parameters
System.Single a

The first value.

System.Single b

The second value.

System.Single t

The position value.

Returns
System.Single

Linear value between 0 and 1.

LineDistToPlane(Vector3, Vector3, Vector3, Vector3)
Distance from line to plane.
public static float LineDistToPlane(Vector3 planeOrigin, Vector3 planeNormal, Vector3 lineOrigin, Vector3 lineDirectionNormalized)
Parameters
UnityEngine.Vector3 planeOrigin

Position of the plane.

UnityEngine.Vector3 planeNormal

Surface normal of the plane.

UnityEngine.Vector3 lineOrigin

Origin of the line.

UnityEngine.Vector3 lineDirectionNormalized

Line direction normal.

Returns
System.Single

LineIntersectsLine(Vector2, Vector2, Vector2, Vector2, out Vector2)
Checks if two given lines intersect with one another and returns the intersection point (if any) in an out parameter. Source: http://stackoverflow.com/questions/3746274/line-intersection-with-aabb-rectangle. Edited to implement Cohen-Sutherland type pruning for efficiency.
public static bool LineIntersectsLine(Vector2 a1, Vector2 a2, Vector2 b1, Vector2 b2, out Vector2 intersection)
Parameters
UnityEngine.Vector2 a1

Starting point of line a.

UnityEngine.Vector2 a2

Ending point of line a.

UnityEngine.Vector2 b1

Starting point of line b.

UnityEngine.Vector2 b2

Ending point of line b.

UnityEngine.Vector2 intersection

The out parameter which contains the intersection point if there was any.

Returns
System.Boolean

True if the two lines intersect, otherwise false.

PointDistanceToLine(Vector3, Vector3, Vector3)
Distance from a point to a line.
public static float PointDistanceToLine(Vector3 point, Vector3 a, Vector3 b)
Parameters
UnityEngine.Vector3 point

UnityEngine.Vector3 a

UnityEngine.Vector3 b

Returns
System.Single

Pow(Vector3, Single)
Pows each element of the vector.
public static Vector3 Pow(this Vector3 v, float p)
Parameters
UnityEngine.Vector3 v

The vector.

System.Single p

The power.

Returns
UnityEngine.Vector3

RayDistToPlane(Ray, Plane)
Distance from ray to plane.
public static float RayDistToPlane(Ray ray, Plane plane)
Parameters
UnityEngine.Ray ray

The ray.

UnityEngine.Plane plane

The plane.

Returns
System.Single

RotatePoint(Vector2, Single)
Rotates a Vector2 by an angle.
public static Vector2 RotatePoint(Vector2 point, float degrees)
Parameters
UnityEngine.Vector2 point

The point to rotate.

System.Single degrees

The angle to rotate.

Returns
UnityEngine.Vector2

RotatePoint(Vector2, Vector2, Single)
Rotates a Vector2 around a point by an angle..
public static Vector2 RotatePoint(Vector2 point, Vector2 around, float degrees)
Parameters
UnityEngine.Vector2 point

The point to rotate.

UnityEngine.Vector2 around

The point to rotate around.

System.Single degrees

The angle to rotate.

Returns
UnityEngine.Vector2

RoundBasedOnMinimumDifference(Double, Double)
Rounds a number based on a mininum difference.
public static double RoundBasedOnMinimumDifference(double valueToRound, double minDifference)
Parameters
System.Double valueToRound

The value to round.

System.Double minDifference

The min difference.

Returns
System.Double

The rounded value.

Sign(Vector3)
Returns a Vector3 with each element set to their respective sign.
public static Vector3 Sign(this Vector3 v)
Parameters
UnityEngine.Vector3 v

The vector to sign.

Returns
UnityEngine.Vector3

SmoothStep(Single, Single, Single)
Interpolates t between a and b to a value between 0 and 1 using a Hermite polynomial.
public static float SmoothStep(float a, float b, float t)
Parameters
System.Single a

The first value.

System.Single b

The second value.

System.Single t

The position value.

Returns
System.Single

A smoothed value between 0 and 1.

StackHermite(Single, Single, Single, Int32)
Returns a smooth value between start and end based on t.
public static float StackHermite(float start, float end, float t, int count)
Parameters
System.Single start

First point.

System.Single end

Second point.

System.Single t

Position between 0 and 1.

System.Int32 count

Number of interpolations to make.

Returns
System.Single

StackHermite01(Single, Int32)
Returns a smooth value between 0 and 1 based on t.
public static float StackHermite01(float t, int count)
Parameters
System.Single t

Position between 0 and 1.

System.Int32 count

Number of interpolations to make.

Returns
System.Single

Wrap(Double, Double, Double)
Wraps a value between min and max.
public static double Wrap(double value, double min, double max)
Parameters
System.Double value

The value to wrap.

System.Double min

The minimum value.

System.Double max

The maximum value.

Returns
System.Double

Wrap(Int32, Int32, Int32)
Wraps a value between min and max.
public static int Wrap(int value, int min, int max)
Parameters
System.Int32 value

The value to wrap.

System.Int32 min

The minimum value.

System.Int32 max

The maximum value.

Returns
System.Int32

Wrap(Single, Single, Single)
Wraps a value between min and max.
public static float Wrap(float value, float min, float max)
Parameters
System.Single value

The value to wrap.

System.Single min

The minimum value.

System.Single max

The maximum value.

Returns
System.Single