A* Pathfinding Project  3.1.4
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Enumerations Properties Groups Pages
Polygon Class Reference

Utility functions for working with polygons, lines, and other vector math. More...

Static Public Member Functions

static Vector3 ClosestPointOnTriangle (Vector3[] triangle, Vector3 point)
 Returns the closest point on the triangle.
 
static Vector3 ClosestPointOnTriangle (Vector3 tr0, Vector3 tr1, Vector3 tr2, Vector3 point)
 Returns the closest point on the triangle.
 
static bool ContainsPoint (Vector3 a, Vector3 b, Vector3 c, Vector3 p)
 Returns if the triangle ABC contains the point p in XZ space.
 
static bool ContainsPoint (Vector2[] polyPoints, Vector2 p)
 Checks if p is inside the polygon.
 
static bool ContainsPoint (Vector3[] polyPoints, Vector3 p)
 Checks if p is inside the polygon (XZ space)
 
static Vector3[] ConvexHull (Vector3[] points)
 Calculates convex hull in XZ space for the points.
 
static float Dot (Vector3 lhs, Vector3 rhs)
 Dot product of two vectors.
 
static bool IntersectionFactor (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 IntersectionFactor (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2)
 Returns the intersection factor for line 1 with line 2.
 
static Vector3 IntersectionPoint (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2)
 Returns the intersection point between the two lines.
 
static Vector3 IntersectionPoint (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2, out bool intersects)
 Returns the intersection point between the two lines.
 
static Vector3 IntersectionPointOptimized (Vector3 start1, Vector3 dir1, Vector3 start2, Vector3 dir2)
 Intersection point between two infinite lines.
 
static Vector3 IntersectionPointOptimized (Vector3 start1, Vector3 dir1, Vector3 start2, Vector3 dir2, out bool intersects)
 Intersection point between two infinite lines.
 
static bool Intersects (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2)
 Returns if the two line segments intersects.
 
static bool IntersectsUnclamped (Vector3 a, Vector3 b, Vector3 a2, Vector3 b2)
 Returns if the line segment a2 - b2 intersects the infinite line a - b.
 
static bool IsClockwise (Vector3 a, Vector3 b, Vector3 c)
 Returns if the points a in a clockwise order.
 
static bool IsClockwise (Int3 a, Int3 b, Int3 c)
 Returns if the points a in a clockwise order.
 
static bool IsClockwiseMargin (Vector3 a, Vector3 b, Vector3 c)
 Returns if the points a in a clockwise order.
 
static bool IsColinear (Int3 a, Int3 b, Int3 c)
 Returns if the points are colinear (lie on a straight line)
 
static bool IsColinear (Vector3 a, Vector3 b, Vector3 c)
 Returns if the points are colinear (lie on a straight line)
 
static bool Left (Vector3 a, Vector3 b, Vector3 p)
 Returns if p lies on the left side of the line a - b.
 
static bool Left (Int3 a, Int3 b, Int3 c)
 Returns if p lies on the left side of the line a - b.
 
static bool LineIntersectsBounds (Bounds bounds, Vector3 a, Vector3 b)
 Does the line segment intersect the bounding box.
 
static Vector3 SegmentIntersectionPoint (Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2, out bool intersects)
 Returns the intersection point between the two line segments.
 
static Vector3[] Subdivide (Vector3[] path, int subdivisions)
 Subdivides path and returns the new array with interpolated values.
 
static long TriangleArea (Int3 a, Int3 b, Int3 c)
 
static float TriangleArea (Vector3 a, Vector3 b, Vector3 c)
 
static long TriangleArea2 (Int3 a, Int3 b, Int3 c)
 Area of a triangle This will be negative for clockwise triangles and positive for counter-clockwise ones.
 
static float TriangleArea2 (Vector3 a, Vector3 b, Vector3 c)
 

Static Public Attributes

static List< Vector3 > hullCache = new List<Vector3>()
 

Detailed Description

Utility functions for working with polygons, lines, and other vector math.

All functions which accepts Vector3s but work in 2D space uses the XZ space if nothing else is said.

Member Function Documentation

static Vector3 ClosestPointOnTriangle ( Vector3[]  triangle,
Vector3  point 
)
static

Returns the closest point on the triangle.

The triangle array must have a length of at least 3.

See Also
ClosesPointOnTriangle(Vector3,Vector3,Vector3,Vector3);

+ Here is the caller graph for this function:

static Vector3 ClosestPointOnTriangle ( Vector3  tr0,
Vector3  tr1,
Vector3  tr2,
Vector3  point 
)
static

Returns the closest point on the triangle.

Note
Got code from the internet, changed a bit to work with the Unity API
Todo:
Uses Dot product to get the sqrMagnitude of a vector, should change to sqrMagnitude for readability and possibly for speed (unlikely though)
static bool ContainsPoint ( Vector2[]  polyPoints,
Vector2  p 
)
static

Checks if p is inside the polygon.

Author
http://unifycommunity.com/wiki/index.php?title=PolyContainsPoint (Eric5h5)
static bool ContainsPoint ( Vector3[]  polyPoints,
Vector3  p 
)
static

Checks if p is inside the polygon (XZ space)

Author
http://unifycommunity.com/wiki/index.php?title=PolyContainsPoint (Eric5h5)
static Vector3 [] ConvexHull ( Vector3[]  points)
static

Calculates convex hull in XZ space for the points.

Implemented using the very simple Gift Wrapping Algorithm which has a complexity of O(nh) where n is the number of points and h is the number of points on the hull, so it is in the worst case quadratic.

+ Here is the call graph for this function:

static float Dot ( Vector3  lhs,
Vector3  rhs 
)
static

Dot product of two vectors.

Todo:
Why is this function defined here?
static bool IntersectionFactor ( Vector3  start1,
Vector3  end1,
Vector3  start2,
Vector3  end2,
out float  factor1,
out float  factor2 
)
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.

intersectionPoint = start1 + factor1 * (end1-start1)
intersectionPoint2 = start2 + factor2 * (end2-start2)

Lines are treated as infinite.
false is returned if the lines are parallel and true if they are not

+ Here is the caller graph for this function:

static float IntersectionFactor ( Vector3  start1,
Vector3  end1,
Vector3  start2,
Vector3  end2 
)
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.

intersectionPoint = start1 + intersectionFactor * (end1-start1)

. 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 Vector3 IntersectionPoint ( Vector3  start1,
Vector3  end1,
Vector3  start2,
Vector3  end2 
)
static

Returns the intersection point between the two lines.

Lines are treated as infinite. start1 is returned if the lines are parallel

static Vector3 IntersectionPoint ( Vector3  start1,
Vector3  end1,
Vector3  start2,
Vector3  end2,
out bool  intersects 
)
static

Returns the intersection point between the two lines.

Lines are treated as infinite. start1 is returned if the lines are parallel

static Vector3 IntersectionPointOptimized ( Vector3  start1,
Vector3  dir1,
Vector3  start2,
Vector3  dir2 
)
static

Intersection point between two infinite lines.

Lines are treated as infinite. If the lines are parallel 'start1' will be returned. Intersections are calculated on the XZ plane.

static Vector3 IntersectionPointOptimized ( Vector3  start1,
Vector3  dir1,
Vector3  start2,
Vector3  dir2,
out bool  intersects 
)
static

Intersection point between two infinite lines.

Lines are treated as infinite. If the lines are parallel 'start1' will be returned. Intersections are calculated on the XZ plane.

static bool Intersects ( Vector3  start1,
Vector3  end1,
Vector3  start2,
Vector3  end2 
)
static

Returns if the two line segments intersects.

The lines are NOT treated as infinite (just for clarification)

See Also
IntersectionPoint
static bool IntersectsUnclamped ( Vector3  a,
Vector3  b,
Vector3  a2,
Vector3  b2 
)
static

Returns if the line segment a2 - b2 intersects the infinite line a - b.

a-b is infinite, a2-b2 is not infinite

+ Here is the call graph for this function:

static bool IsClockwiseMargin ( Vector3  a,
Vector3  b,
Vector3  c 
)
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)

+ Here is the caller graph for this function:

static bool Left ( Vector3  a,
Vector3  b,
Vector3  p 
)
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

+ Here is the caller graph for this function:

static bool Left ( Int3  a,
Int3  b,
Int3  c 
)
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

static bool LineIntersectsBounds ( Bounds  bounds,
Vector3  a,
Vector3  b 
)
static

Does the line segment intersect the bounding box.

The line is NOT treated as infinite.

Author
Slightly modified code from http://www.3dkingdoms.com/weekly/weekly.php?a=21

+ Here is the caller graph for this function:

static Vector3 SegmentIntersectionPoint ( Vector3  start1,
Vector3  end1,
Vector3  start2,
Vector3  end2,
out bool  intersects 
)
static

Returns the intersection point between the two line segments.

Lines are NOT treated as infinite. start1 is returned if the line segments do not intersect

+ Here is the caller graph for this function:

static Vector3 [] Subdivide ( Vector3[]  path,
int  subdivisions 
)
static

Subdivides path and returns the new array with interpolated values.

The returned array is path subdivided subdivisions times, the resulting points are interpolated using Mathf.SmoothStep.
If subdivisions is less or equal to 0 (zero), the original array will be returned


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