|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
I see many people use
#if ( Vector.x=0 & Vector.y=0 & Vector.z=0 )
and
#if ( Vector.x!=0 & Vector.y!=0 & Vector.z!=0 )
I personally find it much simpler to use
#if (vlength(Vector)=0)
and
#if (vlength(Vector)!=0)
I just thought I'd share it with you.
Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated July 23)
/ Also visit http://www.povrayusers.org
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Rune wrote:
>
> I see many people use
>
> #if ( Vector.x=0 & Vector.y=0 & Vector.z=0 )
> and
> #if ( Vector.x!=0 & Vector.y!=0 & Vector.z!=0 )
>
> I personally find it much simpler to use
>
> #if (vlength(Vector)=0)
> and
> #if (vlength(Vector)!=0)
>
> I just thought I'd share it with you.
>
> Rune
If you consider speed optimization, how about:
#if ( abs(Vector.x)+abs(Vector.y)+abs(Vector.z)=0 )
I don't know how fast povray calculates vlength(), but in regular programming
this would probably be faster, because vlength() would have to use
multiplication and sqrt().
Christoph
--
Christoph Hormann <chr### [at] gmxde>
Homepage: http://www.schunter.etc.tu-bs.de/~chris/
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Christoph Hormann" wrote:
> If you consider speed optimization, how about:
>
> #if ( abs(Vector.x)+abs(Vector.y)+abs(Vector.z)=0 )
>
> I don't know how fast povray calculates vlength(), but in regular
programming
> this would probably be faster, because vlength() would have to use
> multiplication and sqrt().
I was not thinking about speed, only what was easier to type.
But I made a speed test, and surprisingly it showed that using vlength()
is quicker than both of the two other methods! At least on my computer...
// Speed test
#declare C = 0;
#declare S = seed(0);
#while (C<100000)
#declare V = <rand(S),rand(S),rand(S)>*4-2;
// #if (V.x=0&V.y=0&V.z=0) #declare D = 0; #end // 119 seconds
// #if (abs(V.x)+abs(V.y)+abs(V.z)=0) #declare D = 0; #end // 121 seconds
#if (vlength(V)=0) #declare D = 0; #end // 113 seconds
#declare C = C+1;
#end
sphere {-z, 0.1 pigment {color 0}}
Greetings,
Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated July 23)
/ Also visit http://www.povrayusers.org
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Christoph Hormann wrote:
> Rune wrote:
> >
> > I see many people use
> >
> > #if ( Vector.x=0 & Vector.y=0 & Vector.z=0 )
> > and
> > #if ( Vector.x!=0 & Vector.y!=0 & Vector.z!=0 )
> >
> > I personally find it much simpler to use
> >
> > #if (vlength(Vector)=0)
> > and
> > #if (vlength(Vector)!=0)
> >
> > I just thought I'd share it with you.
> >
> > Rune
>
> If you consider speed optimization, how about:
>
> #if ( abs(Vector.x)+abs(Vector.y)+abs(Vector.z)=0 )
>
Maybe I'm missing something here, but this isn't going to work. All you're doing
is adding up the vector components. Yes, it will be true for the zero vector,
but it will also be true for vectors like <2, -2, 0> and <3, 2, -5>, etc.
>
> I don't know how fast povray calculates vlength(), but in regular programming
> this would probably be faster, because vlength() would have to use
> multiplication and sqrt().
>
> Christoph
>
> --
> Christoph Hormann <chr### [at] gmxde>
> Homepage: http://www.schunter.etc.tu-bs.de/~chris/
Kevin Jackson-Mead
http://www.mindspring.com/~jacksonmead
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> But I made a speed test, and surprisingly it showed that using vlength()
> is quicker than both of the two other methods! At least on my computer...
quicker parse?
Rick
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Kevin Jackson-Mead wrote:
> Christoph Hormann wrote:
>
> > Rune wrote:
> > >
> > > I see many people use
> > >
> > > #if ( Vector.x=0 & Vector.y=0 & Vector.z=0 )
> > > and
> > > #if ( Vector.x!=0 & Vector.y!=0 & Vector.z!=0 )
> > >
> > > I personally find it much simpler to use
> > >
> > > #if (vlength(Vector)=0)
> > > and
> > > #if (vlength(Vector)!=0)
> > >
> > > I just thought I'd share it with you.
> > >
> > > Rune
> >
> > If you consider speed optimization, how about:
> >
> > #if ( abs(Vector.x)+abs(Vector.y)+abs(Vector.z)=0 )
> >
>
> Maybe I'm missing something here, but this isn't going to work. All you're doing
> is adding up the vector components. Yes, it will be true for the zero vector,
> but it will also be true for vectors like <2, -2, 0> and <3, 2, -5>, etc.
Almost, but....
As you can see, he used the abs, so those vectors you mentioned would turn into <2,
2, 0> and <3, 2, 5>, which would still pass his test.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
In article <39B10CF1.42249F5C@mindspring.com>, Kevin Jackson-Mead
<jac### [at] mindspringcom> wrote:
> Maybe I'm missing something here, but this isn't going to work. All
> you're doing is adding up the vector components. Yes, it will be
> true for the zero vector, but it will also be true for vectors like
> <2, -2, 0> and <3, 2, -5>, etc.
Wrong. The vector < 2,-2, 0> will add up to 4, and < 3, 2,-5> will add
up to 10. That is what the abs() function is for, it gets the absolute
value of the number.
--
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/
<><
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
I knew I was missing something. That's what I get for trying to post on a
Saturday morning. Man I feel like such a tool.
Kevin Jackson-Mead
http://www.mindspring.com/~jacksonmead
Chris Huff wrote:
> In article <39B10CF1.42249F5C@mindspring.com>, Kevin Jackson-Mead
> <jac### [at] mindspringcom> wrote:
>
> > Maybe I'm missing something here, but this isn't going to work. All
> > you're doing is adding up the vector components. Yes, it will be
> > true for the zero vector, but it will also be true for vectors like
> > <2, -2, 0> and <3, 2, -5>, etc.
>
> Wrong. The vector < 2,-2, 0> will add up to 4, and < 3, 2,-5> will add
> up to 10. That is what the abs() function is for, it gets the absolute
> value of the number.
>
> --
> Christopher James Huff
> Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
> TAG: chr### [at] tagpovrayorg, http://tag.povray.org/
>
> <><
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
In article <39b0fb77@news.povray.org>, "Rune" <run### [at] inamecom>
wrote:
> I was not thinking about speed, only what was easier to type.
You could just make a vNull() macro to make it even easier to type, and
more obvious exactly what you are doing.
> But I made a speed test, and surprisingly it showed that using vlength()
> is quicker than both of the two other methods! At least on my computer...
Though vlength() does 3 squares and a sqrt(), it does them internally,
in native C. Using the comparison method, each comparison has to be
parsed separately, which is slower.
--
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/
<><
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|