[Date Index]
[Thread Index]
[Author Index]
Re: in center of a triangle
*To*: mathgroup at smc.vnet.net
*Subject*: [mg19626] Re: [mg19589] in center of a triangle
*From*: "David Park" <djmp at earthlink.net>
*Date*: Mon, 6 Sep 1999 04:20:42 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
>Hello!
>
>I was wondering if anyone has seen or has written a Mathematica procedure to
>generate the incenter of a triangle given the vertices of the triangle. The
>incenter of a triangle is the point at which the angle bisectors meet. From
>this point you can draw an inscribed circle in the triangle.
>
>Thanks for any help you could offer on this!!
>
>Tom De Vries
>Edmonton, Alberta, Canada
>
Hi Tom,
Here is a routine which will calculate the incenter and inradius for an inscribed
circle in a general triangle.
InscribedCircle[ptA:{_, _}, ptB:{_, _}, ptC:{_, _}] :=
Module[{AB, BC, AC, a, b, c, s, ptP, ptQ, AP, BQ, p, q, psol, qsol, pqsol,
center, radius}, AB = ptB - ptA; BC = ptC - ptB; AC = ptC - ptA;
a = Sqrt[BC . BC]; b = Sqrt[AC . AC]; c = Sqrt[AB . AB];
AP = ptB + p*BC - ptA; BQ = ptA + q*AC - ptB;
psol = Solve[AP . AB/c == AP . AC/b, p][[1,1]];
qsol = Solve[BQ . BC/a == BQ . (-AB)/c, q][[1,1]];
ptP = ptB + p*BC /. psol; ptQ = ptA + q*AC /. qsol;
pqsol = Solve[ptA + p*(ptP - ptA) == ptB + q*(ptQ - ptB), {p, q}][[1]];
center = ptA + p*(ptP - ptA) /. pqsol; s = (a + b + c)/2;
radius = Sqrt[((s - a)*(s - b)*(s - c))/s]; {center, radius}]
This tests it on randomly generated triangles.
<< Graphics`Colors`
ran := Random[Real, {0, 5}];
ptA = {ran, ran};
ptB = {ran, ran};
ptC = {ran, ran};
{incenter, inradius} = InscribedCircle[ptA, ptB, ptC];
Show[Graphics[
{AbsolutePointSize[4], Point /@ {ptA, ptB, ptC},
Blue, Line[{ptA, ptB, ptC, ptA}],
OrangeRed, Circle[incenter, inradius],
Black, Point[incenter]}],
AspectRatio -> Automatic, PlotRange -> All, Background -> Linen,
{Frame -> True, FrameLabel -> {x, y}}];
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
Prev by Date:
**Levenberg-Marquart code**
Next by Date:
**RE: Transparent plot color?**
Previous by thread:
**Re: in center of a triangle**
Next by thread:
**Re: in center of a triangle**
| |