Function directx_math::XMVectorBaryCentric [−][src]
pub fn XMVectorBaryCentric(
Position0: FXMVECTOR,
Position1: FXMVECTOR,
Position2: FXMVECTOR,
f: f32,
g: f32
) -> XMVECTOR
Returns a point in Barycentric coordinates, using the specified position vectors.
Parameters
Position0
First position.
Position1
Second position.
Position2
Third position.
f
Weighting factor. See the remarks.
g
Weighting factor. See the remarks.
Return value
Returns the Barycentric coordinates.
Remarks
This function provides a way to understand points in and around a triangle, independent of where the triangle is located. This function returns the resulting point by using the following equation:
Position0 + f * (Position1 - Position0) + g * (Position2 - Position0)
Any point in the plane Position0Position1Position2
can be represented by the Barycentric coordinate
(f, g)
, where f
controls how much Position1
gets weighted into the result, and g
controls how much
Position2
gets weighted into the result. Lastly, 1-f-g
controls how much Position0
gets weighted
into the result.
Note the following relations.
- If
(f>=0 && g>=0 && 1-f-g>=0)
, the point is inside the trianglePosition0Position1Position2
. - If
(f==0 && g>=0 && 1-f-g>=0)
, the point is on the linePosition0Position2
. - If
(f>=0 && g==0 && 1-f-g>=0)
, the point is on the linePosition0Position1
. - If
(f>=0 && g>=0 && 1-f-g==0)
, the point is on the linePosition1Position2
.
Barycentric coordinates are a form of general coordinates. In this context, using Barycentric coordinates
represents a change in coordinate systems. What holds true
for Cartesian coordinates holds true
for
Barycentric coordinates.
Reference
https://docs.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-XMVectorBaryCentric