Barycentric Coordinate Calculator – Triangle Weight Conversion
Barycentric coordinates describe the position of a point relative to a reference triangle instead of relative to a fixed origin. Any point P in the plane of a triangle with vertices A, B, and C can be written as a weighted combinationP = λ₁·A + λ₂·B + λ₃·C, where the three weights always sum to 1. This calculator converts freely between Cartesian (x, y) coordinates and barycentric weights, and classifies whether a point falls inside, on the edge of, or outside the triangle.
The Conversion Formula
Given triangle vertices A(x₁, y₁), B(x₂, y₂), C(x₃, y₃) and a query point P(px, py), the calculator first computes the signed area denominator:
T = (y₂ − y₃)(x₁ − x₃) + (x₃ − x₂)(y₁ − y₃)
The barycentric weights are then:
λ₁ = [(y₂ − y₃)(px − x₃) + (x₃ − x₂)(py − y₃)] / T
λ₂ = [(y₃ − y₁)(px − x₃) + (x₁ − x₃)(py − y₃)] / T
λ₃ = 1 − λ₁ − λ₂
For the reverse operation — reconstructing a Cartesian point from known barycentric weights — the calculator applies the affine combination directly:
x = λ₁·x₁ + λ₂·x₂ + λ₃·x₃
y = λ₁·y₁ + λ₂·y₂ + λ₃·y₃
Classifying a Point's Location
The sign of each barycentric weight reveals exactly where the point sits relative to the triangle:
- Inside— all three weights are strictly positive (λ₁, λ₂, λ₃ > 0)
- On boundary — one weight is (approximately) zero and the other two are non-negative, meaning the point lies on an edge or exactly at a vertex
- Outside — at least one weight is negative
This makes barycentric coordinates one of the fastest and most numerically stable ways to perform point-in-triangle testing, widely used in rasterization and collision detection.
Worked Example
Consider triangle A(0, 0), B(4, 0), C(2, 3) with query point P(2, 1):
T = (0 − 3)(0 − 2) + (2 − 4)(0 − 3) = 6 + 6 = 12- λ₁ = [(0 − 3)(2 − 2) + (2 − 4)(1 − 3)] / 12 = 4 / 12 ≈ 0.3333
- λ₂ ≈ 0.3333
- λ₃ = 1 − 0.3333 − 0.3333 ≈ 0.3333
Since all three weights are equal and positive, P is exactly the centroid of the triangle — confirming the well-known result that the centroid always has barycentric coordinates (1/3, 1/3, 1/3).
Triangle Center Presets
The calculator includes one-click presets for four classic triangle centers:
- Centroid — always (1/3, 1/3, 1/3), the average of the three vertices
- Incenter — weights proportional to the opposite side lengths, a : b : c
- Circumcenter — weights proportional to sin(2A) : sin(2B) : sin(2C)
- Orthocenter — weights proportional to tan(A) : tan(B) : tan(C)
Degenerate Triangles
If the three vertices are collinear, the denominator T equals zero and barycentric coordinates are mathematically undefined. The calculator checks|T| < 1×10⁻¹⁰ and displays a clear warning instead of a misleading result whenever the triangle degenerates into a straight line.
Practical Applications
- Computer graphics — GPU rasterizers use barycentric weights to interpolate colors, texture coordinates, and normals smoothly across a triangle
- Finite element analysis — triangular mesh elements use barycentric (area) coordinates as shape functions for interpolating field values
- Computational geometry — fast, numerically robust point-in-triangle and point-in-mesh testing
- GIS and terrain modeling — elevation interpolation across triangulated irregular networks (TINs)
Adjustable Precision
All calculations use JavaScript's 64-bit double-precision floating-point arithmetic. You can control the number of displayed decimal places from 0 to 10 using the Decimal Precision field, which is useful for both quick estimates and high-precision engineering work.