POV-Ray : Newsgroups : povray.advanced-users : Intersection between two cicles : Re: Intersection between two cicles Server Time
26 Jun 2024 09:18:18 EDT (-0400)
  Re: Intersection between two cicles  
From: Samuel Benge
Date: 6 Jul 2012 15:05:01
Message: <web.4ff7366c3bb301ee18d50c360@news.povray.org>
"Samuel Benge" <stb### [at] hotmailcom> wrote:
>
> I already had some code for this laying around :)
>

Oops, the X & Y intersections were not in sync, and it wasn't handling
non-overlapping circles at all. Here's an improved version:

#declare Pt1 = <0.7, 0, 0>;
#declare Rad1 = 1.5;

#declare Pt2 = <-.5, 0.25, 0>;
#declare Rad2 = 1;

#declare D = vlength(Pt2-Pt1);
#declare T = (pow(Rad1+Rad2,2)-D*D)*(D*D-pow(Rad1-Rad2,2));

#if(T>0)

 #declare K = -.25*sqrt(T);

 #declare IntersectX = (.5*(Pt2.x+Pt1.x) +
..5*(Pt2.x-Pt1.x)*(Rad1*Rad1-Rad2*Rad2)/(D*D) + 2*(Pt2.y-Pt1.y)*K/(D*D));
 #declare IntersectY = (.5*(Pt1.y+Pt2.y) +
..5*(Pt1.y-Pt2.y)*(Rad2*Rad2-Rad1*Rad1)/(D*D) + 2*(Pt1.x-Pt2.x)*K/(D*D));

 // display circles
 union{
  torus{Rad1, 3/image_width rotate x*90 translate Pt1}
  torus{Rad2, 3/image_width rotate x*90 translate Pt2}
  pigment{rgb x}
 }

 // display intersection
 union{
  cylinder{
   -y*2, y*2, 3/image_width
   translate x*IntersectX
  }
  cylinder{
   -x*2, x*2, 3/image_width
   translate y*IntersectY
  }
  pigment{rgb x+y}
  finish{ambient 1 diffuse 0}
 }

#else

 #warning "warning: circles do not overlap"

#end


Post a reply to this message

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