POV-Ray : Newsgroups : povray.advanced-users : Intersection between two cicles Server Time
31 Oct 2024 21:22:28 EDT (-0400)
  Intersection between two cicles (Message 1 to 6 of 6)  
From: Thomas
Subject: Intersection between two cicles
Date: 5 Jul 2012 11:35:00
Message: <web.4ff5b32655ccbfc0236ebfb40@news.povray.org>
Hi,

For my animation (see animations groups, Lego ladder) I need to calculate the
intersection between two circles. Does anyone have have an example of this they
would like to share?

TIA
Thomas


Post a reply to this message

From: Samuel Benge
Subject: Re: Intersection between two cicles
Date: 6 Jul 2012 14:55:00
Message: <web.4ff734443bb301ee18d50c360@news.povray.org>
"Thomas" <tho### [at] gmxnet> wrote:
> Hi,
>
> For my animation (see animations groups, Lego ladder) I need to calculate the
> intersection between two circles. Does anyone have have an example of this they
> would like to share?
>

I already had some code for this laying around :) It uses calculations from this
page: http://2000clicks.com/mathhelp/GeometryConicSectionCircleIntersection.aspx

The circles are assumed to be laying along the X & Y axes and centered at Z=0.

// code //

#declare Pt1 = <-.7,0,0>;
#declare Rad1 = 1.5;

#declare Pt2 = <.75,0,0>;
#declare Rad2 = 1;

#declare D = vlength(Pt2-Pt1);
#declare K = .25*sqrt((pow(Rad1+Rad2,2)-D*D)*(D*D-pow(Rad1-Rad2,2)));

#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*(Pt2.y+Pt1.y) +
..5*(Pt2.y-Pt1.y)*(Rad1*Rad1-Rad2*Rad2)/(D*D) + 2*(Pt2.x-Pt1.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}
}

// end code //


Hope this helps!

Sam


Post a reply to this message

From: Samuel Benge
Subject: Re: Intersection between two cicles
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

From: Thomas
Subject: Re: Intersection between two cicles
Date: 8 Jul 2012 15:25:01
Message: <web.4ff9de0e3bb301ee13782c460@news.povray.org>
Thank you Samuel, this looks very good indeed. Over the weekend I ported the C
code mentioned here: http://paulbourke.net/geometry/2circle/ to a POV macro and
that does give me the same result. I might move to your way, was it is much more
POV like.

My first attempt at an animation is here:
http://legopov.blogspot.co.uk/

As mentioned, I am not sure the bottom part should move like that.

Thank you for your help,

Thomas


Post a reply to this message

From: Alain
Subject: Re: Intersection between two cicles
Date: 8 Jul 2012 16:40:08
Message: <4ff9f028$1@news.povray.org>

> Thank you Samuel, this looks very good indeed. Over the weekend I ported the C
> code mentioned here: http://paulbourke.net/geometry/2circle/ to a POV macro and
> that does give me the same result. I might move to your way, was it is much more
> POV like.
>
> My first attempt at an animation is here:
> http://legopov.blogspot.co.uk/
>
> As mentioned, I am not sure the bottom part should move like that.
>
> Thank you for your help,
>
> Thomas
>
>
All parts should always move at the same rate. After all, it's not an 
elastic.
Just adding another point on your spline under the bottom part, with the 
same separation as the previous ones, should do the trick.




Alain


Post a reply to this message

From: Thomas
Subject: Re: Intersection between two cicles
Date: 9 Jul 2012 15:55:03
Message: <web.4ffb36b53bb301ee13782c460@news.povray.org>
Alain <kua### [at] videotronca> wrote:

> > Thank you Samuel, this looks very good indeed. Over the weekend I ported the C
> > code mentioned here: http://paulbourke.net/geometry/2circle/ to a POV macro and
> > that does give me the same result. I might move to your way, was it is much more
> > POV like.
> >
> > My first attempt at an animation is here:
> > http://legopov.blogspot.co.uk/
> >
> > As mentioned, I am not sure the bottom part should move like that.
> >
> > Thank you for your help,
> >
> > Thomas
> >
> >
> All parts should always move at the same rate. After all, it's not an
> elastic.
> Just adding another point on your spline under the bottom part, with the
> same separation as the previous ones, should do the trick.
>
>
>
>
> Alain

posted new video in animations binary section and continuing discussion in
povray.animations (Lego Garage door)

Thanks,
Thomas


Post a reply to this message

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