POV-Ray : Newsgroups : povray.general : Blender Vs PovRay Server Time
21 Feb 2025 13:19:28 EST (-0500)
  Blender Vs PovRay (Message 25 to 34 of 44)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Nicolas Alvarez
Subject: Re: Blender Vs PovRay
Date: 24 Oct 2008 22:29:52
Message: <490284a0@news.povray.org>
Nicolas Alvarez wrote:
> The problem with doing #declare V=V+1/100; is that it might not reach
> 1.0000 exactly at the end of the loop (because of floating point
> inaccuracies), so it might run one time too many.

Or even if it runs runs the correct number of times, it may have slightly
off values. And errors would *accumulate*.

Tested in Python:
>>> x = 0;
>>> for i in range(0,100):
...     x += 1.0/100;
... 
>>> print x;
1.0000000000000007
>>>


Post a reply to this message

From: stbenge
Subject: Re: Blender Vs PovRay
Date: 25 Oct 2008 00:13:41
Message: <49029cf5@news.povray.org>
Nicolas Alvarez wrote:
> Nicolas Alvarez wrote:
>> The problem with doing #declare V=V+1/100; is that it might not reach
>> 1.0000 exactly at the end of the loop (because of floating point
>> inaccuracies), so it might run one time too many.
> 
> Or even if it runs runs the correct number of times, it may have slightly
> off values. And errors would *accumulate*.
>
> Tested in Python:
>>>> x = 0;
>>>> for i in range(0,100):
> ...     x += 1.0/100;
> ... 
>>>> print x;
> 1.0000000000000007

I see what you mean. I've never encountered any unwanted effects from 
using fractional number-dependent loops, but it's a good thing to keep 
in mind. Errors at the 16th decimal place are acceptable for most of the 
things I do, but there will probably come a time when your input saves 
me from beating my head against a hard surface :)

Sam


Post a reply to this message

From: Dan Connelly
Subject: Re: Blender Vs PovRay
Date: 25 Oct 2008 10:14:36
Message: <490329cc$1@news.povray.org>
Nicolas Alvarez wrote:
> The problem with doing #declare V=V+1/100; is that it might not reach 1.0000
> exactly at the end of the loop (because of floating point inaccuracies), so
> it might run one time too many.
> 

Right. If you MUST use floats, more robust is this sort of thing:

#local xmin = ....;
#local xmax = ....;
#local dx = .....;

#local x = xmin;
#while (x < xmax + dx / 2)
   #local x = x + dx;
#end


Post a reply to this message

From: Nicolas George
Subject: Re: Blender Vs PovRay
Date: 25 Oct 2008 14:41:52
Message: <49036870$1@news.povray.org>
stbenge  wrote in message <49027f8c@news.povray.org>:
>								 but since 
> POV-Ray treats all variables as floats, I can't see how it could harm 
> things.

You mean, instead of using an integer counter? There is a big difference:
with most architectures, floats can represent reasonably-small integers in
an exact manner. On the other hand, 1/100 is not an exact float; 1/64 and
1/128 would have been, but not 1/100.

So the point that PoV internally uses floats is not valid: there are more
robust ways to use floats than others, and using an integer counter for
looks is one.


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Blender Vs PovRay
Date: 25 Oct 2008 14:46:55
Message: <4903699f@news.povray.org>
stbenge wrote:
> I see what you mean. I've never encountered any unwanted effects from
> using fractional number-dependent loops, but it's a good thing to keep
> in mind. Errors at the 16th decimal place are acceptable for most of the
> things I do, but there will probably come a time when your input saves
> me from beating my head against a hard surface :)

It's mainly relevant if you loop thousands of times. With 100 iterations
it's not a big problem :)


Post a reply to this message

From: Nicolas George
Subject: Re: Blender Vs PovRay
Date: 26 Oct 2008 08:45:52
Message: <49046680$1@news.povray.org>
Nicolas Alvarez  wrote in message <4903699f@news.povray.org>:
> It's mainly relevant if you loop thousands of times. With 100 iterations
> it's not a big problem :)

Quite the contrary, with this code, there may be problems even for a very
small number of iterations.

For example, consider the following code:

#local n = 10;
#local t = 0;
#while(t < 1)
  #local t = t + 1/n;
#end

and the same with n = 11. It happens that the float value for 1/10 is
slightly smaller than the exact value 1/10, while the float value for 1/11
is slightly greater than the exact value for 1/11. The result is that both
loops make 11 iterations.

This issue can be fixed by using a float-friendly bound, as suggested
earlier by someone: t < 1 + dt / 2 or t < 1 - dt / 2, depending on whether
the loop is supposed to be inclusive or not.


Post a reply to this message

From: Dan Connelly
Subject: Re: Blender Vs PovRay
Date: 26 Oct 2008 13:52:55
Message: <4904ae77@news.povray.org>
Nicolas George wrote:
> For example, consider the following code:
> 
> #local n = 10;
> #local t = 0;
> #while(t < 1)
>   #local t = t + 1/n;
> #end
> 

Well, t's a a reserved identifier, but otherwise....

If you change it count from 0 to "< 10" in increments of 1 (ie in integers), it's
fine.

Dan


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Blender Vs PovRay
Date: 26 Oct 2008 14:02:09
Message: <4904b0a1@news.povray.org>
Dan Connelly wrote:
> If you change it count from 0 to "< 10" in increments of 1 (ie in
> integers), it's fine.

Yes, that's exactly the point. Use integers instead of floats.


Post a reply to this message

From: Janet
Subject: Re: Blender Vs PovRay
Date: 28 Oct 2008 20:50:00
Message: <web.4907b2b2320575a46670cae90@news.povray.org>
stbenge <THI### [at] hotmailcom> wrote:
> #declare native_motif=
> pigment{
>   gradient y triangle_wave
>   #declare V=0;
>   #while(V<1)
>    translate y*.75
>    rotate z*45.2
>    //rotate -z*45.1
>    scale .98
>    warp{repeat x*5 flip x}
>    #declare V=V+1/100;
>   #end
>   scale .1
> }


I just want to say this is so much fun to play around with. Thanks for sharing
it.

Janet


Post a reply to this message

From: Stephen
Subject: Re: Blender Vs PovRay
Date: 29 Oct 2008 08:10:00
Message: <web.490851d4320575a4208d05c80@news.povray.org>
"Janet" <par### [at] attnet> wrote:

>
> I just want to say this is so much fun to play around with. Thanks for sharing
> it.
>

My mother would have given her eye teeth for a pattern generator like this. I
can see her using it for Fair Isle jumpers.

Stephen


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

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