# MathHelper.Barycentric Method

**XNA Game Studio 4.0**

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

public static float Barycentric ( float value1, float value2, float value3, float amount1, float amount2 )

#### Parameters

*value1*- The coordinate on one axis of vertex 1 of the defining triangle.
*value2*- The coordinate on the same axis of vertex 2 of the defining triangle.
*value3*- The coordinate on the same axis of vertex 3 of the defining triangle.
*amount1*- The normalized barycentric (areal) coordinate
**b2**, equal to the weighting factor for vertex 2, the coordinate of which is specified in*value2*. *amount2*- The normalized barycentric (areal) coordinate
**b3**, equal to the weighting factor for vertex 3, the coordinate of which is specified in*value3*.

#### Return Value

## 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 three 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);

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** is known to equal **(1** − **b2** − **b3)**.

## What MathHelper Barycentric Does

On an axis **a** (**a** being the x-, y-, or z-axis), the MathHelper.Barycentric method takes three triangle vertex coordinates on that axis (**V1a**, **V2a**, and **V3a**), 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 **b3** coordinate relates to **V3**.

Barycentric then calculates the Cartesian coordinate of **Pa** as follows:

Pa = ( (1 - b2 - b3) * V1a ) + (b2 * V2a) + (b3 * V3a);

Thus, to calculate the x-axis Cartesian coordinate of **P**, you would pass the x-coordinates of the triangle vertices to Barycentric together with the approproiate areal coordinates of **P**.