POV-Ray : Newsgroups : povray.general : Array Question Server Time
9 Aug 2024 19:36:57 EDT (-0400)
  Array Question (Message 1 to 10 of 12)  
Goto Latest 10 Messages Next 2 Messages >>>
From: Chris S 
Subject: Array Question
Date: 1 Jun 2000 21:56:02
Message: <39371432@news.povray.org>
I have a while loop which runs through numbers calculating a coordinate and
radius of a sphere.  What I'm trying to do is have these coordinates and
radii be entered into a sphere_sweep in order to serve as its sphere list.
I tried placing the while loop in the sphere_sweep code but received an
error message.  Is there any way to do this with an array?  I'm
inexperienced with arrays so any help would be appreciated.

Thanks, I only try bothering the group as a last resort:)

-Chris-


Post a reply to this message

From: David Fontaine
Subject: Re: Array Question
Date: 1 Jun 2000 23:50:03
Message: <39372DF5.AAB80A80@faricy.net>
"Chris S." wrote:

> I have a while loop which runs through numbers calculating a coordinate and
> radius of a sphere.  What I'm trying to do is have these coordinates and
> radii be entered into a sphere_sweep in order to serve as its sphere list.
> I tried placing the while loop in the sphere_sweep code but received an
> error message.  Is there any way to do this with an array?  I'm
> inexperienced with arrays so any help would be appreciated.
>
> Thanks, I only try bothering the group as a last resort:)

Hmm, that should work... What's the message? and check your syntax :-)

--
David Fontaine     <dav### [at] faricynet>     ICQ 55354965
Please visit my website: http://www.faricy.net/~davidf/


Post a reply to this message

From: Chris S 
Subject: Re: Array Question
Date: 2 Jun 2000 11:12:43
Message: <3937ceeb@news.povray.org>
error:  no matching } in sphere_sweep, < found instead

/////

#declare Rand01 = seed(34747);
#macro Tree_Root(X,Y,Z,R,L,Next)
    #declare counter=0;
    sphere_sweep {
      linear_sphere_sweep,
      10,
      #while(Next>0)
        <X,Y,Z>,R
        #declare R=R/1.05;
        #local X=X-rand(Rand01)*2;
        #local Y=Y-rand(Rand01);
        #local Z=Z-rand(Rand01)*2;
        #declare Next=Next-.1;
        #declare counter=counter+1;
     #end
    }
#end
union{
Tree_Root(0,0,0,2,1,1)
pigment{color rgb <1,0,0>}}

//////

-Chris-

David Fontaine <dav### [at] faricynet> wrote in message
news:39372DF5.AAB80A80@faricy.net...
> "Chris S." wrote:
>
> > I have a while loop which runs through numbers calculating a coordinate
and
> > radius of a sphere.  What I'm trying to do is have these coordinates and
> > radii be entered into a sphere_sweep in order to serve as its sphere
list.
> > I tried placing the while loop in the sphere_sweep code but received an
> > error message.  Is there any way to do this with an array?  I'm
> > inexperienced with arrays so any help would be appreciated.
> >
> > Thanks, I only try bothering the group as a last resort:)
>
> Hmm, that should work... What's the message? and check your syntax :-)
>
> --
> David Fontaine     <dav### [at] faricynet>     ICQ 55354965
> Please visit my website: http://www.faricy.net/~davidf/
>
>


Post a reply to this message

From: Gail Shaw
Subject: Re: Array Question
Date: 2 Jun 2000 15:14:23
Message: <3938078f@news.povray.org>
Chris S. wrote in message <3937ceeb@news.povray.org>...
>error:  no matching } in sphere_sweep, < found instead
>
>/////
>
>#declare Rand01 = seed(34747);
>#macro Tree_Root(X,Y,Z,R,L,Next)
>    #declare counter=0;
>    sphere_sweep {
>      linear_sphere_sweep,
>      10,
>      #while(Next>0)
>        <X,Y,Z>,R

You need a comma after R for each entry except the last.

Gail
********************************************************************
* gsh### [at] monotixcoza              * Reality.dat not found         *
* http://www.rucus.ru.ac.za/~gail/ * Attempting to reboot universe *
********************************************************************
* The best way to accelerate Windows NT is at 9.8 m/s^2      *
********************************************************************


Post a reply to this message

From: Margus Ramst
Subject: Re: Array Question
Date: 2 Jun 2000 15:28:41
Message: <3937FD1B.D6427D09@peak.edu.ee>
"Chris S." wrote:
> 
> error:  no matching } in sphere_sweep, < found instead
> 

It is a float precision problem (in decrementing of Next by 0.1). Because of it
your loop goes through 11 iterations instead of 10. It' will work fine if you
change Next to 10 and decrement it by 1 insted of 0.1
Note that this is not a bug; floating point math is just not infinitely precise,
and 0.1 is a problematic number, since it can't be presented accurately in
binary notation (just like 1/3 in decimal).

-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg


Post a reply to this message

From: Chris S 
Subject: Re: Array Question
Date: 2 Jun 2000 16:22:08
Message: <39381770@news.povray.org>
Wow, that was it.  Problem fixed, thanks.

-Chris-

Margus Ramst <mar### [at] peakeduee> wrote in message
news:3937FD1B.D6427D09@peak.edu.ee...
> "Chris S." wrote:
> >
> > error:  no matching } in sphere_sweep, < found instead
> >
>
> It is a float precision problem (in decrementing of Next by 0.1). Because
of it
> your loop goes through 11 iterations instead of 10. It' will work fine if
you
> change Next to 10 and decrement it by 1 insted of 0.1
> Note that this is not a bug; floating point math is just not infinitely
precise,
> and 0.1 is a problematic number, since it can't be presented accurately in
> binary notation (just like 1/3 in decimal).
>
> --
> Margus Ramst
>
> Personal e-mail: mar### [at] peakeduee
> TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg


Post a reply to this message

From: David Fontaine
Subject: Re: Array Question
Date: 2 Jun 2000 16:42:36
Message: <39381B41.50601093@faricy.net>
Gail Shaw wrote:

> You need a comma after R for each entry except the last.

An example taken from the help file:

sphere_sweep {
  b_spline_sphere_sweep, 4,
  <-5, -5, 0>, 1
  <-5, 5, 0>, 1
  < 5, -5, 0>, 1
  < 5, 5, 0>, 1
  sphere_sweep_depth_tolerance 1.0e-3
}

--
David Fontaine     <dav### [at] faricynet>     ICQ 55354965
Please visit my website: http://www.faricy.net/~davidf/


Post a reply to this message

From: David Fontaine
Subject: Re: Array Question
Date: 2 Jun 2000 16:44:13
Message: <39381BA1.B2E34F7A@faricy.net>
Margus Ramst wrote:

> It is a float precision problem (in decrementing of Next by 0.1). Because of it
> your loop goes through 11 iterations instead of 10. It' will work fine if you
> change Next to 10 and decrement it by 1 insted of 0.1
> Note that this is not a bug; floating point math is just not infinitely precise,
> and 0.1 is a problematic number, since it can't be presented accurately in
> binary notation (just like 1/3 in decimal).

Ah, I remember that crap... took me a while to figure it out when it happened to me.

It could happen to you, to. *points finger* ;-)

--
David Fontaine     <dav### [at] faricynet>     ICQ 55354965
Please visit my website: http://www.faricy.net/~davidf/


Post a reply to this message

From: Mike Williams
Subject: Re: Array Question
Date: 2 Jun 2000 16:48:43
Message: <4z$1BGAC1BO5EwZ6@econym.demon.co.uk>
Wasn't it Chris S. who wrote:
>error:  no matching } in sphere_sweep, < found instead
>
>/////
>
>#declare Rand01 = seed(34747);
>#macro Tree_Root(X,Y,Z,R,L,Next)
>    #declare counter=0;
>    sphere_sweep {
>      linear_sphere_sweep,
>      10,
>      #while(Next>0)
>        <X,Y,Z>,R
>        #declare R=R/1.05;
>        #local X=X-rand(Rand01)*2;
>        #local Y=Y-rand(Rand01);
>        #local Z=Z-rand(Rand01)*2;
>        #declare Next=Next-.1;
>        #declare counter=counter+1;
>     #end
>    }
>#end
>union{
>Tree_Root(0,0,0,2,1,1)
>pigment{color rgb <1,0,0>}}
>
>//////

It's a rounding error.

If you subtract .1 from 1 10 times you get a number that's not quite
exactly zero, because floating point arithmetic is never exact. So,
after the tenth iteration "Next" turns out to be very slightly greater
than zero, so "#while(Next>0)" is still true, and the eleventh iteration
produces the error.

Dirty fix:   #while(Next>0.01)

Clean fix: #while(counter<10)

This is a better fix because it will work even if you call the Tree_Root
macro with the sixth parameter not equal to 1.


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Warp
Subject: Re: Array Question
Date: 3 Jun 2000 08:14:10
Message: <3938f692@news.povray.org>
Mike Williams <mik### [at] nospamplease> wrote:
: If you subtract .1 from 1 10 times you get a number that's not quite
: exactly zero, because floating point arithmetic is never exact.
                                                     =====

  False. For some values floating point arithmetic is very exact.
  For example, 1.0+1.0 is exactly 2.0, no less, no more.

  However, for some other values it might not be. For example 0.1+0.1 may not
be exactly 0.2 (although 0.5+0.5 is exactly 1.0).

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

Goto Latest 10 Messages Next 2 Messages >>>

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