POV-Ray : Newsgroups : povray.general : Test for vector <0,0,0> Server Time
1 Nov 2024 06:17:14 EDT (-0400)
  Test for vector <0,0,0> (Message 1 to 9 of 9)  
From: Rune
Subject: Test for vector <0,0,0>
Date: 2 Sep 2000 08:23:57
Message: <39b0f15d@news.povray.org>
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

From: Christoph Hormann
Subject: Re: Test for vector <0,0,0>
Date: 2 Sep 2000 08:40:13
Message: <39B0F580.685093C0@schunter.etc.tu-bs.de>
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

From: Rune
Subject: Re: Test for vector <0,0,0>
Date: 2 Sep 2000 09:07:03
Message: <39b0fb77@news.povray.org>
"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

From: Kevin Jackson-Mead
Subject: Re: Test for vector <0,0,0>
Date: 2 Sep 2000 10:23:40
Message: <39B10CF1.42249F5C@mindspring.com>
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

From: Rick [Kitty5]
Subject: Re: Test for vector <0,0,0>
Date: 2 Sep 2000 10:27:20
Message: <39b10e48@news.povray.org>
> 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

From: Jon A  Cruz
Subject: Re: Test for vector <0,0,0>
Date: 2 Sep 2000 10:30:25
Message: <39B10F99.5D686CA6@geocities.com>
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

From: Chris Huff
Subject: Re: Test for vector <0,0,0>
Date: 2 Sep 2000 10:35:33
Message: <chrishuff-A3FA04.09371002092000@news.povray.org>
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

From: Kevin Jackson-Mead
Subject: Re: Test for vector <0,0,0>
Date: 2 Sep 2000 10:37:50
Message: <39B11043.1CA96F3B@mindspring.com>
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

From: Chris Huff
Subject: Re: Test for vector <0,0,0>
Date: 2 Sep 2000 11:53:50
Message: <chrishuff-C64FE6.10552802092000@news.povray.org>
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

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