POV-Ray : Newsgroups : povray.general : general geometry question : Re: general geometry question Server Time
7 Aug 2024 21:18:06 EDT (-0400)
  Re: general geometry question  
From: Tor Olav Kristensen
Date: 23 Aug 2001 22:14:26
Message: <3B85B85A.ABCC61CE@hotmail.com>
Hi Josh.

I like your idea to use the "Law of Sines".

So here is a macro I came up with after I
messed around for a while with a pen, paper
and a ruler:


#macro pCircleCenter(pA, pB, pC)

  #local vBA = vnormalize(pA - pB);
  #local vBC = vnormalize(pC - pB);
  #local CosABC = vdot(vBA, vBC);
  #local SinABC = vlength(vcross(vBA, vBC));
  #local vBAn = vnormalize(vBC - vBA*CosABC);
  #local vBCn = vnormalize(vBA - vBC*CosABC);

  ((pA + pB + vlength(vcross(pC - pA, vBCn))/SinABC*vBAn)/2)

#end // macro pCircleCenter


I haven't tested it much, so I don't know
if it has the same problem as you say that
your macro has.

I.e.: That the macro sometimes have to 
re-arrange the order of the points.


Tor Olav


Josh English wrote:
> 
> "Mark M. Wilson" wrote:
> 
> > I have a couple of questions, actually.  The second is dependent on the
> > first.
> > 1) It's been a LOOONNNNGGGGGG time since high school geometry, but it
> > seems to me it should be possible to scribe a circle given any three
> > (coplanar) points.  Am I right?
> >
> > 2) if the premise in #1 is correct, does anyone know of any macros for
> > Povray that will calculate the coordinates of  the center of such a
> > circle?
> >
> > TIA,
> > Mark M. Wilson
> 
> Here is a macro I created using the Law of Sines.
> 
> #macro Center(a,b,c)
>   #local d = (a+b)/2;
>   #local e = (b+c)/2;
>   #local v0 = vnormalize(vcross((b-c),(b-a)));
>   #local v1 = vnormalize(vcross(d-b,v0));
>   #local v2 = vnormalize(vcross(v0,e-b));
>   #local a1 = (acos(vdot(d-e,v2)/vlength(d-e)*vlength(v2)));
>   #local a2 = (acos(vdot(e-d,v1)/vlength(e-d)*vlength(v1)));
>   #local a3 = pi-a1-a2;
>   #local l = (sin(a1)/sin(a3))*vlength(e-d);
>   #local f = d + vnormalize(v1)*l;
>   #local t1 = vlength(f-a);
>   #local t2 = vlength(f-b);
>   #local t3 = vlength(f-c);
>   #if ((t1!=t2)|(t2!=t3)|(t1!=t3))
>     #render "help"
>     #local f =Center(a,c,b);
>   #end
>   f
> #end
> 
> The only problem with it is that I have to check that the point it finds
> is equidistant to all three points. I think it has to do with the
> orientation of the points, since the correction only requires a reversal
> of orientation to fix the problem.


Post a reply to this message

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