POV-Ray : Newsgroups : povray.general : general geometry question : Re: general geometry question Server Time
7 Aug 2024 15:12:39 EDT (-0400)
  Re: general geometry question  
From: Ron Parker
Date: 21 Aug 2001 17:18:37
Message: <slrn9o5k1f.i1c.ron.parker@fwi.com>
On Tue, 21 Aug 2001 17:03:15 -0400, Mark M. Wilson wrote:
>Maybe what I SHOULD have asked is, how to do the raw math myself to
>figure out where to place the center of whatever torus or circle I
>decide to place in my scene...  That would be, how to find the vector
>for the ONE point which is equidistant from all three points.

Well, that's exactly what you have in the sequence of assignments I 
gave you; it's not actually a macro, it's just the math.

The truth is that there are really an infinite number of points that 
are equidistant from all three points.  The code I gave you computes
the one that happens to lie in the same plane.  Essentially, what it 
does is what you'd do with a compass and straightedge: draw the line 
segment from A to B and the line segment from B to C, construct the
perpendicular bisector of each segment, and the center is where the 
two perpendicular bisectors cross.  It's made somewhat more ugly by 
the fact that I did a basis transform to make the third step (finding
the intersection of the two bisectors) easier mathematically, but 
that's the basic idea.  I've tried to explain some of the math below.

(The rest of the points that are equidistant are of the form 
Center + m * Axis, for real values of m.  In other words, the axis of 
the uniquely-determined cylinder that all three points lie on.)

>>           #local Axis=vnormalize(vcross((C-A),(B-A)));

Axis is the direction of the line that is equidistant from all three
points.  We don't know its position in space yet, but we know which
direction it points.  It's also the third basis vector, but we don't
care about that so much.

>>           #local Base1=vnormalize(C-A);
>>           #local Base2=vnormalize(vcross(Axis,Base1));
>>           #local VB=<0.5*vlength(C-A),0,0>;
>>           #local VA=vcross(VB,z);
>>           #local VD=.5*<vdot(B-A,Base1),vdot(B-A,Base2),0>;
>>           #local VC=vcross(VD,z);

This is the basis transform and construction of perpendicular bisectors
rolled into one.  VA and VC are the bisectors, and VB and VD are their
offsets from point A (which is the origin in the alternate basis.)  They 
aren't much use, though, because the basis for these vectors is not x,y,z 
as with "normal" vectors.  In fact, note that the z component of all four 
vectors is zero.  That's why I chose this basis: it makes the next line a 
lot easier.

>>           #local Beta=((VD-VB).y*VA.x-(VD-VB).x*VA.y)/(VC.x*VA.y-VC.y*VA.x);

Beta is just an intermediate value.  It has physical significance, in that
it is the distance to the center along VC from the center to the line from
A to B (and also, of course, the distance along VA from the center to the
line from A to C) but it didn't really need to be separated out, except
to make the next line easier to read.  The mess above is just the solution
of two equations (the equations of the two bisectors) in two unknowns (the 
center of the circle in my alternate basis; z is known because it's zero.
Setting z to something besides zero would give you one of the other points
that's equidistant from all three points, conceptually, except that the
z component is ignored in the next line.)

>>           #local Center=A+VD.x*Base1+VD.y*Base2+Beta*(VC.x*Base1+VC.y*Base2);

In my alternate basis, the center is just VD+Beta*VC.  This line incorporates
that with the inverse basis transform to get back into x,y,z space.

>>           #local Radius=vlength(Center-A);

This line should be pretty obvious: if the center really is the center, then
the radius is the distance from the center to one of the points.  I picked
A because it's first.  I could have used B or C instead.

-- 
plane{-z,-3normal{crackle scale.2#local a=5;#while(a)warp{repeat x flip x}rotate
z*60#local a=a-1;#end translate-9*x}pigment{rgb 1}}light_source{-9red 1rotate 60
*z}light_source{-9rgb y rotate-z*60}light_source{9-z*18rgb z}text{ttf"arial.ttf"
"RP".01,0translate-<.6,.4,.02>pigment{bozo}}light_source{-z*3rgb-.2}//Ron Parker


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.