6
$\begingroup$

Having three distinct points as it is possible to obtain the height of the triangle ABC?

What is the distance between the point A to segment BC?

a = {4, 2, 1}; b = {1, 0, 1}; c = {1, 2, 0}; 
$\endgroup$
2
  • 1
    $\begingroup$ @MichaelE2 Does it make sense to close this as a duplicate of a later question, even if that question is more encompassing? $\endgroup$
    – Feyre
    Aug 31, 2016 at 9:30
  • $\begingroup$ @Feyre I guess it's up to the community. A foolish consistency...and all that. Of course, this one allows many silly variants, such as 2 Area@Triangle@{a, b, c}/RegionMeasure@Line@{b, c}. $\endgroup$
    – Michael E2
    Aug 31, 2016 at 10:36

4 Answers 4

8
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Two options very good $\endgroup$
    – LCarvalho
    Aug 26, 2016 at 17:32
  • $\begingroup$ Might want to use InfiniteLine instead of Line in general. $\endgroup$
    – Michael E2
    Aug 31, 2016 at 10:31
  • $\begingroup$ @MichaelE2 - thanks for pointing that out! $\endgroup$
    – Jason B.
    Sep 26, 2016 at 17:35
6
$\begingroup$

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 *)
$\endgroup$
5
$\begingroup$
BC = c - b; BA = a - c;

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

3.1305

$\endgroup$
0
4
$\begingroup$

Let's ask FormulaData. These should suffice (there are not that many anyways :( ):

Flatten@{FormulaData["TriangleAreaSSS"], FormulaData["TriangleAreaBH"]} // TeXForm

(I started looking for something involving heights: FormulaLookup["TriangleHeight"] gave {"TriangleAreaBH"} which I noted involved Areas which I didn't have yet, so I added "TriangleAreaSSS").

$$\left\{\text{s}=\frac{1}{2} (\text{a}+\text{b}+\text{c}),\text{A}=\sqrt{\text{s} (\text{s}-\text{a}) (\text{s}-\text{b}) (\text{s}-\text{c})},\text{A}=\frac{\text{b} \text{h}}{2}\right\}$$

a = {4, 2, 1}; b = {1, 0, 1}; c = {1, 2, 0};

quantityRename = QuantityVariable[n_, q_] :> Symbol[n <> q];
sides = {aLength -> Norm[b - a], 
   bLength -> Norm[c - b](*height is on b, aka BC, *b*ase*), 
   cLength -> Norm[a - c]};

hHeight /. (
   Solve[Flatten@{FormulaData["TriangleAreaSSS"], 
        FormulaData["TriangleAreaBH"]},
      {QuantityVariable["A","Area"], QuantityVariable["h","Height"], 
       QuantityVariable["s","Length"]}] /. quantityRename
    /. sides) // Simplify

{7/Sqrt[5]}

{3.1305}

It would be nice if there where a formula for the side-lengths given vertex coordinates. I had to get that in there manually.

It's also a bit unfortunate that your variables are called a, b, c like those in the formulas.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.