![]() |
Infohazard.Core 1.4.1
Infohazard Core Utility Library
|
Contains utility methods for working with mathematical types and solving math equations. More...
Static Public Member Functions | |
static float | RoundToNearest (float value, float factor) |
Round a value to the nearest multiple of a given factor. More... | |
static float | SignZero (float value) |
Same as Mathf.Sign, except that if the input is zero, it returns zero. More... | |
static float | NormalizeAngle (float angle) |
Normalize an angle to a value between 0 and 360. More... | |
static Vector3 | NormalizeAngles (Vector3 angles) |
Normalize a set of euler angles to values between 0 and 360. More... | |
static float | NormalizeInnerAngle (float angle) |
Normalize an angle to a value between -180 and 180. More... | |
static Vector3 | NormalizeInnerAngles (Vector3 angles) |
Normalize a set of euler angles to values between -180 and 180. More... | |
static float | ClampInnerAngle (float angle, float min, float max) |
Normalize an angle to a value between -180 and 180, then clamp it in the given range. More... | |
static Vector3 | ClampInnerAngles (Vector3 angles, Vector3 min, Vector3 max) |
Normalize a set of euler angles to values between -180 and 180, then clamp them in the given ranges. More... | |
static Vector3 | Multiply (Vector3 left, Vector3 right) |
Multiply the components of left by the components of right. More... | |
static Vector3 | Divide (Vector3 left, Vector3 right) |
Divide the components of left by the components of right. More... | |
static Vector3 | Reciprocal (Vector3 vector) |
Take the reciprocal of each component of a vector. More... | |
static Vector3 | Divide (float left, Vector3 right) |
Divide a float by each component of a vector. More... | |
static Vector3 | RoundToNearest (Vector3 vector, float factor) |
Round a each component of a vector to the nearest multiple of a given factor. More... | |
static bool | GetNearestPointOnLines (Ray line1, Ray line2, out float t1, out float t2) |
Find the point along each line where the lines come closest to each other. More... | |
static float | GetNearestPointOnLine (Ray line, Vector3 p) |
Get the point on a line where it is nearest to a position. More... | |
static bool | GetNearestPointOnSegment (Vector3 v1, Vector3 v2, Vector3 point, out Vector3 pointOnSegment) |
Find the point on a bounded line segment where it is nearest to a position, and return whether that point is in the segment's bounds. More... | |
static Vector3 | GetNearestPointOnTriangleIncludingBounds (Vector3 v1, Vector3 v2, Vector3 v3, Vector3 point) |
Find the point on a triangle (including its bounds) where it is nearest to a position. More... | |
static bool | GetNearestPointOnTriangle (Vector3 v1, Vector3 v2, Vector3 v3, Vector3 point, out Vector3 pointOnTriangle) |
Find the point on a triangle where it is nearest to a position, and return whether that point is in the triangle's bounds. More... | |
static bool | IsPointInsideBound (Vector3 v1, Vector3 v2, Vector3 normal, Vector3 point) |
Returns true if a given point is on the inner side (defined by a given normal) of a segment. More... | |
static bool | DoesSegmentIntersectTriangle (Vector3 v1, Vector3 v2, Vector3 v3, Vector3 s1, Vector3 s2, out float t) |
Raycast a line segment against a triangle, and return whether they intersect. More... | |
static Vector3 | WorldToCanvasPoint (this Camera camera, Canvas canvas, Vector3 point) |
Projects a point in the world onto a canvas in camera or overlay space. More... | |
static Vector3 | GetPerpendicularVector (this Vector3 vector) |
Returns a vector that is perpendicular to the given vector. More... | |
static int | Dot (Vector3Int v1, Vector3Int v2) |
Dot product of two int vectors. More... | |
static Vector3 | WithX (this Vector3 v, float x) |
Replace the X component of a vector. More... | |
static Vector3 | WithY (this Vector3 v, float y) |
Replace the Y component of a vector. More... | |
static Vector3 | WithZ (this Vector3 v, float z) |
Replace the Z component of a vector. More... | |
static Vector2 | WithX (this Vector2 v, float x) |
Replace the X component of a vector. More... | |
static Vector2 | WithY (this Vector2 v, float y) |
Replace the Y component of a vector. More... | |
static Vector3 | WithZ (this Vector2 v, float z) |
Convert a Vector2 to a Vector3 with the given Z. More... | |
static Vector3 | AsXY (this Vector2 v) |
Get a Vector3 with the components (x, y, 0). More... | |
static Vector3 | AsYX (this Vector2 v) |
Get a Vector3 with the components (y, x, 0). More... | |
static Vector3 | AsXZ (this Vector2 v) |
Get a Vector3 with the components (x, 0, y). More... | |
static Vector3 | AsZX (this Vector2 v) |
Get a Vector3 with the components (y, 0, x). More... | |
static Vector3 | AsYZ (this Vector2 v) |
Get a Vector3 with the components (0, x, y). More... | |
static Vector3 | AsZY (this Vector2 v) |
Get a Vector3 with the components (0, y, x). More... | |
static Vector2 | ToXY (this Vector3 v) |
Get a Vector2 with the components (x, y). More... | |
static Vector2 | ToYX (this Vector3 v) |
Get a Vector2 with the components (y, x). More... | |
static Vector2 | ToXZ (this Vector3 v) |
Get a Vector2 with the components (x, z). More... | |
static Vector2 | ToZX (this Vector3 v) |
Get a Vector2 with the components (z, x). More... | |
static Vector2 | ToYZ (this Vector3 v) |
Get a Vector2 with the components (y, z). More... | |
static Vector2 | ToZY (this Vector3 v) |
Get a Vector2 with the components (z, y). More... | |
static Vector4 | ToV4Pos (this Vector3 vector) |
Get a Vector4 with the components (x, y, z, 1). More... | |
static Vector4 | ToV4 (this Vector3 vector) |
Get a Vector4 with the components (x, y, z, 0). More... | |
static Quaternion | XYRotation (Vector3 right, Vector3 upHint) |
Get a quaternion based on a right vector and approximate up vector. More... | |
static Quaternion | YXRotation (Vector3 up, Vector3 rightHint) |
Get a quaternion based on a up vector and approximate right vector. More... | |
static Quaternion | XZRotation (Vector3 right, Vector3 forwardHint) |
Get a quaternion based on a right vector and approximate forward vector. More... | |
static Quaternion | ZXRotation (Vector3 forward, Vector3 rightHint) |
Get a quaternion based on a forward vector and approximate right vector. More... | |
static Quaternion | YZRotation (Vector3 up, Vector3 forwardHint) |
Get a quaternion based on a up vector and approximate forward vector. More... | |
static Quaternion | ZYRotation (Vector3 forward, Vector3 upHint) |
Get a quaternion based on a forward vector and approximate up vector. More... | |
static void | GetCorners (this Bounds bounds, Vector3[] corners) |
Get the eight corners of a bounding box and save them in the given array. More... | |
static bool | BoundsToScreenRect (Transform transform, Bounds bounds, Func< Vector3, Vector3 > worldToScreen, out Rect rect) |
Get a screen rect that encapsulates the given bounds. More... | |
static void | SplitHorizontal (Rect rect, float gap, out Rect out1, out Rect out2, float div=0.5f) |
Split a rect into two halves horizontally, with given gap between the halves. More... | |
static void | SplitHorizontal (Rect rect, float gap, out Rect out1, out Rect out2, out Rect out3, float div1=1.0f/3.0f, float div2=2.0f/3.0f) |
Split a rect into three thirds horizontally, with given gap between the thirds. More... | |
Static Public Attributes | |
static | Complex |
Evaluate all cubic roots of this Complex. More... | |
static Complex | r1 |
Solve a quadratic equation (find x such that the result is zero) in the form ax^2 + bx + c = 0. More... | |
static readonly Vector3[] | BoundsCornerArray = new Vector3[8] |
A static array that can be used to store the output of GetCorners, as long as the values are copied from the array right away. More... | |
Contains utility methods for working with mathematical types and solving math equations.
|
static |
Get a Vector3 with the components (x, y, 0).
|
static |
Get a Vector3 with the components (x, 0, y).
|
static |
Get a Vector3 with the components (y, x, 0).
|
static |
Get a Vector3 with the components (0, x, y).
|
static |
Get a Vector3 with the components (y, 0, x).
|
static |
Get a Vector3 with the components (0, y, x).
|
static |
Get a screen rect that encapsulates the given bounds.
transform | Parent that the bounds are attached to (can be null). |
bounds | The input bounds. |
worldToScreen | A function that converts world points to screen points, such as Camera.WorldToScreenPoint. |
rect | A screen rect that encapsulates the bounds. |
|
static |
Normalize an angle to a value between -180 and 180, then clamp it in the given range.
angle | Input angle. |
min | Min clamp value (applied after normalize). |
max | Max Clamp value (applied after normalize). |
|
static |
Normalize a set of euler angles to values between -180 and 180, then clamp them in the given ranges.
angles | Input angles. |
min | Min clamp values (applied after normalize). |
max | Max Clamp values (applied after normalize). |
|
static |
Divide a float by each component of a vector.
|
static |
Divide the components of left by the components of right.
|
static |
Raycast a line segment against a triangle, and return whether they intersect.
v1 | The first triangle point. |
v2 | The second triangle point. |
v3 | The third triangle point. |
s1 | The start of the segment. |
s2 | The end of the segment. |
t | The point along the input segment where it intersects the triangle, or -1. |
|
static |
Dot product of two int vectors.
|
static |
Get the eight corners of a bounding box and save them in the given array.
You can use BoundsCornerArray to avoid allocating here.
bounds | The input bounds. |
corners | Array to save the values in. |
|
static |
Get the point on a line where it is nearest to a position.
line | The input line. |
p | The input position. |
|
static |
Find the point along each line where the lines come closest to each other.
If the lines are parallel, then return false.
line1 | The first line. |
line2 | The second line. |
t1 | The point along the first line where they are closest to intersecting. |
t2 | The point along the second line where they are closest to intersecting. |
|
static |
Find the point on a bounded line segment where it is nearest to a position, and return whether that point is in the segment's bounds.
Does not return points on the ends of the segment. If the nearest point on the segment's line is outside the segment, will fail and not return a valid point.
v1 | The start of the segment. |
v2 | The end of the segment. |
point | The point to search for. |
pointOnSegment | The point on the segment closest to the input point. |
|
static |
Find the point on a triangle where it is nearest to a position, and return whether that point is in the triangle's bounds.
Does not return points on the edge of the triangle. If the nearest point on the triangle's plane is outside the triangle, will fail and not return a valid point.
v1 | The first triangle point. |
v2 | The second triangle point. |
v3 | The third triangle point. |
point | The point to search for. |
pointOnTriangle | The point on the triangle closest to the input point. |
|
static |
Find the point on a triangle (including its bounds) where it is nearest to a position.
If nearest point is on the triangle's bounds, that point will be returned, unlike GetNearestPointOnTriangle.
v1 | The first triangle point. |
v2 | The second triangle point. |
v3 | The third triangle point. |
point | The point to search for. |
|
static |
Returns a vector that is perpendicular to the given vector.
vector | Input vector. |
|
static |
Returns true if a given point is on the inner side (defined by a given normal) of a segment.
v1 | The start of the segment. |
v2 | The end of the segment. |
normal | The normal, defining which side is inside. |
point | The point to search for. |
|
static |
Multiply the components of left by the components of right.
|
static |
Normalize an angle to a value between 0 and 360.
angle | Input angle. |
|
static |
Normalize a set of euler angles to values between 0 and 360.
angles | Input angles. |
|
static |
Normalize an angle to a value between -180 and 180.
angle | Input angle. |
|
static |
Normalize a set of euler angles to values between -180 and 180.
angles | Input angles. |
|
static |
Take the reciprocal of each component of a vector.
|
static |
Round a value to the nearest multiple of a given factor.
value | Input value. |
factor | Value to round to a multiple of. |
|
static |
Round a each component of a vector to the nearest multiple of a given factor.
vector | Input values. |
factor | Value to round to a multiple of. |
|
static |
Same as Mathf.Sign, except that if the input is zero, it returns zero.
value | A number to get the sign of. |
|
static |
Split a rect into two halves horizontally, with given gap between the halves.
rect | Rect to split. |
gap | Gap between the split halves. |
out1 | Output rect 1. |
out2 | Output rect 2. |
div | The ratio of the total space taken up by the left rect. |
|
static |
Split a rect into three thirds horizontally, with given gap between the thirds.
rect | Rect to split. |
gap | Gap between the split halves. |
out1 | Output rect 1. |
out2 | Output rect 2. |
out3 | Output rect 3. |
div1 | The ratio of the total space taken up by the left rect. |
div2 | The ratio of the total space taken up by the left and center rect. |
|
static |
Get a Vector4 with the components (x, y, z, 0).
|
static |
Get a Vector4 with the components (x, y, z, 1).
|
static |
Get a Vector2 with the components (x, y).
|
static |
Get a Vector2 with the components (x, z).
|
static |
Get a Vector2 with the components (y, x).
|
static |
Get a Vector2 with the components (y, z).
|
static |
Get a Vector2 with the components (z, x).
|
static |
Get a Vector2 with the components (z, y).
|
static |
Replace the X component of a vector.
|
static |
Replace the X component of a vector.
|
static |
Replace the Y component of a vector.
|
static |
Replace the Y component of a vector.
|
static |
Convert a Vector2 to a Vector3 with the given Z.
|
static |
Replace the Z component of a vector.
|
static |
Projects a point in the world onto a canvas in camera or overlay space.
Similar to Camera.WorldToScreenPoint, but scaled to the size of the canvas and its viewport. Logs an error if the canvas is in world space, as that is not supported.
camera | The camera to use for reference. |
canvas | The canvas to use for reference. |
point | The world point to find on the canvas. |
|
static |
Get a quaternion based on a right vector and approximate up vector.
|
static |
Get a quaternion based on a right vector and approximate forward vector.
|
static |
Get a quaternion based on a up vector and approximate right vector.
|
static |
Get a quaternion based on a up vector and approximate forward vector.
|
static |
Get a quaternion based on a forward vector and approximate right vector.
|
static |
Get a quaternion based on a forward vector and approximate up vector.
|
static |
A static array that can be used to store the output of GetCorners, as long as the values are copied from the array right away.
|
static |
Evaluate all cubic roots of this Complex.
complex | The number to get the cube roots of. |
|
static |
Solve a quadratic equation (find x such that the result is zero) in the form ax^2 + bx + c = 0.
Solve a quartic equation (find x such that the result is zero) of the form ax^4 + bx^3 + cx^2 + dx + e = 0.
Solve a cubic equation (find x such that the result is zero) in the form ax^3 + bx^2 + cx + d = 0.
a | The coefficient for the x^2 term. |
b | The coefficient for the x term. |
c | The constant term. |
a | The coefficient for the x^3 term. |
b | The coefficient for the x^2 term. |
c | The coefficient for the x term. |
d | The constant term. |
a | The coefficient for the x^4 term. |
b | The coefficient for the x^3 term. |
c | The coefficient for the x^2 term. |
d | The coefficient for the x term. |
e | The constant term. |