POV-Ray : Newsgroups : povray.general : general geometry question : Re: general geometry question Server Time
7 Aug 2024 21:23:36 EDT (-0400)
  Re: general geometry question  
From: Tor Olav Kristensen
Date: 21 Aug 2001 19:45:04
Message: <3B82F267.36412849@hotmail.com>
"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?

Hello Mark

I had to go and dig up some of my old 
macros to solve this problem of yours.

The code below solves it.

It draws a circle through any 3 points
in 3D-space that are not co-linear.

(Not very much coding is really needed
to find the coordinates for the center
of the circle, the radius and the normal
vector for the plane that the circle lies
in. But I have added some code to 
visualize it all.) 

The code also shows how to make a sphere
touch any 4 points in 3D-space that are
not co-planar (Hmmm... I wonder if it's
correct to say that about points.)

Have fun !


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// Copyright 2001 by Tor Olav Kristensen
// http://www.crosswinds.net/~tok
// http://hjem.sol.no/t-o-k
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

// How to make a circle touch 3 points in 3D-space.

#version 3.1;

#include "colors.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// Macros to do the dirty work

// Returns the point that lies in all the 3 planes.
#macro pl2pl2pl(pPlane1, vPlane1, pPlane2, vPlane2, pPlane3, vPlane3)

  ((vdot(pPlane1, vPlane1)*vcross(vPlane2, vPlane3) +
    vdot(pPlane2, vPlane2)*vcross(vPlane3, vPlane1) +
    vdot(pPlane3, vPlane3)*vcross(vPlane1, vPlane2))/
    vdot(vPlane1, vcross(vPlane2, vPlane3)))

#end // macro pl2pl2pl


#macro CircleTouches3Points(p1, p2, p3, pCenter, Radius, vPlane)

  #local v12 = p2 - p1;
  #local v13 = p3 - p1;

  #declare vPlane = vnormalize(vcross(v13, v12));
  #declare pCenter = pl2pl2pl(
                       p1 + p1, vPlane,
                       p1 + p2, v12,
                       p1 + p3, v13
                     )/2;

  #declare Radius = vlength(p1 - pCenter);

#end // macro CircleTouches3Points

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// Define problem

#declare pA = <1, 2, 3>;
#declare pB = <-2, 0, -1>;
#declare pC = <1, -3, 3>;

sphere { pA, 0.2 pigment { color Red*2 } }
sphere { pB, 0.2 pigment { color Green*2 } }
sphere { pC, 0.2 pigment { color Magenta*2 } }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// Solve problem

#declare pCtr = <0, 0, 0>;
#declare R = 0;
#declare vPl = <0, 0, 0>; 
 
CircleTouches3Points(pA, pB, pC, pCtr, R, vPl)

difference {
  cylinder { -0.05*vPl, 0.05*vPl, R + 0.04 }
  cylinder { -0.06*vPl, 0.06*vPl, R - 0.04 }
  translate pCtr
  pigment { color rgb <0, 1, 1> } 
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

background { color Blue/2 }

light_source { 100*<1, 1, -1> color White }

camera {
  location pCtr + 8*vPl
  look_at pCtr
}

/*
// Uncomment region below to see how to make a sphere touch 4 points.
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// Another slave

#macro SphereTouches4Points(p0, p1, p2, p3, pCenter, Radius)

  #declare pCenter = pl2pl2pl(
                    p0 + p1, p1 - p0,
                    p0 + p2, p2 - p0,
                    p0 + p3, p3 - p0
                  )/2;
  #declare Radius = vlength(p0 - pCenter);

#end // macro SphereTouches4Points

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// Extend problem

#declare pD = <1, 0, 1>;

sphere { pD, 0.2 pigment { color Blue*2 } }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// And solve that too

#declare pCtr = <0, 0, 0>;
#declare R = 0;

SphereTouches4Points(pA, pB, pC, pD, pCtr, R)

sphere { pCtr, R pigment { color White } }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

camera {
  location <2, 2, -3>*3
  look_at <0, 1, 0>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
*/


Post a reply to this message

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