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};
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityYou 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.
InfiniteLine
instead of Line
in general.
$\endgroup$
Aug 31, 2016 at 10:31
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
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.
2 Area@Triangle@{a, b, c}/RegionMeasure@Line@{b, c}
. $\endgroup$