Class Vector3Helper
- Namespace
- HelixToolkit.Maths
- Assembly
- HelixToolkit.Maths.dll
Represents a three dimensional mathematical vector.
public static class Vector3Helper
- Inheritance
-
Vector3Helper
- Inherited Members
Fields
BackwardLH
A unit Vector3 designating backward in a left-handed coordinate system (0, 0, -1).
public static readonly Vector3 BackwardLH
Field Value
BackwardRH
A unit Vector3 designating backward in a right-handed coordinate system (0, 0, 1).
public static readonly Vector3 BackwardRH
Field Value
Down
A unit Vector3 designating down (0, -1, 0).
public static readonly Vector3 Down
Field Value
ForwardLH
A unit Vector3 designating forward in a left-handed coordinate system (0, 0, 1).
public static readonly Vector3 ForwardLH
Field Value
ForwardRH
A unit Vector3 designating forward in a right-handed coordinate system (0, 0, -1).
public static readonly Vector3 ForwardRH
Field Value
Left
A unit Vector3 designating left (-1, 0, 0).
public static readonly Vector3 Left
Field Value
One
A Vector3 with all of its components set to one.
public static readonly Vector3 One
Field Value
Right
A unit Vector3 designating right (1, 0, 0).
public static readonly Vector3 Right
Field Value
SizeInBytes
The size of the Vector3 type, in bytes.
public static readonly int SizeInBytes
Field Value
UnitX
The X unit Vector3 (1, 0, 0).
public static readonly Vector3 UnitX
Field Value
UnitY
The Y unit Vector3 (0, 1, 0).
public static readonly Vector3 UnitY
Field Value
UnitZ
The Z unit Vector3 (0, 0, 1).
public static readonly Vector3 UnitZ
Field Value
Up
A unit Vector3 designating up (0, 1, 0).
public static readonly Vector3 Up
Field Value
Zero
A Vector3 with all of its components set to zero.
public static readonly Vector3 Zero
Field Value
Methods
AngleBetween(Vector3, Vector3)
Calculates the angle (in radians) between two vectors.
public static float AngleBetween(this Vector3 vector1, Vector3 vector2)
Parameters
Returns
- float
The angle (in radians) between the vectors.
Remarks
Note that the returned angle is never bigger than the constant PI.
AnyInfinity(Vector3)
public static bool AnyInfinity(this Vector3 vector)
Parameters
vectorVector3
Returns
AnyUndefined(Vector3)
Determines whether any components of the vector are undefined (NaN).
public static bool AnyUndefined(this Vector3 vector)
Parameters
vectorVector3The vector.
Returns
- bool
trueif the vector has at least one undefined component; otherwise,false.
Barycentric(Vector3, Vector3, Vector3, float, float)
Returns a Vector3 containing the 3D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 3D triangle.
public static Vector3 Barycentric(Vector3 value1, Vector3 value2, Vector3 value3, float amount1, float amount2)
Parameters
value1Vector3A Vector3 containing the 3D Cartesian coordinates of vertex 1 of the triangle.
value2Vector3A Vector3 containing the 3D Cartesian coordinates of vertex 2 of the triangle.
value3Vector3A Vector3 containing the 3D Cartesian coordinates of vertex 3 of the triangle.
amount1floatBarycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in
value2).amount2floatBarycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in
value3).
Returns
Barycentric(ref Vector3, ref Vector3, ref Vector3, float, float, out Vector3)
Returns a Vector3 containing the 3D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 3D triangle.
public static void Barycentric(ref Vector3 value1, ref Vector3 value2, ref Vector3 value3, float amount1, float amount2, out Vector3 result)
Parameters
value1Vector3A Vector3 containing the 3D Cartesian coordinates of vertex 1 of the triangle.
value2Vector3A Vector3 containing the 3D Cartesian coordinates of vertex 2 of the triangle.
value3Vector3A Vector3 containing the 3D Cartesian coordinates of vertex 3 of the triangle.
amount1floatBarycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in
value2).amount2floatBarycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in
value3).resultVector3When the method completes, contains the 3D Cartesian coordinates of the specified point.
CatmullRom(Vector3, Vector3, Vector3, Vector3, float)
Performs a Catmull-Rom interpolation using the specified positions.
public static Vector3 CatmullRom(Vector3 value1, Vector3 value2, Vector3 value3, Vector3 value4, float amount)
Parameters
value1Vector3The first position in the interpolation.
value2Vector3The second position in the interpolation.
value3Vector3The third position in the interpolation.
value4Vector3The fourth position in the interpolation.
amountfloatWeighting factor.
Returns
- Vector3
A vector that is the result of the Catmull-Rom interpolation.
CatmullRom(ref Vector3, ref Vector3, ref Vector3, ref Vector3, float, out Vector3)
Performs a Catmull-Rom interpolation using the specified positions.
public static void CatmullRom(ref Vector3 value1, ref Vector3 value2, ref Vector3 value3, ref Vector3 value4, float amount, out Vector3 result)
Parameters
value1Vector3The first position in the interpolation.
value2Vector3The second position in the interpolation.
value3Vector3The third position in the interpolation.
value4Vector3The fourth position in the interpolation.
amountfloatWeighting factor.
resultVector3When the method completes, contains the result of the Catmull-Rom interpolation.
Clamp(Vector3, Vector3, Vector3)
public static Vector3 Clamp(this Vector3 value, Vector3 min, Vector3 max)
Parameters
Returns
Clamp(ref Vector3, ref Vector3, ref Vector3, out Vector3)
public static void Clamp(ref Vector3 value, ref Vector3 min, ref Vector3 max, out Vector3 result)
Parameters
FindAnyPerpendicular(Vector3)
public static Vector3 FindAnyPerpendicular(this Vector3 value)
Parameters
valueVector3
Returns
Get(Vector3, int)
Gets or sets the component at the specified index.
public static float Get(this Vector3 v, int index)
Parameters
vVector3indexintThe index of the component to access. Use 0 for the X component, 1 for the Y component, and 2 for the Z component.
Returns
- float
The value of the X, Y, or Z component, depending on the index.
Exceptions
- ArgumentOutOfRangeException
Thrown when the
indexis out of the range [0, 2].
GetCentroid(IList<Vector3>)
public static Vector3 GetCentroid(this IList<Vector3> vertices)
Parameters
Returns
GetCentroid(IList<Vector3>, int, int)
public static Vector3 GetCentroid(this IList<Vector3> vertices, int start, int count)
Parameters
Returns
Hermite(Vector3, Vector3, Vector3, Vector3, float)
Performs a Hermite spline interpolation.
public static Vector3 Hermite(Vector3 value1, Vector3 tangent1, Vector3 value2, Vector3 tangent2, float amount)
Parameters
value1Vector3First source position vector.
tangent1Vector3First source tangent vector.
value2Vector3Second source position vector.
tangent2Vector3Second source tangent vector.
amountfloatWeighting factor.
Returns
- Vector3
The result of the Hermite spline interpolation.
Hermite(ref Vector3, ref Vector3, ref Vector3, ref Vector3, float, out Vector3)
Performs a Hermite spline interpolation.
public static void Hermite(ref Vector3 value1, ref Vector3 tangent1, ref Vector3 value2, ref Vector3 tangent2, float amount, out Vector3 result)
Parameters
value1Vector3First source position vector.
tangent1Vector3First source tangent vector.
value2Vector3Second source position vector.
tangent2Vector3Second source tangent vector.
amountfloatWeighting factor.
resultVector3When the method completes, contains the result of the Hermite spline interpolation.
IsNormalized(Vector3)
Gets a value indicting whether this instance is normalized.
public static bool IsNormalized(this Vector3 v)
Parameters
vVector3
Returns
IsZero(Vector3)
Gets a value indicting whether this vector is zero
public static bool IsZero(this Vector3 v)
Parameters
vVector3
Returns
Max(Vector3, Vector3)
public static Vector3 Max(this Vector3 v1, Vector3 v2)
Parameters
Returns
Max(Vector3, ref Vector3)
public static Vector3 Max(this Vector3 v1, ref Vector3 v2)
Parameters
Returns
Min(Vector3, Vector3)
public static Vector3 Min(this Vector3 v1, Vector3 v2)
Parameters
Returns
Min(Vector3, ref Vector3)
public static Vector3 Min(this Vector3 v1, ref Vector3 v2)
Parameters
Returns
MinMax(IList<Vector3>, int, int, out Vector3, out Vector3)
public static void MinMax(this IList<Vector3> vectors, int start, int count, out Vector3 min, out Vector3 max)
Parameters
MinMax(IList<Vector3>, out Vector3, out Vector3)
public static void MinMax(this IList<Vector3> vectors, out Vector3 min, out Vector3 max)
Parameters
NearEqual(Vector3, Vector3, Vector3)
Tests whether one 3D vector is near another 3D vector.
public static bool NearEqual(Vector3 left, Vector3 right, Vector3 epsilon)
Parameters
Returns
- bool
trueif left and right are near another 3D,falseotherwise
NearEqual(ref Vector3, ref Vector3, ref Vector3)
Tests whether one 3D vector is near another 3D vector.
public static bool NearEqual(ref Vector3 left, ref Vector3 right, ref Vector3 epsilon)
Parameters
Returns
- bool
trueif left and right are near another 3D,falseotherwise
Orthogonalize(Vector3[], params Vector3[])
Orthogonalizes a list of vectors.
public static void Orthogonalize(Vector3[] destination, params Vector3[] source)
Parameters
destinationVector3[]The list of orthogonalized vectors.
sourceVector3[]The list of vectors to orthogonalize.
Remarks
Orthogonalization is the process of making all vectors orthogonal to each other. This means that any given vector in the list will be orthogonal to any other given vector in the list.
Because this method uses the modified Gram-Schmidt process, the resulting vectors tend to be numerically unstable. The numeric stability decreases according to the vectors position in the list so that the first vector is the most stable and the last vector is the least stable.
Exceptions
- ArgumentNullException
Thrown when
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
Orthonormalize(Vector3[], params Vector3[])
Orthonormalizes a list of vectors.
public static void Orthonormalize(Vector3[] destination, params Vector3[] source)
Parameters
destinationVector3[]The list of orthonormalized vectors.
sourceVector3[]The list of vectors to orthonormalize.
Remarks
Orthonormalization is the process of making all vectors orthogonal to each other and making all vectors of unit length. This means that any given vector will be orthogonal to any other given vector in the list.
Because this method uses the modified Gram-Schmidt process, the resulting vectors tend to be numerically unstable. The numeric stability decreases according to the vectors position in the list so that the first vector is the most stable and the last vector is the least stable.
Exceptions
- ArgumentNullException
Thrown when
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
PointToPlanePosition(Vector3, Plane)
Point to plane position. Front/Back/Intersecting.
public static PlaneIntersectionType PointToPlanePosition(this Vector3 point, Plane plane)
Parameters
Returns
PointToPlanePosition(Vector3, ref Plane)
Point to plane position. Front/Back/Intersecting.
public static PlaneIntersectionType PointToPlanePosition(this Vector3 point, ref Plane plane)
Parameters
Returns
Project(Vector3, float, float, float, float, float, float, Matrix4x4)
Projects a 3D vector from object space into screen space.
public static Vector3 Project(Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix4x4 worldViewProjection)
Parameters
vectorVector3The vector to project.
xfloatThe X position of the viewport.
yfloatThe Y position of the viewport.
widthfloatThe width of the viewport.
heightfloatThe height of the viewport.
minZfloatThe minimum depth of the viewport.
maxZfloatThe maximum depth of the viewport.
worldViewProjectionMatrix4x4The combined world-view-projection matrix.
Returns
- Vector3
The vector in screen space.
Project(ref Vector3, float, float, float, float, float, float, ref Matrix4x4, out Vector3)
Projects a 3D vector from object space into screen space.
public static void Project(ref Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix4x4 worldViewProjection, out Vector3 result)
Parameters
vectorVector3The vector to project.
xfloatThe X position of the viewport.
yfloatThe Y position of the viewport.
widthfloatThe width of the viewport.
heightfloatThe height of the viewport.
minZfloatThe minimum depth of the viewport.
maxZfloatThe maximum depth of the viewport.
worldViewProjectionMatrix4x4The combined world-view-projection matrix.
resultVector3When the method completes, contains the vector in screen space.
RotateAround(in Vector3, in Vector3, in Vector3, float)
Rotates the source around the target by the rotation angle around the supplied axis.
public static Vector3 RotateAround(this in Vector3 source, in Vector3 target, in Vector3 axis, float angle)
Parameters
sourceVector3The position to rotate.
targetVector3The point to rotate around.
axisVector3The axis of rotation.
anglefloatThe angle to rotate by in radians.
Returns
- Vector3
The rotated vector.
Set(ref Vector3, int, float)
public static void Set(ref Vector3 v, int index, float value)
Parameters
SignedAngleBetween(Vector3, Vector3, Vector3)
Calculates the signed angle (in radians) between two vectors.
public static float SignedAngleBetween(this Vector3 vector1, Vector3 vector2, Vector3 axis)
Parameters
vector1Vector3The first vector.
vector2Vector3The second vector.
axisVector3The vector around which the other vectors are rotated.
Returns
- float
The signed angle (in radians) between two vectors.
Remarks
The sign of the angle is positive in a counter-clockwise direction and negative in a clockwise direction when viewed from the side specified by the axis.
SmoothStep(Vector3, Vector3, float)
Performs a cubic interpolation between two vectors.
public static Vector3 SmoothStep(Vector3 start, Vector3 end, float amount)
Parameters
startVector3Start vector.
endVector3End vector.
amountfloatValue between 0 and 1 indicating the weight of
end.
Returns
- Vector3
The cubic interpolation of the two vectors.
SmoothStep(ref Vector3, ref Vector3, float, out Vector3)
Performs a cubic interpolation between two vectors.
public static void SmoothStep(ref Vector3 start, ref Vector3 end, float amount, out Vector3 result)
Parameters
startVector3Start vector.
endVector3End vector.
amountfloatValue between 0 and 1 indicating the weight of
end.resultVector3When the method completes, contains the cubic interpolation of the two vectors.
ToArray(Vector3)
Creates an array containing the elements of the vector.
public static float[] ToArray(this Vector3 v)
Parameters
vVector3
Returns
- float[]
A three-element array containing the components of the vector.
Transform(Vector3, Matrix3x3)
Transforms a 3D vector by the given Matrix3x3.
public static Vector3 Transform(Vector3 vector, Matrix3x3 transform)
Parameters
Returns
Transform(Vector3, ref Matrix3x3)
Transforms a 3D vector by the given Matrix3x3.
public static Vector3 Transform(Vector3 vector, ref Matrix3x3 transform)
Parameters
Returns
Transform(ref Vector3, ref Matrix3x3, out Vector3)
Transforms a 3D vector by the given Matrix3x3.
public static void Transform(ref Vector3 vector, ref Matrix3x3 transform, out Vector3 result)
Parameters
vectorVector3The source vector.
transformMatrix3x3The transformation Matrix3x3.
resultVector3When the method completes, contains the transformed Vector3.
Transform(ref Vector3, ref Matrix4x4, out Vector4)
Transforms a 3D vector by the given Matrix4x4.
public static void Transform(ref Vector3 vector, ref Matrix4x4 transform, out Vector4 result)
Parameters
vectorVector3The source vector.
transformMatrix4x4The transformation Matrix4x4.
resultVector4When the method completes, contains the transformed Vector4.
Transform(Vector3[], ref Matrix4x4, Vector4[])
Transforms an array of 3D vectors by the given Matrix4x4.
public static void Transform(Vector3[] source, ref Matrix4x4 transform, Vector4[] destination)
Parameters
sourceVector3[]The array of vectors to transform.
transformMatrix4x4The transformation Matrix4x4.
destinationVector4[]The array for which the transformed vectors are stored.
Exceptions
- ArgumentNullException
Thrown when
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
Transform(Vector3[], ref Quaternion, Vector3[])
Transforms an array of vectors by the given Quaternion rotation.
public static void Transform(Vector3[] source, ref Quaternion rotation, Vector3[] destination)
Parameters
sourceVector3[]The array of vectors to transform.
rotationQuaternionThe Quaternion rotation to apply.
destinationVector3[]The array for which the transformed vectors are stored. This array may be the same array as
source.
Exceptions
- ArgumentNullException
Thrown when
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
TransformCoordinate(IList<Vector3>, ref Matrix4x4, IList<Vector3>)
Performs a coordinate transformation on an array of vectors using the given Matrix4x4.
public static void TransformCoordinate(this IList<Vector3> source, ref Matrix4x4 transform, IList<Vector3> destination)
Parameters
sourceIList<Vector3>The array of coordinate vectors to transform.
transformMatrix4x4The transformation Matrix4x4.
destinationIList<Vector3>The array for which the transformed vectors are stored. This array may be the same array as
source.
Remarks
A coordinate transform performs the transformation with the assumption that the w component is one. The four dimensional vector obtained from the transformation operation has each component in the vector divided by the w component. This forces the w component to be one and therefore makes the vector homogeneous. The homogeneous vector is often preferred when working with coordinates as the w component can safely be ignored.
Exceptions
- ArgumentNullException
Thrown when
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
TransformCoordinate(Vector3, Matrix4x4)
Performs a coordinate transformation using the given Matrix4x4.
public static Vector3 TransformCoordinate(this Vector3 coordinate, Matrix4x4 transform)
Parameters
coordinateVector3The coordinate vector to transform.
transformMatrix4x4The transformation Matrix4x4.
Returns
- Vector3
The transformed coordinates.
Remarks
A coordinate transform performs the transformation with the assumption that the w component is one. The four dimensional vector obtained from the transformation operation has each component in the vector divided by the w component. This forces the w component to be one and therefore makes the vector homogeneous. The homogeneous vector is often preferred when working with coordinates as the w component can safely be ignored.
TransformCoordinate(Vector3, ref Matrix4x4)
Performs a coordinate transformation using the given Matrix4x4.
public static Vector3 TransformCoordinate(this Vector3 coordinate, ref Matrix4x4 transform)
Parameters
coordinateVector3The coordinate vector to transform.
transformMatrix4x4The transformation Matrix4x4.
Returns
- Vector3
The transformed coordinates.
Remarks
A coordinate transform performs the transformation with the assumption that the w component is one. The four dimensional vector obtained from the transformation operation has each component in the vector divided by the w component. This forces the w component to be one and therefore makes the vector homogeneous. The homogeneous vector is often preferred when working with coordinates as the w component can safely be ignored.
TransformCoordinate(ref Vector3, ref Matrix4x4, out Vector3)
Performs a coordinate transformation using the given Matrix4x4.
public static void TransformCoordinate(ref Vector3 coordinate, ref Matrix4x4 transform, out Vector3 result)
Parameters
coordinateVector3The coordinate vector to transform.
transformMatrix4x4The transformation Matrix4x4.
resultVector3When the method completes, contains the transformed coordinates.
Remarks
A coordinate transform performs the transformation with the assumption that the w component is one. The four dimensional vector obtained from the transformation operation has each component in the vector divided by the w component. This forces the w component to be one and therefore makes the vector homogeneous. The homogeneous vector is often preferred when working with coordinates as the w component can safely be ignored.
TransformNormal(IList<Vector3>, ref Matrix4x4, IList<Vector3>)
Performs a normal transformation on an array of vectors using the given Matrix4x4.
public static void TransformNormal(this IList<Vector3> source, ref Matrix4x4 transform, IList<Vector3> destination)
Parameters
sourceIList<Vector3>The array of normal vectors to transform.
transformMatrix4x4The transformation Matrix4x4.
destinationIList<Vector3>The array for which the transformed vectors are stored. This array may be the same array as
source.
Remarks
A normal transform performs the transformation with the assumption that the w component is zero. This causes the fourth row and fourth column of the matrix to be unused. The end result is a vector that is not translated, but all other transformation properties apply. This is often preferred for normal vectors as normals purely represent direction rather than location because normal vectors should not be translated.
Exceptions
- ArgumentNullException
Thrown when
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
TransformNormal(Vector3, ref Matrix4x4)
Performs a normal transformation using the given Matrix4x4.
public static Vector3 TransformNormal(this Vector3 normal, ref Matrix4x4 transform)
Parameters
Returns
Remarks
A normal transform performs the transformation with the assumption that the w component is zero. This causes the fourth row and fourth column of the matrix to be unused. The end result is a vector that is not translated, but all other transformation properties apply. This is often preferred for normal vectors as normals purely represent direction rather than location because normal vectors should not be translated.
TransformNormal(ref Vector3, ref Matrix4x4, out Vector3)
Performs a normal transformation using the given Matrix4x4.
public static void TransformNormal(ref Vector3 normal, ref Matrix4x4 transform, out Vector3 result)
Parameters
normalVector3The normal vector to transform.
transformMatrix4x4The transformation Matrix4x4.
resultVector3When the method completes, contains the transformed normal.
Remarks
A normal transform performs the transformation with the assumption that the w component is zero. This causes the fourth row and fourth column of the matrix to be unused. The end result is a vector that is not translated, but all other transformation properties apply. This is often preferred for normal vectors as normals purely represent direction rather than location because normal vectors should not be translated.
Unproject(Vector3, float, float, float, float, float, float, Matrix4x4)
Projects a 3D vector from screen space into object space.
public static Vector3 Unproject(Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix4x4 worldViewProjection)
Parameters
vectorVector3The vector to project.
xfloatThe X position of the viewport.
yfloatThe Y position of the viewport.
widthfloatThe width of the viewport.
heightfloatThe height of the viewport.
minZfloatThe minimum depth of the viewport.
maxZfloatThe maximum depth of the viewport.
worldViewProjectionMatrix4x4The combined world-view-projection matrix.
Returns
- Vector3
The vector in object space.
Unproject(ref Vector3, float, float, float, float, float, float, ref Matrix4x4, out Vector3)
Projects a 3D vector from screen space into object space.
public static void Unproject(ref Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix4x4 worldViewProjection, out Vector3 result)
Parameters
vectorVector3The vector to project.
xfloatThe X position of the viewport.
yfloatThe Y position of the viewport.
widthfloatThe width of the viewport.
heightfloatThe height of the viewport.
minZfloatThe minimum depth of the viewport.
maxZfloatThe maximum depth of the viewport.
worldViewProjectionMatrix4x4The combined world-view-projection matrix.
resultVector3When the method completes, contains the vector in object space.