A* Pathfinding Project  3.7.3
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, lines and vectors. More...

Detailed Description

Utility functions for working with numbers, lines and vectors.

See Also
Polygon

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)
 Returns a hash value for a integer vector.
 
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)
 Returns the distance between x,z and the line p-q.
 
static float DistancePointSegment2 (Vector3 a, Vector3 b, Vector3 p)
 Returns the distance between c and the line a-b.
 
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)
 Returns a nicely formatted string for the number of bytes (kB, MB, GB etc).
 
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)
 Returns a point on a hermite curve.
 
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)
 Distance between two points on the XZ plane.
 
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)
 Maps a value (0...1) to be between targetMin and targetMax.
 
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
static int Abs ( int  a)
static
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
static int Clamp ( int  a,
int  b,
int  c 
)
static
static float Clamp01 ( float  a)
static
static int Clamp01 ( int  a)
static
static int ComputeVertexHash ( int  x,
int  y,
int  z 
)
static

Returns a hash value for a integer vector.

Author
Code got from the internet
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

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

The line is considered infinite.

static float DistancePointSegment2 ( Vector3  a,
Vector3  b,
Vector3  p 
)
static

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

The line is considered infinite.

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

Returns a nicely formatted string for the number of bytes (kB, MB, GB etc).

Uses decimal values, not binary ones

See Also
FormatBytesBinary
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

Returns a point on a hermite curve.

Slow start and slow end, fast in the middle

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 good
Seems like there are only 64 possible colors from studying the code

static float Lerp ( float  a,
float  b,
float  t 
)
static
static float MagnitudeXZ ( Vector3  a,
Vector3  b 
)
static

Distance between two points on the XZ plane.

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

Maps a value (0...1) to be between targetMin and targetMax.

static float Max ( float  a,
float  b 
)
static
static int Max ( int  a,
int  b 
)
static
static uint Max ( uint  a,
uint  b 
)
static
static ushort Max ( ushort  a,
ushort  b 
)
static
static float Min ( float  a,
float  b 
)
static
static int Min ( int  a,
int  b 
)
static
static uint Min ( uint  a,
uint  b 
)
static
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
static int RoundToInt ( float  v)
static
static int RoundToInt ( double  v)
static
static float Sign ( float  a)
static
static int Sign ( int  a)
static
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: