POV-Ray : Newsgroups : povray.general : Help with "programmatically" determining intersection : Re: Help with "programmatically" determining intersection Server Time
3 May 2024 03:07:54 EDT (-0400)
  Re: Help with "programmatically" determining intersection  
From: Le Forgeron
Date: 17 Mar 2016 03:07:17
Message: <56ea57a5$1@news.povray.org>
Le 17/03/2016 04:07, Bald Eagle a écrit :
> #declare Z1 = Base * (sin(theta) - theta*cos(theta));
> #declare Z2 = -Base * (sin(theta) - theta*cos(theta));

you are trying to solve Z1 = Z2, i.e. Z1-Z2 = 0

Base * (sin(theta) - theta*cos(theta)) + Base * (sin(theta) - 
theta*cos(theta)) = 0

2 * Base * (sin(theta) - theta*cos(theta)) = 0

Base is constant, not interesting.

Remains (sin(theta) - theta*cos(theta)) = 0

sin(theta) = theta*cos(theta)

Obvious (as in math) first solution is theta = 0.

Then you can use the Internet

http://www.wolframalpha.com/input/?i=sin+x+-+x+cos+x+%3D+0

x ~~ -14.0661939128315...

x ~~ ±10.9041216594289...

x ~~ ±7.72525183693771...

x ~~ ±4.49340945790906...

x = 0

At least 8 intersections, but only one if you restrict yourself to -pi , 
+pi.

Back to your original problem: you should detect the change of sign of 
Z1-Z2, not its small absolute value. You need a memory of the sign at 
the previous point, and compare with the new sign for the new point.

And possibly handling a 3 states sign: <0, ==0, >0

You crossed the intersection when going from <0 to >0 or vice-versa
You found the intersection when new sign == 0


Post a reply to this message

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