How to get the height of a triangle from three points

You could use RegionDistance,

a = {4, 2, 1}; b = {1, 0, 1}; c = {1, 2, 0};
RegionDistance[InfiniteLine[{b, c}], a]
N@%
(* 7/Sqrt[5] *)
(* 3.1305 *)

edit: Using InfiniteLine instead of Line, because for obtuse triangles the altitude from point $a$ will not intersect with the line segment $\overline{bc}$.

Or you could work out the trig equations yourself, and use VectorAngle to arrive at

Norm[b-a] Sin[VectorAngle[b-c, b-a]]

which gives the same answer.


Just for fun, other answers being more practical, you can use Heron's formula https://en.wikipedia.org/wiki/Heron%27s_formula

fn[a_, b_, c_] := Module[{area, ab, bc, ca, s},
  ab = Norm[a - b];
  bc = Norm[b - c];
  ca = Norm[c - a];
  s = (ab + bc + ca)/2;
  area = Sqrt[s (s - ab) (s - bc) (s - ca)];
  2 area/bc]
With[{a = {4, 2, 1}, b = {1, 0, 1}, c = {1, 2, 0}},
  fn[a, b, c]] // FullSimplify
% // N
(* 7/Sqrt[5] *)
(* 3.1305 *)

BC = c - b; BA = a - c;

h = N[Norm[Cross[BC, BA]]/Norm[BC]]

3.1305

Tags:

Geometry