A* Pathfinding Project
4.0.9
The A* Pathfinding Project for Unity 3D
|
Various vector math utility functions. More...
Various vector math utility functions.
Note the difference between segments and lines. Lines are infinitely long but segments have only a finite length.
Static Public Member Functions | |
static Vector3 | ClampMagnitudeXZ (Vector3 v, float maxMagnitude) |
static Vector3 | ClosestPointOnLine (Vector3 lineStart, Vector3 lineEnd, Vector3 point) |
Returns the closest point on the line. | |
static float | ClosestPointOnLineFactor (Vector3 lineStart, Vector3 lineEnd, Vector3 point) |
Factor along the line which is closest to the point. | |
static float | ClosestPointOnLineFactor (Int3 lineStart, Int3 lineEnd, Int3 point) |
Factor along the line which is closest to the point. | |
static float | ClosestPointOnLineFactor (Int2 lineStart, Int2 lineEnd, Int2 point) |
Factor of the nearest point on the segment. | |
static Vector3 | ClosestPointOnSegment (Vector3 lineStart, Vector3 lineEnd, Vector3 point) |
Returns the closest point on the segment. | |
static Vector3 | ClosestPointOnSegmentXZ (Vector3 lineStart, Vector3 lineEnd, Vector3 point) |
Returns the closest point on the segment in the XZ plane. | |
static bool | IsClockwiseMarginXZ (Vector3 a, Vector3 b, Vector3 c) |
Returns if the points a in a clockwise order. | |
static bool | IsClockwiseOrColinear (Int2 a, Int2 b, Int2 c) |
Returns true if the points a in a clockwise order or if they are colinear. | |
static bool | IsClockwiseOrColinearXZ (Int3 a, Int3 b, Int3 c) |
Returns true if the points a in a clockwise order or if they are colinear. | |
static bool | IsClockwiseXZ (Vector3 a, Vector3 b, Vector3 c) |
Returns if the points a in a clockwise order. | |
static bool | IsClockwiseXZ (Int3 a, Int3 b, Int3 c) |
Returns if the points a in a clockwise order. | |
static bool | IsColinear (Vector2 a, Vector2 b, Vector2 c) |
Returns if the points are colinear (lie on a straight line) | |
static bool | IsColinearAlmostXZ (Int3 a, Int3 b, Int3 c) |
Returns if the points are colinear (lie on a straight line) | |
static bool | IsColinearXZ (Int3 a, Int3 b, Int3 c) |
Returns if the points are colinear (lie on a straight line) | |
static bool | IsColinearXZ (Vector3 a, Vector3 b, Vector3 c) |
Returns if the points are colinear (lie on a straight line) | |
static float | LineCircleIntersectionFactor (Vector3 circleCenter, Vector3 linePoint1, Vector3 linePoint2, float radius) |
Intersection of a line and a circle. | |
static Vector3 | LineDirIntersectionPointXZ (Vector3 start1, Vector3 dir1, Vector3 start2, Vector3 dir2) |
Intersection point between two infinite lines. | |
static Vector3 | LineDirIntersectionPointXZ (Vector3 start1, Vector3 dir1, Vector3 start2, Vector3 dir2, out bool intersects) |
Intersection point between two infinite lines. | |
static bool | LineIntersectionFactorXZ (Int3 start1, Int3 end1, Int3 start2, Int3 end2, out float factor1, out float factor2) |
Returns the intersection factors for line 1 and line 2. | |
static bool | LineIntersectionFactorXZ (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2, out float factor1, out float factor2) |
Returns the intersection factors for line 1 and line 2. | |
static float | LineIntersectionFactorXZ (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2) |
Returns the intersection factor for line 1 with line 2. | |
static Vector2 | LineIntersectionPoint (Vector2 start1, Vector2 end1, Vector2 start2, Vector2 end2) |
Returns the intersection point between the two lines. | |
static Vector2 | LineIntersectionPoint (Vector2 start1, Vector2 end1, Vector2 start2, Vector2 end2, out bool intersects) |
Returns the intersection point between the two lines. | |
static Vector3 | LineIntersectionPointXZ (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2) |
Returns the intersection point between the two lines. | |
static Vector3 | LineIntersectionPointXZ (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2, out bool intersects) |
Returns the intersection point between the two lines. | |
static float | LineRayIntersectionFactorXZ (Int3 start1, Int3 end1, Int3 start2, Int3 end2) |
Returns the intersection factor for line 1 with ray 2. | |
static float | MagnitudeXZ (Vector3 v) |
static Vector3 | Normalize (Vector3 v, out float magnitude) |
Normalize vector and also return the magnitude. | |
static Vector2 | Normalize (Vector2 v, out float magnitude) |
Normalize vector and also return the magnitude. | |
static bool | RaySegmentIntersectXZ (Int3 start1, Int3 end1, Int3 start2, Int3 end2) |
Returns if the ray (start1, end1) intersects the segment (start2, end2). | |
static bool | ReversesFaceOrientations (Matrix4x4 matrix) |
True if the matrix will reverse orientations of faces. | |
static bool | ReversesFaceOrientationsXZ (Matrix4x4 matrix) |
True if the matrix will reverse orientations of faces in the XZ plane. | |
static bool | RightOrColinear (Vector2 a, Vector2 b, Vector2 p) |
Returns if p lies on the right side of the line a - b. | |
static bool | RightOrColinear (Int2 a, Int2 b, Int2 p) |
Returns if p lies on the right side of the line a - b. | |
static bool | RightOrColinearXZ (Vector3 a, Vector3 b, Vector3 p) |
Returns if p lies on the left side of the line a - b. | |
static bool | RightOrColinearXZ (Int3 a, Int3 b, Int3 p) |
Returns if p lies on the left side of the line a - b. | |
static bool | RightXZ (Vector3 a, Vector3 b, Vector3 p) |
Returns if p lies on the right side of the line a - b. | |
static bool | RightXZ (Int3 a, Int3 b, Int3 p) |
Returns if p lies on the right side of the line a - b. | |
static Vector3 | SegmentIntersectionPointXZ (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2, out bool intersects) |
Returns the intersection point between the two line segments in XZ space. | |
static bool | SegmentIntersectsBounds (Bounds bounds, Vector3 a, Vector3 b) |
Does the line segment intersect the bounding box. | |
static bool | SegmentsIntersect (Int2 start1, Int2 end1, Int2 start2, Int2 end2) |
Returns if the line segment start2 - end2 intersects the line segment start1 - end1. | |
static bool | SegmentsIntersectXZ (Int3 start1, Int3 end1, Int3 start2, Int3 end2) |
Returns if the line segment start2 - end2 intersects the line segment start1 - end1. | |
static bool | SegmentsIntersectXZ (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2) |
Returns if the two line segments intersects. | |
static long | SignedTriangleAreaTimes2XZ (Int3 a, Int3 b, Int3 c) |
Signed area of a triangle in the XZ plane multiplied by 2. | |
static float | SignedTriangleAreaTimes2XZ (Vector3 a, Vector3 b, Vector3 c) |
Signed area of a triangle in the XZ plane multiplied by 2. | |
static float | SqrDistancePointSegment (Vector3 a, Vector3 b, Vector3 p) |
Returns the squared distance between p and the segment a-b. | |
static float | SqrDistancePointSegmentApproximate (int x, int z, int px, int pz, int qx, int qz) |
Returns the approximate shortest squared distance between x,z and the segment p-q. | |
static float | SqrDistancePointSegmentApproximate (Int3 a, Int3 b, Int3 p) |
Returns the approximate shortest squared distance between x,z and the segment p-q. | |
static float | SqrDistanceSegmentSegment (Vector3 s1, Vector3 e1, Vector3 s2, Vector3 e2) |
3D minimum distance between 2 segments. | |
static float | SqrDistanceXZ (Vector3 a, Vector3 b) |
Squared distance between two points in the XZ plane. | |
|
static |
|
static |
Returns the closest point on the line.
The line is treated as infinite.
|
static |
Factor along the line which is closest to the point.
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 calculated using (end-start)*factor + start.
Factor along the line which is closest to the point.
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 calculated using (end-start)*factor + start
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 calculated using (end-start)*factor + start;
|
static |
Returns the closest point on the segment.
The segment is NOT treated as infinite.
|
static |
Returns the closest point on the segment in the XZ plane.
The y coordinate of the result will be the same as the y coordinate of the point parameter.
The segment is NOT treated as infinite.
|
static |
Returns if the points a in a clockwise order.
Will return true even if the points are colinear or very slightly counter-clockwise (if the signed area of the triangle formed by the points has an area less than or equals to float.Epsilon)
Returns true if the points a in a clockwise order or if they are colinear.
Returns true if the points a in a clockwise order or if they are colinear.
|
static |
Returns if the points a in a clockwise order.
Returns if the points a in a clockwise order.
|
static |
Returns if the points are colinear (lie on a straight line)
Returns if the points are colinear (lie on a straight line)
Returns if the points are colinear (lie on a straight line)
|
static |
Returns if the points are colinear (lie on a straight line)
|
static |
Intersection of a line and a circle.
Returns the greatest t such that segmentStart+t*(segmentEnd-segmentStart) lies on the circle.
In case the line does not intersect with the circle, the closest point on the line to the circle will be returned.
|
static |
Intersection point between two infinite lines.
Note that start points and directions are taken as parameters instead of start and end points. Lines are treated as infinite. If the lines are parallel 'start1' will be returned. Intersections are calculated on the XZ plane.
|
static |
Intersection point between two infinite lines.
Note that start points and directions are taken as parameters instead of start and end points. Lines are treated as infinite. If the lines are parallel 'start1' will be returned. Intersections are calculated on the XZ plane.
|
static |
Returns the intersection factors for line 1 and line 2.
The intersection factors is a distance along the line start - end where the other line intersects it.
Lines are treated as infinite.
false is returned if the lines are parallel and true if they are not. Only the XZ coordinates are used.
|
static |
Returns the intersection factors for line 1 and line 2.
The intersection factors is a distance along the line start - end where the other line intersects it.
Lines are treated as infinite.
false is returned if the lines are parallel and true if they are not. Only the XZ coordinates are used.
|
static |
Returns the intersection factor for line 1 with line 2.
The intersection factor is a distance along the line start1 - end1 where the line start2 - end2 intersects it.
. Lines are treated as infinite.
-1 is returned if the lines are parallel (note that this is a valid return value if they are not parallel too)
|
static |
Returns the intersection point between the two lines.
Lines are treated as infinite. start1 is returned if the lines are parallel
|
static |
Returns the intersection point between the two lines.
Lines are treated as infinite. start1 is returned if the lines are parallel
|
static |
Returns the intersection point between the two lines.
Lines are treated as infinite. start1 is returned if the lines are parallel
|
static |
Returns the intersection point between the two lines.
Lines are treated as infinite. start1 is returned if the lines are parallel
Returns the intersection factor for line 1 with ray 2.
The intersection factors is a factor distance along the line start - end where the other line intersects it.
Lines are treated as infinite.
The second "line" is treated as a ray, meaning only matches on start2 or forwards towards end2 (and beyond) will be returned If the point lies on the wrong side of the ray start, Nan will be returned.
NaN is returned if the lines are parallel.
|
static |
|
static |
Normalize vector and also return the magnitude.
This is more efficient than calculating the magnitude and normalizing separately
|
static |
Normalize vector and also return the magnitude.
This is more efficient than calculating the magnitude and normalizing separately
Returns if the ray (start1, end1) intersects the segment (start2, end2).
false is returned if the lines are parallel. Only the XZ coordinates are used.
|
static |
True if the matrix will reverse orientations of faces.
Scaling by a negative value along an odd number of axes will reverse the orientation of e.g faces on a mesh. This must be counter adjusted by for example the recast rasterization system to be able to handle meshes with negative scales properly.
We can find out if they are flipped by finding out how the signed volume of a unit cube is transformed when applying the matrix
If the (signed) volume turns out to be negative that also means that the orientation of it has been reversed.
|
static |
True if the matrix will reverse orientations of faces in the XZ plane.
Almost the same as ReversesFaceOrientations, but this method assumes that scaling a face with a negative scale along the Y axis does not reverse the orientation of the face.
This is used for navmesh cuts.
Scaling by a negative value along one axis or rotating it so that it is upside down will reverse the orientation of the cut, so we need to be reverse it again as a countermeasure. However if it is flipped along two axes it does not need to be reversed. We can handle all these cases by finding out how a unit square formed by our forward axis and our rightward axis is transformed in XZ space when applying the local to world matrix. If the (signed) area of the unit square turns out to be negative that also means that the orientation of it has been reversed. The signed area is calculated using a cross product of the vectors.
|
static |
Returns if p lies on the right side of the line a - b.
Also returns true if the points are colinear.
Returns if p lies on the right side of the line a - b.
Also returns true if the points are colinear.
|
static |
Returns if p lies on the left side of the line a - b.
Uses XZ space. Also returns true if the points are colinear.
Returns if p lies on the left side of the line a - b.
Uses XZ space. Also returns true if the points are colinear.
|
static |
Returns if p lies on the right side of the line a - b.
Uses XZ space. Does not return true if the points are colinear.
Returns if p lies on the right side of the line a - b.
Uses XZ space. Does not return true if the points are colinear.
|
static |
Returns the intersection point between the two line segments in XZ space.
Lines are NOT treated as infinite. start1 is returned if the line segments do not intersect The point will be returned along the line [start1, end1] (this matters only for the y coordinate).
|
static |
Does the line segment intersect the bounding box.
The line is NOT treated as infinite.
Returns if the line segment start2 - end2 intersects the line segment start1 - end1.
If only the endpoints coincide, the result is undefined (may be true or false).
Returns if the line segment start2 - end2 intersects the line segment start1 - end1.
If only the endpoints coincide, the result is undefined (may be true or false).
|
static |
Returns if the two line segments intersects.
The lines are NOT treated as infinite (just for clarification)
Signed area of a triangle in the XZ plane multiplied by 2.
This will be negative for clockwise triangles and positive for counter-clockwise ones
|
static |
Signed area of a triangle in the XZ plane multiplied by 2.
This will be negative for clockwise triangles and positive for counter-clockwise ones.
|
static |
Returns the squared distance between p and the segment a-b.
The line is not considered infinite.
|
static |
Returns the approximate shortest squared distance between x,z and the segment p-q.
The segment is not considered infinite. This function is not entirely exact, but it is about twice as fast as DistancePointSegment2.
Returns the approximate shortest squared distance between x,z and the segment p-q.
The segment is not considered infinite. This function is not entirely exact, but it is about twice as fast as DistancePointSegment2.
|
static |
3D minimum distance between 2 segments.
Input: two 3D line segments S1 and S2
|
static |
Squared distance between two points in the XZ plane.