POV-Ray : Newsgroups : povray.general : Test for vector <0,0,0> : Re: Test for vector <0,0,0> Server Time
9 Aug 2024 01:19:32 EDT (-0400)
  Re: Test for vector <0,0,0>  
From: Rune
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

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