次の方法で共有


Vector4.Barycentric Method (Vector4, Vector4, Vector4, Single, Single)

Returns a Vector4 containing the 4D Cartesian coordinates of a point specified in barycentric (areal) coordinates relative to a 4D triangle.

Syntax

'Declaration
Public Shared Function Barycentric ( _
         value1 As Vector4, _
         value2 As Vector4, _
         value3 As Vector4, _
         amount1 As Single, _
         amount2 As Single _
) As Vector4 
public static Vector4 Barycentric (
         Vector4 value1,
         Vector4 value2,
         Vector4 value3,
         float amount1,
         float amount2
)
public:
static Vector4 Barycentric(
         Vector4 value1,
         Vector4 value2,
         Vector4 value3,
         float amount1,
         float amount2
)

Parameters

  • value1
    Type: Vector4
    A Vector4 containing the 4D Cartesian coordinates of vertex 1 of the triangle.
  • value2
    Type: Vector4
    A Vector4 containing the 4D Cartesian coordinates of vertex 2 of the triangle.
  • value3
    Type: Vector4
    A Vector4 containing the 4D Cartesian coordinates of vertex 3 of the triangle.
  • amount1
    Type: Single
    Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in value2).
  • amount2
    Type: Single
    Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in value3).

Return Value

Type: Vector4
A new Vector4 containing the 4D Cartesian coordinates of the specified point.

Remarks

About Barycentric Coordinates

Given a triangle with vertices V1, V2, and V3, any point P on the plane of that triangle can be specified by 3 weighting factors b1, b2, and b3, each of which indicates how much relative influence the corresponding triangle vertex contributes to the location of the point, as specified in the following formulas.

    Px = (b1 * V1x) + (b2 * V2x) + (b3 * V3x);
    Py = (b1 * V1y) + (b2 * V2y) + (b3 * V3y);
    Pz = (b1 * V1z) + (b2 * V2z) + (b3 * V3z);
    Pw = (b1 * V1w) + (b2 * V2w) + (b3 * V3w);

Such triple weighting factors b1, b2, and b3 are called barycentric coordinates.

Barycentric coordinates express relative weights, meaning that (k * b1), (k * b2), and (k * b3) are also coordinates of the same point as b1, b2, and b3 for any positive value of k.

If a set of barycentric coordinates is normalized so that: b1 + b2 + b3 = 1, the resulting coordinates are unique for the point in question, and are known as areal coordinates. When normalized in this way, only two coordinates are needed, say b2 and b3, since b1 equals (1b2b3).

Bb195071.Barycentric(en-us,XNAGameStudio.42).gif

What Vector4 Barycentric Does

The Vector4 Barycentric method takes three vectors specifying the Cartesian coordinates of the triangle vertices, V1, V2, and V3), and two areal coordinates b2 and b3 of some point P (b2 is the amount1 argument and b3 is the amount2 argument). The b2 coordinate relates to vertex V2, and the b3coordinate relates to V3.

Barycentric then calculates the Cartesian coordinate of P as follows:

    Px = ( (1 - b2 - b3) * V1x ) + (b2 * V2x) + (b3 * V3x);
    Py = ( (1 - b2 - b3) * V1y ) + (b2 * V2y) + (b3 * V3y);
    Pz = ( (1 - b2 - b3) * V1z ) + (b2 * V2z) + (b3 * V3z);
    Pw = ( (1 - b2 - b3) * V1w ) + (b2 * V2w) + (b3 * V3w);

Thus, to calculate the 3D Cartesian coordinates of P, you would pass the coordinates of the triangle vertices to Barycentric together with the appropropriate normalized barycentric (areal) coordinates of P.

The following relationships may be useful.

  • If ( (amount1 <= 0) and (amount2 >= 0) and (1 − amount1amount2 >= 0) ), then the point is inside the triangle defined by value1, value2, and value3.
  • If ( (amount1 == 0) and (amount2 >= 0) and (1 − amount1amount2 >= 0) ), then the point is on the line defined by value1 and value3.
  • If ( (amount1 >= 0) and (amount2 == 0) and (1 − amount1amount2 >= 0) ), then the point is on the line defined by value1 and value2.
  • If ( (amount1 >= 0) and (amount2 >= 0) and (1 − amount1amount2 == 0) ), then the point is on the line defined by value2 and value3.

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.

Requirements

Namespace: Microsoft.Xna.Framework

Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

See Also

Reference

Vector4 Structure
Vector4 Members
Microsoft.Xna.Framework Namespace

Platforms

Windows Phone