Class Math
A collection of math functions that are useful when working with 3d meshes.
Inherited Members
Namespace: UnityEngine.Polybrush
Assembly: Unity.Polybrush.dll
Syntax
public static class Math
Fields
phi
Pi / 2.
Declaration
public const float phi = 1.618034
Field Value
| Type | Description |
|---|---|
| float |
Methods
Average(IList<Vector2>, IList<int>)
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<int> | 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<int>)
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<int> | 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<int>)
Average a set of Vector4.
Declaration
public static Vector4 Average(IList<Vector4> v, IList<int> indexes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IList<Vector4> | v | The collection from which to select indices. |
| IList<int> | indexes | The indexes to use to compute the average value |
Returns
| Type | Description |
|---|---|
| Vector4 | Average Vector4 from selected values |
Clamp(int, int, int)
Clamp a int to a 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 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 |
|---|---|
| float | 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 |
|---|---|
| float | 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 | The nearest point between the given rays. |
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 | The normalized (unit length) normal vector of the triangle's surface. |
RayIntersectsTriangle(Ray, Vector3, Vector3, Vector3, out float, 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 | The given ray. |
| 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 | 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 |
|---|---|
| bool | 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 original point. |
| Vector2 | origin | The pivot to scale from. |
| Vector2 | scale | Vector2 representing the scale factor for the X and Y axes. |
Returns
| Type | Description |
|---|---|
| Vector2 | A Vector2 position that has been scaled around the origin point. |
Secant(float)
Return the secant of a radian.
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 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 |
|---|---|
| float | The squared distance. |
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 |
|---|---|
| float | The area of the triangle. |