# UnsafeNativeMethods.Vector3.BaryCentric(Vector3,Vector3,Vector3,Vector3,Single,Single) Method (Microsoft.DirectX)

Returns a point in barycentric coordinates, using specified 3-D vectors.

Note: For programming in Microsoft Visual Basic .NET or Microsoft JScript .NET, use the equivalent method in the Microsoft.DirectX structures.

Definition

 Visual Basic Public Shared Function BaryCentric( _     ByVal pOut As Vector3, _     ByVal pV1 As Vector3, _     ByVal pV2 As Vector3, _     ByVal pV3 As Vector3, _     ByVal f As Single, _     ByVal g As Single _ ) As Vector3 C# public static Vector3 BaryCentric(     Vector3 pOut,     Vector3 pV1,     Vector3 pV2,     Vector3 pV3,     float f,     float g ); C++ public: static Vector3 BaryCentric(     Vector3 pOut,     Vector3 pV1,     Vector3 pV2,     Vector3 pV3,     float f,     float g ); JScript public static function BaryCentric(     pOut : Vector3,     pV1 : Vector3,     pV2 : Vector3,     pV3 : Vector3,     f : float,     g : float ) : Vector3;

Parameters

 pOut Microsoft.DirectX.Vector3 A Vector3 structure in barycentric coordinates. pV1 Microsoft.DirectX.Vector3 Source Vector3 structure. pV2 Microsoft.DirectX.Vector3 Source Vector3 structure. pV3 Microsoft.DirectX.Vector3 Source Vector3 structure. f System.Single Weighting factor. See Remarks. g System.Single Weighting factor. See Remarks.

Return Value

Microsoft.DirectX.Vector3
A Vector3 structure in barycentric coordinates.

Remarks

The BaryCentric method provides a way to understand points in and around a triangle, regardless of where the triangle is actually located. This method returns the resulting point by using the following equation.

pV1 + f(pV2 - pV1) + g(pV3 - pV1)

Any point in the plane pV1pV2pV3 can be represented by the barycentric coordinates (f, g). The f parameter controls the extent to which pV2 gets weighted into the result, and the f parameter controls the extent to which pV3 gets weighted into the result. Lastly, (1 - f - g) controls the extent to which pV1 gets weighted into the result.

Note the following relations.

• If (f >= 0 && g >=0 && 1 - f - g >= 0), the point is inside the triangle pV1pV2pV3.
• If (f == 0 && g >= 0 && 1 - f - g >= 0), the point is on the line pV1pV3.
• If (f >= 0 && g == 0 && 1 - f - g >= 0), the point is on the line pV1pV2.
• If (f >= 0 && g >= 0 && 1 - f - g == 0), the point is on the line pV2pV3.

Barycentric coordinates are a form of general coordinates. In this context, using them represents a change in coordinate systems. What holds true for Cartesian coordinates holds true for barycentric coordinates.

The return value for this method is the same value returned in the pOut parameter. This allows you to use the BaryCentric method as a parameter for another method.