How this calculation works
The closest point on a triangle can lie in its face interior, on an edge or at a vertex. Projecting only onto the triangle’s infinite plane is insufficient when that projection lies outside the triangular boundary. This calculator tests a feasible face projection and all three closed edge segments, then chooses the candidate with the smallest Euclidean distance. It returns the closest coordinates, region label and barycentric weights relative to A, B and C.
Minimize |P−(λA A+λB B+λC C)| with λA+λB+λC=1 and all λ≥0.A worked example
For triangle A=(0,0,0), B=(2,0,0), C=(0,2,0), point P=(0.5,0.5,3) projects to (0.5,0.5,0). Its barycentric weights are (0.5,0.25,0.25), all nonnegative, so the closest point is on the face and the distance is three. For P=(1,−2,0), the plane distance is zero but the closest triangle point is (1,0,0) on AB, at distance two.
Good to know
Triangle vertices must define a nondegenerate, numerically well-resolved triangle. Coincident or nearly collinear configurations are rejected rather than silently replaced by a segment. All Cartesian coordinates are finite and within ±10⁹. The distance is unsigned. Region labels near shared boundaries may depend on floating comparison; the closest coordinates and distance are the primary outputs. No closed-surface inside/outside conclusion is inferred from one face.
Reference: David Eberly, Geometric Tools — distance between a point and triangle in 3D (opens in a new tab) ↗
Barycentric feasibility decides whether the plane projection belongs to the face
Barycentric weights sum to one and reconstruct the candidate point from the three vertices. Negative weights indicate that a plane point lies beyond a triangle boundary, so it cannot be retained as an interior-face solution. In the default example the projection has weights one half, one quarter and one quarter, which place it safely inside. Their interpretation is geometric and does not require the triangle to be aligned with a coordinate plane.
Each edge contributes its own closest point after the edge parameter is clamped to the closed interval from zero to one. Clamping naturally includes endpoints, so vertex candidates are not lost. Comparing all feasible candidates covers the whole triangle, including its boundary. The same point may have more than one equally descriptive region label when it lies exactly on a face-edge or edge-vertex transition.
The Parametric line sphere intersection calculator also uses three-dimensional coordinates but finds surface crossings rather than the shortest point on a triangular face.
Zero distance to a plane does not imply zero distance to its triangle
An observation can lie in the triangle’s plane but far outside its edges. Its perpendicular plane distance is then zero, while its distance to the triangular surface is positive. The second worked configuration shows this directly. A point-to-plane calculator therefore cannot replace this constrained minimization. Likewise, point-to-line distance does not enforce the endpoints of a finite triangle edge.
A triangle with very small area relative to its edge lengths makes face coordinates numerically ill-conditioned. Rejecting that input is more informative than returning unstable barycentric weights with a false precision claim. If the intended object is genuinely a segment, use an appropriate segment-distance method. For a mesh, this page can analyze one face, but finding the global closest point requires considering all relevant faces or a validated spatial-search structure.
A few questions, answered
Is the distance negative on one side of the triangle?
No. Euclidean distance is nonnegative. A signed distance needs a separately specified orientation and surface interpretation.
Can vertex order change the closest point?
Permuting valid vertices describes the same geometric triangle. It changes barycentric labels and possibly a boundary-region label, while the geometric distance remains the same within numerical precision.