POV-Ray : Newsgroups : povray.general : Torus help! Server Time
31 Oct 2024 16:15:29 EDT (-0400)
  Torus help! (Message 1 to 3 of 3)  
From: Mike Horvath
Subject: Torus help!
Date: 9 Jan 2016 04:08:53
Message: <5690ce25$1@news.povray.org>
I have the following code which is supposed to generate a parabola and 5 
toroidal rings along the parabola's shape. However, only 3 of the 5 tori 
are showing up. For the life of me I cannot figure out why. Where did I 
make a mistake?

union
{
	#local p_scale = 256;
	#local wire_radius = 8;
	#local wire_color = color rgb x+y;
	#local x_old = 0;
	#local z_old = 0;
	#for (t_cnt, 0.1, 5, 0.1)
		#local x_new = p_scale/4 * t_cnt * 2;
		#local z_new = p_scale/4 * pow(t_cnt, 2);
		cylinder {<+x_old,0,z_old>, <+x_new,0,z_new>, wire_radius}
		cylinder {<-x_old,0,z_old>, <-x_new,0,z_new>, wire_radius}
		#if (mod(abs(t_cnt), 1) = 0)
			torus
			{
				x_new, wire_radius
				rotate +x * 90
				translate +z * z_new
			}
		#end
		#local x_old = x_new;
		#local z_old = z_new;
	#end
	pigment {wire_color}
}


Post a reply to this message

From: Jérôme M. Berger
Subject: Re: Torus help!
Date: 9 Jan 2016 05:57:54
Message: <5690e7b2$1@news.povray.org>
On 01/09/2016 10:09 AM, Mike Horvath wrote:
> I have the following code which is supposed to generate a parabola and 
5 
> toroidal rings along the parabola's shape. However, only 3 of the 5 tor
i 
> are showing up. For the life of me I cannot figure out why. Where did I
 
> make a mistake?
> 
> 		#if (mod(abs(t_cnt), 1) = 0)

	My bet would be floating point rounding errors and this line: due to
rounding errors, t_cnt will take values like 2.9999999999 or 3.000000001
which will cause the test to fail. Try to loop on integers (from 1 to
50) and use t_cnt/10 when computing coordinates.

		Jerome
-- 
mailto:jeb### [at] freefr
http://jeberger.free.fr
Jabber: jeb### [at] jabberfr


Post a reply to this message


Attachments:
Download 'us-ascii' (1 KB)

From: Mike Horvath
Subject: Re: Torus help!
Date: 9 Jan 2016 06:03:01
Message: <5690e8e5$1@news.povray.org>
On 1/9/2016 5:57 AM, Jérôme M. Berger wrote:
> On 01/09/2016 10:09 AM, Mike Horvath wrote:
>> I have the following code which is supposed to generate a parabola and 5
>> toroidal rings along the parabola's shape. However, only 3 of the 5 tori
>> are showing up. For the life of me I cannot figure out why. Where did I
>> make a mistake?
>>
>> 		#if (mod(abs(t_cnt), 1) = 0)
>
> 	My bet would be floating point rounding errors and this line: due to
> rounding errors, t_cnt will take values like 2.9999999999 or 3.000000001
> which will cause the test to fail. Try to loop on integers (from 1 to
> 50) and use t_cnt/10 when computing coordinates.
>
> 		Jerome
>

That's a good idea, thanks!


Mike


Post a reply to this message

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