Class Math
Defines a set of math functions that are useful for working with 3D meshes.
Inherited Members
Namespace: UnityEngine.ProBuilder
Assembly: Unity.ProBuilder.dll
Syntax
public static class Math
Fields
phi
Defines Pi / 2
.
Declaration
public const float phi = 1.618034
Field Value
Type | Description |
---|---|
float |
Methods
Average(IList<Vector2>, IList<int>)
Calculates and returns the average of a Vector2 array.
Declaration
public static Vector2 Average(IList<Vector2> array, IList<int> indexes = null)
Parameters
Type | Name | Description |
---|---|---|
IList<Vector2> | array | The array to get the average for. |
IList<int> | indexes | Specify a list of points in the vector array to calculate the average from.
If not specified, it uses the entire |
Returns
Type | Description |
---|---|
Vector2 | Average of the whole vertex array or the portion specified in the |
Average(IList<Vector3>, IList<int>)
Calculates and returns the average of the specified Vector3 array.
Declaration
public static Vector3 Average(IList<Vector3> array, IList<int> indexes = null)
Parameters
Type | Name | Description |
---|---|---|
IList<Vector3> | array | The array to get the average for. |
IList<int> | indexes | Specify a list of points in the vector array to calculate the average from.
If not specified, it uses the entire |
Returns
Type | Description |
---|---|
Vector3 | Average of the whole vertex array or the portion specified in the |
Average(IList<Vector4>, IList<int>)
Calculates and returns the average of a Vector4 array.
Declaration
public static Vector4 Average(IList<Vector4> array, IList<int> indexes = null)
Parameters
Type | Name | Description |
---|---|---|
IList<Vector4> | array | The array to get the average for. |
IList<int> | indexes | Specify a list of points in the vector array to calculate the average from.
If not specified, it uses the entire |
Returns
Type | Description |
---|---|
Vector4 | Average of the whole vertex array or the portion specified in the |
Clamp(int, int, int)
Clamps an integer value to the specified range.
Declaration
public static int Clamp(int value, int lowerBound, int upperBound)
Parameters
Type | Name | Description |
---|---|---|
int | value | The value to clamp. |
int | lowerBound | The lowest value that the clamped value can be. |
int | upperBound | The highest value that the clamped value can be. |
Returns
Type | Description |
---|---|
int | A value clamped inside the range of |
DistancePointLineSegment(Vector2, Vector2, Vector2)
Returns the distance between a point and a finite line segment using Vector2s.
Declaration
public static float DistancePointLineSegment(Vector2 point, Vector2 lineStart, Vector2 lineEnd)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | point | The point. |
Vector2 | lineStart | Where the line starts. |
Vector2 | lineEnd | Where the line ends. |
Returns
Type | Description |
---|---|
float | The distance from the point to the nearest point on a line segment. |
Remarks
DistancePointLineSegment(Vector3, Vector3, Vector3)
Returns the distance between a point and a finite line segment using Vector3s.
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 |
---|---|
float | The distance from point to the nearest point on a line segment. |
Remarks
GetNearestPointRayRay(Ray, Ray)
Calculates and returns 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 | The nearest point between the two rays |
Normal(ProBuilderMesh, Face)
Finds and returns 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 coordinates. |
Normal(Vector3, Vector3, Vector3)
Calculates and returns the unit vector normal of 3 points in a triangle.
This is 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 | The unit vector normal of the points |
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 float, out Vector3)
Tests whether 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 | The ray to test. |
Vector3 | InTriangleA | First vertex position in the triangle. |
Vector3 | InTriangleB | Second vertex position in the triangle. |
Vector3 | InTriangleC | Third vertex position in the triangle. |
float | OutDistance | The distance of the intersection point from the ray origin if the ray intersects the triangle; otherwise, 0. |
Vector3 | OutPoint | The point of collision if the ray intersects the triangle; otherwise, 0. |
Returns
Type | Description |
---|---|
bool | True if the ray intersects the triangle; otherwise false. |
Remarks
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 the origin as the pivot point.
Declaration
public static Vector2 ScaleAroundPoint(this Vector2 v, Vector2 origin, Vector2 scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | v | The Vector2 to scale. |
Vector2 | origin | The center point to use as the pivot point. |
Vector2 | scale | Unit(s) to scale by. |
Returns
Type | Description |
---|---|
Vector2 | The scaled Vector2 |
Secant(float)
Returns the secant of a radian. This is equivalent to: 1f / cos(x)
.
Declaration
public static float Secant(float x)
Parameters
Type | Name | Description |
---|---|---|
float | x | The radian to calculate the secant of. |
Returns
Type | Description |
---|---|
float | The secant of radian |
SqrDistance(Vector3, Vector3)
Returns the 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 |
---|---|
float | The squared distance between two points. |
TriangleArea(Vector3, Vector3, Vector3)
Returns 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 |
---|---|
float | The area of the triangle. |