Struct Plane
- Namespace
- Misaki.HighPerformance.Mathematics.Geometry
- Assembly
- Misaki.HighPerformance.Mathematics.dll
A plane represented by a normal vector and a distance along the normal from the origin.
public struct Plane
- Inherited Members
Remarks
A plane splits the 3D space in half. The normal vector points to the positive half and the other half is considered negative.
Constructors
Plane(float3, float3)
Constructs a plane with a normal vector and a point that lies in the plane.
public Plane(float3 normal, float3 pointInPlane)
Parameters
normalfloat3A non-zero vector that is perpendicular to the plane. It may be any length.
pointInPlanefloat3A point that lies in the plane.
Remarks
The constructed plane will be the normalized form of the plane specified by the inputs.
Plane(float3, float3, float3)
Constructs a plane with two vectors and a point that all lie in the plane.
public Plane(float3 vector1InPlane, float3 vector2InPlane, float3 pointInPlane)
Parameters
vector1InPlanefloat3A non-zero vector that lies in the plane. It may be any length.
vector2InPlanefloat3A non-zero vector that lies in the plane. It may be any length and must not be a scalar multiple of
vector1InPlane.pointInPlanefloat3A point that lies in the plane.
Remarks
The constructed plane will be the normalized form of the plane specified by the inputs.
Plane(float3, float)
Constructs a plane with a normal vector and distance from the origin.
public Plane(float3 normal, float distance)
Parameters
normalfloat3A non-zero vector that is perpendicular to the plane. It may be any length.
distancefloatDistance from the origin along the normal. A negative value moves the plane in the same direction as the normal while a positive value moves it in the opposite direction.
Remarks
The constructed plane will be the normalized form of the plane specified by the inputs.
Plane(float, float, float, float)
Constructs a Plane from arbitrary coefficients A, B, C, D of the plane equation Ax + By + Cz + Dw = 0.
public Plane(float coefficientA, float coefficientB, float coefficientC, float coefficientD)
Parameters
coefficientAfloatCoefficient A from plane equation.
coefficientBfloatCoefficient B from plane equation.
coefficientCfloatCoefficient C from plane equation.
coefficientDfloatCoefficient D from plane equation.
Remarks
The constructed plane will be the normalized form of the plane specified by the given coefficients.
Fields
normalAndDistance
A plane in the form Ax + By + Cz + Dw = 0.
public float4 normalAndDistance
Field Value
Remarks
Stores the plane coefficients A, B, C, D where (A, B, C) is a unit normal vector and D is the distance from the origin. A plane stored with a unit normal vector is called a normalized plane.
Properties
Distance
Get/set the distance of the plane from the origin. May be a negative value.
public float Distance { get; set; }
Property Value
Remarks
It is assumed that the normal is unit length. If you set a new plane such that Ax + By + Cz + Dw = 0 but (A, B, C) is not unit length, then you must normalize the plane by calling Normalize(Plane).
Flipped
Flips the plane so the normal points in the opposite direction.
public Plane Flipped { get; }
Property Value
Normal
Get/set the normal vector of the plane.
public float3 Normal { get; set; }
Property Value
Remarks
It is assumed that the normal is unit length. If you set a new plane such that Ax + By + Cz + Dw = 0 but (A, B, C) is not unit length, then you must normalize the plane by calling Normalize(Plane).
Methods
CreateFromUnitNormalAndDistance(float3, float)
Creates a normalized Plane directly without normalization cost.
public static Plane CreateFromUnitNormalAndDistance(float3 unitNormal, float distance)
Parameters
unitNormalfloat3A non-zero vector that is perpendicular to the plane. It must be unit length.
distancefloatDistance from the origin along the normal. A negative value moves the plane in the same direction as the normal while a positive value moves it in the opposite direction.
Returns
- Plane
Normalized Plane constructed from given inputs.
Remarks
If you have a unit length normal vector, you can create a Plane faster than using one of its constructors by calling this function.
CreateFromUnitNormalAndPointInPlane(float3, float3)
Creates a normalized Plane without normalization cost.
public static Plane CreateFromUnitNormalAndPointInPlane(float3 unitNormal, float3 pointInPlane)
Parameters
unitNormalfloat3A non-zero vector that is perpendicular to the plane. It must be unit length.
pointInPlanefloat3A point that lies in the plane.
Returns
- Plane
Normalized Plane constructed from given inputs.
Remarks
If you have a unit length normal vector, you can create a Plane faster than using one of its constructors by calling this function.
Normalize(Plane)
Normalizes the given Plane.
public static Plane Normalize(Plane plane)
Parameters
planePlanePlane to normalize.
Returns
- Plane
Normalized Plane.
Normalize(float4)
Normalizes the plane represented by the given plane coefficients.
public static float4 Normalize(float4 planeCoefficients)
Parameters
planeCoefficientsfloat4Plane coefficients A, B, C, D stored in x, y, z, w (respectively).
Returns
- float4
Normalized plane coefficients.
Remarks
The plane coefficients are A, B, C, D and stored in that order in the float4.
Projection(float3)
Projects the given point onto the plane.
public float3 Projection(float3 point)
Parameters
pointfloat3Point to project onto the plane.
Returns
- float3
Projected point that's inside the plane.
Remarks
Plane must be normalized prior to calling this function. The result is the position closest to the point that still lies in the plane.
SignedDistanceToPoint(float3)
Get the signed distance from the point to the plane.
public float SignedDistanceToPoint(float3 point)
Parameters
pointfloat3Point to find the signed distance with.
Returns
- float
Signed distance of the point from the plane.
Remarks
Plane must be normalized prior to calling this function. Distance is positive if point is on side of the plane the normal points to, negative if on the opposite side and zero if the point lies in the plane. Avoid comparing equality with 0.0f when testing if a point lies exactly in the plane and use an approximate comparison instead.
Operators
implicit operator float4(Plane)
public static implicit operator float4(Plane plane)
Parameters
planePlanePlane to convert.