|
![](/i/fill.gif) |
Here is the solution I came up with:
#macro LineIntersect(p1, d1, p2, d2)
#local pSep = p2-p1;
#local pdCross = vcross(d1,d2);
#local pdLen = vlength(pdCross);
#local lDist = vdot(pSep,pdCross);
#local dist = vdot(vcross(pSep,d2),pdCross)/(pdLen*pdLen);
#local pnt = p1+d1*dist;
pnt
#end
#macro icRad(p1, p2, p3) // Inscribed circle radius
#local ln1 = vlength(p2-p1);
#local ln2 = vlength(p3-p1);
#local ln3 = vlength(p3-p2);
#local hPer = (ln1+ln2+ln3)*0.5;
#local area = sqrt(hPer*(hPer-ln1)*(hPer-ln2)*(hPer-ln3));
#declare rad = area/hPer;
rad
#end
#macro icCen(p1, p2, p3) // Inscribed circle center
#local dr1 = vnormalize(p3-p2);
#local dr2 = vnormalize(p3-p1);
#local dr3 = vnormalize(p2-p1);
#local drb1 = vnormalize(-dr2-dr3); // Bisects angle through p1
#local drb2 = vnormalize(dr3-dr1); // Bisects angle through p2
#declare cen = LineIntersect(p1, drb1, p2, drb2);
cen
#end
#macro ccRad(p1, p2, p3) // Circumscribed circle radius
#local ln1 = vlength(p2-p1);
#local ln2 = vlength(p3-p1);
#local ln3 = vlength(p3-p2);
#local hPer = (ln1+ln2+ln3)*0.5;
#local area = sqrt(hPer*(hPer-ln1)*(hPer-ln2)*(hPer-ln3));
#declare rad = ln1*ln2*ln3*0.25/area;
rad
#end
#macro ccCen(p1, p2, p3) // Circumscribed circle center
#local pNrm = vnormalize(vcross(p2-p1,p3-p1)); // Unit triangle plane
normal
#local mp1 = (p2+p3)*.5; // Midpoint of line opposite p1
#local mp2 = (p1+p3)*.5; // Midpoint of line opposite p2
#local dr1 = vnormalize(vcross(p3-p2,pNrm)); // Perpincular to line opp.
p1
#local dr2 = vnormalize(vcross(p3-p1,pNrm)); // Perpincular to line opp.
p2
#declare cen = LineIntersect(mp1, dr1, mp2, dr2);
cen
#end
My approach was simply set up the appropriate lines (angle bisectors for
incenter, perpendicular bisectors for circumcenter) and calculate the
intersection. I found the solutions at MathWorld
(http://mathworld.wolfram.com/). This approach is highly extensible and can
be used to calculate many triangle centers.
If anyone has a simpler solution that works in three dimensions (sorry,
Sputnik, your formula is for two), let me know.
Post a reply to this message
|
![](/i/fill.gif) |