Vector2.BaryCentric(Vector2,Vector2,Vector2,Single,Single) Method (Microsoft.DirectX)

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

Definition

Visual Basic Public Shared Function BaryCentric( _
    ByVal v1 As Vector2, _
    ByVal v2 As Vector2, _
    ByVal v3 As Vector2, _
    ByVal f As Single, _
    ByVal g As Single _
) As Vector2
C# public static Vector2 BaryCentric(
    Vector2 v1,
    Vector2 v2,
    Vector2 v3,
    float f,
    float g
);
C++ public:
static Vector2 BaryCentric(
    Vector2 v1,
    Vector2 v2,
    Vector2 v3,
    float f,
    float g
);
JScript public static function BaryCentric(
    v1 : Vector2,
    v2 : Vector2,
    v3 : Vector2,
    f : float,
    g : float
) : Vector2;

Parameters

v1 Microsoft.DirectX.Vector2
Source Vector2 structure.
v2 Microsoft.DirectX.Vector2
Source Vector2 structure.
v3 Microsoft.DirectX.Vector2
Source Vector2 structure.
f System.Single
Weighting factor. See Remarks.
g System.Single
Weighting factor. See Remarks.

Return Value

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

Remarks

The BaryCentric method provides a way to understand points in and around a triangle, regardless of its actual location. This method returns the resulting point by using the following equation.

v1 + f(v2 - v1) + g(v3 - v1)

Any point in the plane v1v2v3 can be represented by the barycentric coordinates (f, g). The f parameter controls the extent to which v2 gets weighted into the result, and the f parameter controls the extent to which v3 gets weighted into the result. Lastly, (1 - f - g) controls the extent to which v1 gets weighted into the result.

Note the following relations.

  • If (f >= 0 && g >=0 && 1 - f - g >= 0), the point is inside the triangle v1v2v3.
  • If (f == 0 && g >= 0 && 1 - f - g >= 0), the point is on the line v1v3.
  • If (f >= 0 && g == 0 && 1 - f - g >= 0), the point is on the line v1v2.
  • If (f >= 0 && g >= 0 && 1 - f - g == 0), the point is on the line v2v3.

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 also holds true for barycentric coordinates.