A* Pathfinding Project  3.8.5
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
AstarMath Class Reference

Utility functions for working with numbers and strings. More...

Detailed Description

Utility functions for working with numbers and strings.

See Also
Polygon
VectorMath

Static Public Member Functions

static float Abs (float a)
 
static int Abs (int a)
 
static float Clamp (float a, float b, float c)
 
static int Clamp (int a, int b, int c)
 
static float Clamp01 (float a)
 
static int Clamp01 (int a)
 
static int ComputeVertexHash (int x, int y, int z)
 
static Vector3 CubicBezier (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
 Returns a point on a cubic bezier curve.
 
static float DistancePointSegment (int x, int z, int px, int pz, int qx, int qz)
 Returns the approximate shortest squared distance between x,z and the line p-q.
 
static float DistancePointSegment (Int3 a, Int3 b, Int3 p)
 Returns the approximate shortest squared distance between x,z and the line p-q.
 
static float DistancePointSegment2 (int x, int z, int px, int pz, int qx, int qz)
 
static float DistancePointSegment2 (Vector3 a, Vector3 b, Vector3 p)
 
static float DistancePointSegmentStrict (Vector3 a, Vector3 b, Vector3 p)
 Returns the squared distance between c and the line a-b.
 
static string FormatBytes (int bytes)
 
static string FormatBytesBinary (int bytes)
 Returns a nicely formatted string for the number of bytes (KiB, MiB, GiB etc).
 
static float Hermite (float start, float end, float value)
 
static Color HSVToRGB (float h, float s, float v)
 Converts an HSV color to an RGB color.
 
static Color IntToColor (int i, float a)
 Returns a nice color from int i with alpha a.
 
static float Lerp (float a, float b, float t)
 
static float MagnitudeXZ (Vector3 a, Vector3 b)
 
static float MapTo (float startMin, float startMax, float value)
 Maps a value between startMin and startMax to be between 0 and 1.
 
static float MapTo (float startMin, float startMax, float targetMin, float targetMax, float value)
 Maps a value between startMin and startMax to be between targetMin and targetMax.
 
static float MapToRange (float targetMin, float targetMax, float value)
 
static float Max (float a, float b)
 
static int Max (int a, int b)
 
static uint Max (uint a, uint b)
 
static ushort Max (ushort a, ushort b)
 
static float Min (float a, float b)
 
static int Min (int a, int b)
 
static uint Min (uint a, uint b)
 
static Vector3 NearestPoint (Vector3 lineStart, Vector3 lineEnd, Vector3 point)
 Returns the closest point on the line.
 
static float NearestPointFactor (Vector3 lineStart, Vector3 lineEnd, Vector3 point)
 
static float NearestPointFactor (Int3 lineStart, Int3 lineEnd, Int3 point)
 Factor of the nearest point on the segment.
 
static float NearestPointFactor (Int2 lineStart, Int2 lineEnd, Int2 point)
 Factor of the nearest point on the segment.
 
static Vector3 NearestPointStrict (Vector3 lineStart, Vector3 lineEnd, Vector3 point)
 Returns the closest point on the line segment.
 
static Vector3 NearestPointStrictXZ (Vector3 lineStart, Vector3 lineEnd, Vector3 point)
 Returns the closest point on the line segment on the XZ plane.
 
static int Repeat (int i, int n)
 
static int RoundToInt (float v)
 
static int RoundToInt (double v)
 
static float Sign (float a)
 
static int Sign (int a)
 
static float SqrMagnitudeXZ (Vector3 a, Vector3 b)
 Squared distance between two points on the XZ plane.
 

Static Private Member Functions

static int Bit (int a, int b)
 Returns bit number b from int a.
 

Member Function Documentation

static float Abs ( float  a)
static
Deprecated:
Use Mathf.Abs instead
static int Abs ( int  a)
static
Deprecated:
Use Mathf.Abs instead
static int Bit ( int  a,
int  b 
)
staticprivate

Returns bit number b from int a.

The bit number is zero based. Relevant b values are from 0 to 31
Equals to (a >> b) & 1

static float Clamp ( float  a,
float  b,
float  c 
)
static
Deprecated:
Use Mathf.Clamp instead
static int Clamp ( int  a,
int  b,
int  c 
)
static
Deprecated:
Use Mathf.Clamp instead
static float Clamp01 ( float  a)
static
Deprecated:
Use Mathf.Clamp01 instead
static int Clamp01 ( int  a)
static
Deprecated:
Use Mathf.Clamp01 instead
static int ComputeVertexHash ( int  x,
int  y,
int  z 
)
static
static Vector3 CubicBezier ( Vector3  p0,
Vector3  p1,
Vector3  p2,
Vector3  p3,
float  t 
)
static

Returns a point on a cubic bezier curve.

t is clamped between 0 and 1

static float DistancePointSegment ( int  x,
int  z,
int  px,
int  pz,
int  qx,
int  qz 
)
static

Returns the approximate shortest squared distance between x,z and the line p-q.

The line is considered infinite. This function is not entirely exact, but it is about twice as fast as DistancePointSegment2.

static float DistancePointSegment ( Int3  a,
Int3  b,
Int3  p 
)
static

Returns the approximate shortest squared distance between x,z and the line p-q.

The line is considered infinite. This function is not entirely exact, but it is about twice as fast as DistancePointSegment2.

static float DistancePointSegment2 ( int  x,
int  z,
int  px,
int  pz,
int  qx,
int  qz 
)
static
Deprecated:
Obsolete
static float DistancePointSegment2 ( Vector3  a,
Vector3  b,
Vector3  p 
)
static
Deprecated:
Obsolete
static float DistancePointSegmentStrict ( Vector3  a,
Vector3  b,
Vector3  p 
)
static

Returns the squared distance between c and the line a-b.

The line is not considered infinite.

static string FormatBytes ( int  bytes)
static
Deprecated:
Obsolete
static string FormatBytesBinary ( int  bytes)
static

Returns a nicely formatted string for the number of bytes (KiB, MiB, GiB etc).

Uses decimal names (KB, Mb - 1000) but calculates using binary values (KiB, MiB - 1024)

static float Hermite ( float  start,
float  end,
float  value 
)
static
Deprecated:
Obsolete
static Color HSVToRGB ( float  h,
float  s,
float  v 
)
static

Converts an HSV color to an RGB color.

According to the algorithm described at http://en.wikipedia.org/wiki/HSL_and_HSV

Author
Wikipedia
Returns
the RGB representation of the color.
static Color IntToColor ( int  i,
float  a 
)
static

Returns a nice color from int i with alpha a.

Got code from the open-source Recast project, works really well
Seems like there are only 64 possible colors from studying the code

static float Lerp ( float  a,
float  b,
float  t 
)
static
Deprecated:
Use Mathf.Lerp instead
static float MagnitudeXZ ( Vector3  a,
Vector3  b 
)
static
Deprecated:
Obsolete
static float MapTo ( float  startMin,
float  startMax,
float  value 
)
static

Maps a value between startMin and startMax to be between 0 and 1.

static float MapTo ( float  startMin,
float  startMax,
float  targetMin,
float  targetMax,
float  value 
)
static

Maps a value between startMin and startMax to be between targetMin and targetMax.

static float MapToRange ( float  targetMin,
float  targetMax,
float  value 
)
static
Deprecated:
Obsolete
static float Max ( float  a,
float  b 
)
static
Deprecated:
Use Mathf.Max instead
static int Max ( int  a,
int  b 
)
static
Deprecated:
Use Mathf.Max instead
static uint Max ( uint  a,
uint  b 
)
static
Deprecated:
Use Mathf.Max instead
static ushort Max ( ushort  a,
ushort  b 
)
static
Deprecated:
Use Mathf.Max instead
static float Min ( float  a,
float  b 
)
static
Deprecated:
Use Mathf.Min instead
static int Min ( int  a,
int  b 
)
static
Deprecated:
Use Mathf.Min instead
static uint Min ( uint  a,
uint  b 
)
static
Deprecated:
Use Mathf.Min instead
static Vector3 NearestPoint ( Vector3  lineStart,
Vector3  lineEnd,
Vector3  point 
)
static

Returns the closest point on the line.

The line is treated as infinite.

See Also
NearestPointStrict
static float NearestPointFactor ( Vector3  lineStart,
Vector3  lineEnd,
Vector3  point 
)
static
static float NearestPointFactor ( Int3  lineStart,
Int3  lineEnd,
Int3  point 
)
static

Factor of the nearest point on the segment.

Returned value is in the range [0,1] if the point lies on the segment otherwise it just lies on the line. The closest point can be got by (end-start)*factor + start;

static float NearestPointFactor ( Int2  lineStart,
Int2  lineEnd,
Int2  point 
)
static

Factor of the nearest point on the segment.

Returned value is in the range [0,1] if the point lies on the segment otherwise it just lies on the line. The closest point can be got by (end-start)*factor + start;

static Vector3 NearestPointStrict ( Vector3  lineStart,
Vector3  lineEnd,
Vector3  point 
)
static

Returns the closest point on the line segment.

The line is NOT treated as infinite.

See Also
NearestPoint
static Vector3 NearestPointStrictXZ ( Vector3  lineStart,
Vector3  lineEnd,
Vector3  point 
)
static

Returns the closest point on the line segment on the XZ plane.

The line is NOT treated as infinite.

See Also
NearestPoint
static int Repeat ( int  i,
int  n 
)
static
Deprecated:
Obsolete
static int RoundToInt ( float  v)
static
Deprecated:
Use Mathf.RoundToInt instead
static int RoundToInt ( double  v)
static
Deprecated:
Use Mathf.RoundToInt instead
static float Sign ( float  a)
static
Deprecated:
Use Mathf.Sign instead
static int Sign ( int  a)
static
Deprecated:
Use Mathf.Sign instead
static float SqrMagnitudeXZ ( Vector3  a,
Vector3  b 
)
static

Squared distance between two points on the XZ plane.


The documentation for this class was generated from the following file: