Class Math
A collection of math functions that are useful when working with 3d meshes.
Namespace: UnityEngine.ProBuilder
Syntax
public static class Math
Fields
phi
Declaration
public const float phi = 1.618034F
Field Value
Type | Description |
---|---|
Single | Pi / 2. |
Methods
Average(IList<Vector2>, IList<Int32>)
Gets the average of a vector array.
Declaration
public static Vector2 Average(IList<Vector2> array, IList<int> indexes = null)
Parameters
Type | Name | Description |
---|---|---|
IList<Vector2> | array | The array |
IList<Int32> | indexes | If provided the average is the sum of all points contained in the indexes array. If not, the entire v array is used. |
Returns
Type | Description |
---|---|
Vector2 | Average Vector3 of passed vertex array. |
Average(IList<Vector3>, IList<Int32>)
Gets the average of a vector array.
Declaration
public static Vector3 Average(IList<Vector3> array, IList<int> indexes = null)
Parameters
Type | Name | Description |
---|---|---|
IList<Vector3> | array | The array. |
IList<Int32> | indexes | If provided the average is the sum of all points contained in the indexes array. If not, the entire v array is used. |
Returns
Type | Description |
---|---|
Vector3 | Average Vector3 of passed vertex array. |
Average(IList<Vector4>, IList<Int32>)
Declaration
public static Vector4 Average(IList<Vector4> v, IList<int> indexes = null)
Parameters
Type | Name | Description |
---|---|---|
IList<Vector4> | v | |
IList<Int32> | indexes |
Returns
Type | Description |
---|---|
Vector4 |
Clamp(Int32, Int32, Int32)
Clamp a int to a range.
Declaration
public static int Clamp(int value, int lowerBound, int upperBound)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The value to clamp. |
Int32 | lowerBound | The lowest value that the clamped value can be. |
Int32 | upperBound | The highest value that the clamped value can be. |
Returns
Type | Description |
---|---|
Int32 | A value clamped with the range of lowerBound and upperBound. |
DistancePointLineSegment(Vector2, Vector2, Vector2)
Get the distance between a point and a finite line segment.
Declaration
public static float DistancePointLineSegment(Vector2 point, Vector2 lineStart, Vector2 lineEnd)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | point | The point. |
Vector2 | lineStart | Line start. |
Vector2 | lineEnd | Line end. |
Returns
Type | Description |
---|---|
Single | The distance from point to the nearest point on a line segment. |
Remarks
DistancePointLineSegment(Vector3, Vector3, Vector3)
Get the distance between a point and a finite line segment.
Declaration
public static float DistancePointLineSegment(Vector3 point, Vector3 lineStart, Vector3 lineEnd)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | point | The point. |
Vector3 | lineStart | Line start. |
Vector3 | lineEnd | Line end. |
Returns
Type | Description |
---|---|
Single | The distance from point to the nearest point on a line segment. |
Remarks
GetNearestPointRayRay(Ray, Ray)
Calculate the nearest point between two rays.
Declaration
public static Vector3 GetNearestPointRayRay(Ray a, Ray b)
Parameters
Type | Name | Description |
---|---|---|
Ray | a | First ray. |
Ray | b | Second ray. |
Returns
Type | Description |
---|---|
Vector3 |
Normal(ProBuilderMesh, Face)
Finds the best normal for a face.
Declaration
public static Vector3 Normal(ProBuilderMesh mesh, Face face)
Parameters
Type | Name | Description |
---|---|---|
ProBuilderMesh | mesh | The mesh that the target face belongs to. |
Face | face | The face to calculate a normal for. |
Returns
Type | Description |
---|---|
Vector3 | A normal that most closely matches the face orientation in model corrdinates. |
Normal(Vector3, Vector3, Vector3)
Calculate the unit vector normal of 3 points.
Equivalent to: B-A x C-A
Declaration
public static Vector3 Normal(Vector3 p0, Vector3 p1, Vector3 p2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | p0 | First point of the triangle. |
Vector3 | p1 | Second point of the triangle. |
Vector3 | p2 | Third point of the triangle. |
Returns
Type | Description |
---|---|
Vector3 |
NormalTangentBitangent(ProBuilderMesh, Face)
Returns the first normal, tangent, and bitangent for this face using the first triangle available for tangent and bitangent.
Declaration
public static Normal NormalTangentBitangent(ProBuilderMesh mesh, Face face)
Parameters
Type | Name | Description |
---|---|---|
ProBuilderMesh | mesh | The mesh that the target face belongs to. |
Face | face | The face to calculate normal information for. |
Returns
Type | Description |
---|---|
Normal | The normal, bitangent, and tangent for the face. |
RayIntersectsTriangle(Ray, Vector3, Vector3, Vector3, out Single, out Vector3)
Test if a raycast intersects a triangle. Does not test for culling.
Declaration
public static bool RayIntersectsTriangle(Ray InRay, Vector3 InTriangleA, Vector3 InTriangleB, Vector3 InTriangleC, out float OutDistance, out Vector3 OutPoint)
Parameters
Type | Name | Description |
---|---|---|
Ray | InRay | |
Vector3 | InTriangleA | First vertex position in the triangle. |
Vector3 | InTriangleB | Second vertex position in the triangle. |
Vector3 | InTriangleC | Third vertex position in the triangle. |
Single | OutDistance | If triangle is intersected, this is the distance of intersection point from ray origin. Zero if not intersected. |
Vector3 | OutPoint | If triangle is intersected, this is the point of collision. Zero if not intersected. |
Returns
Type | Description |
---|---|
Boolean | True if ray intersects, false if not. |
Remarks
http://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
ReflectPoint(Vector2, Vector2, Vector2)
Reflects a point across a line segment.
Declaration
public static Vector2 ReflectPoint(Vector2 point, Vector2 lineStart, Vector2 lineEnd)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | point | The point to reflect. |
Vector2 | lineStart | First point of the line segment. |
Vector2 | lineEnd | Second point of the line segment. |
Returns
Type | Description |
---|---|
Vector2 | The reflected point. |
ScaleAroundPoint(Vector2, Vector2, Vector2)
Scales a Vector2 using origin as the pivot point.
Declaration
public static Vector2 ScaleAroundPoint(this Vector2 v, Vector2 origin, Vector2 scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | v | |
Vector2 | origin | |
Vector2 | scale |
Returns
Type | Description |
---|---|
Vector2 |
Secant(Single)
Return the secant of a radian.
Equivalent to: 1f / cos(x)
.
Declaration
public static float Secant(float x)
Parameters
Type | Name | Description |
---|---|---|
Single | x | The radian to calculate the secant of. |
Returns
Type | Description |
---|---|
Single | The secant of radian x. |
SqrDistance(Vector3, Vector3)
Squared distance between two points. This is the same as (b - a).sqrMagnitude
.
Declaration
public static float SqrDistance(Vector3 a, Vector3 b)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First point. |
Vector3 | b | Second point. |
Returns
Type | Description |
---|---|
Single |
TriangleArea(Vector3, Vector3, Vector3)
Get the area of a triangle.
Declaration
public static float TriangleArea(Vector3 x, Vector3 y, Vector3 z)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | x | First vertex position of the triangle. |
Vector3 | y | Second vertex position of the triangle. |
Vector3 | z | Third vertex position of the triangle. |
Returns
Type | Description |
---|---|
Single | The area of the triangle. |