POV-Ray : Newsgroups : povray.general : Vector comparison Server Time
25 Nov 2024 21:24:10 EST (-0500)
  Vector comparison (Message 1 to 9 of 9)  
From: Albun
Subject: Vector comparison
Date: 27 Dec 2012 13:30:01
Message: <web.50dc9273db110770f192a6e30@news.povray.org>
Well, i try to change color with  vector's comparison. Subtraction , or equal
can't give a result to change color.
And  substraction (Pos_-Pos_compare) can't be recognize. I want to change color
when the two vectors are the same, in substraction equal to 0 ,=0.
I use trace() for one vector.

////

#declare PointA = VEq(Pos_,Pos_compare);


sphere{Pos_,.25
 #if (0=PointA)
 pigment{White}
#else
 pigment{Gray30}  #end }


////

Thanks so


Post a reply to this message

From: Le Forgeron
Subject: Re: Vector comparison
Date: 27 Dec 2012 14:05:08
Message: <50dc9be4$1@news.povray.org>
Le 27/12/2012 19:28, Albun nous fit lire :
> 
> Well, i try to change color with  vector's comparison. Subtraction , or equal
> can't give a result to change color.
> And  substraction (Pos_-Pos_compare) can't be recognize. I want to change color
> when the two vectors are the same, in substraction equal to 0 ,=0.
> I use trace() for one vector.
> 

Caveat: 3D vectors are using floating point arithmetic, strict equality
is unlikely to occurs due to noise on floating point operations. (e.g. :
A=<2,4,5>/10; B=<2,4,5>/20; C=B+B+B; D=A+B; ... does D == C ? not sure!)

I would recommend computing the square length of the difference, and
testing it for "small enough" (not =0).

#declare DeltaLenSquared = vdot((Pos_ - Pos_compare),(Pos_ - Pos_compare));
#if (DeltaLenSquared < 0.01)

If you want slower (due to a square root):

#declare DeltaLen = vlength(Pos_ - Pos_compare);
#if (DeltaLen < 0.1)


> ////
> 
> #declare PointA = VEq(Pos_,Pos_compare);
> 
> 
> sphere{Pos_,.25
>  #if (0=PointA)
>  pigment{White}
> #else
>  pigment{Gray30}  #end }
> 
> 
> ////
> 
> Thanks so
> 
> 
> 
>


Post a reply to this message

From: Warp
Subject: Re: Vector comparison
Date: 28 Dec 2012 03:40:47
Message: <50dd5b0f@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
> I would recommend computing the square length of the difference, and
> testing it for "small enough" (not =0).

I think that povray already does that.

-- 
                                                          - Warp


Post a reply to this message

From: Albun
Subject: Re: Vector comparison
Date: 28 Dec 2012 06:00:01
Message: <web.50dd7a9b64cb6c105749dd3d0@news.povray.org>
So, for good result i find the 'near zero value', .25 and .5, not less. I think
it's a gremlin's fake who make noise on floating point operations...


#declare DeltaLenSquared = vdot((Pos_ - Pos_compare),(Pos_ - Pos_compare));
#if (DeltaLenSquared < 0.25)



#declare DeltaLen = vlength(Pos_ - Pos_compare);
#if (DeltaLen < 0.5)


Thanks a lot


Post a reply to this message

From: Kenneth
Subject: Re: Vector comparison
Date: 30 Dec 2012 01:20:08
Message: <web.50dfdbdb64cb6c10c2d977c20@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:

>
> Caveat: 3D vectors are using floating point arithmetic, strict equality
> is unlikely to occurs due to noise on floating point operations. (e.g. :
> A=<2,4,5>/10; B=<2,4,5>/20; C=B+B+B; D=A+B; ... does D == C ? not sure!)
>

That's something fundamental that I didn't know. But I just always assumed that
POV-Ray took care of the floating-point discrepancy internally (as Warp
indicates), i.e. safely truncating the errors in some way. Put a different way:
I haven't *noticed* any oddities in my scenes.

Using an even simpler case:  something like #if(1/1 = 1) would cause havoc if it
was only 'statistically' TRUE due to floating-point errors. *Hopefully* that's
not the situation! :-O

It raises a question in my mind, though: Given a particular math equation on an
unchanging set of values, are the floating point errors always the same? As in,
frame-by-frame animation?


Post a reply to this message

From: Kenneth
Subject: Re: Vector comparison
Date: 30 Dec 2012 01:30:07
Message: <web.50dfdf4064cb6c10c2d977c20@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> Using an even simpler case:  something like #if(1/1 = 1) ...

Actually, a more appropriate example might(?) be #if(pi/pi = 1)


Post a reply to this message

From: Albun
Subject: Re: Vector comparison
Date: 30 Dec 2012 12:30:01
Message: <web.50e0790a64cb6c10bfeb9b920@news.povray.org>
Due to that thing, a constant appear in my 'near-by after sequence' and resolve
the problem.


Post a reply to this message

From: clipka
Subject: Re: Vector comparison
Date: 2 Jan 2013 04:02:43
Message: <50e3f7b3@news.povray.org>
Am 30.12.2012 07:14, schrieb Kenneth:

> It raises a question in my mind, though: Given a particular math equation on an
> unchanging set of values, are the floating point errors always the same? As in,
> frame-by-frame animation?

Depends.

The floating point errors are deterministic, so with one and the same 
POV-Ray build they are always the same from frame to frame.

However, they may differ between builds, depending on floating point 
compiler settings; for instance, the old x87 instruction set allows for 
either 64-bit or 80-bit interim results, while SSE2 always uses 64-bit; 
and depending on optimization settings, very small numbers may or may 
not be truncated to zero. So if you split up an animation on a 
heterogenous render farm, results may differ between frames. (This is 
true for both SDL math and the actual render math.)


Post a reply to this message

From: Kenneth
Subject: Re: Vector comparison
Date: 2 Jan 2013 21:25:03
Message: <web.50e4eae964cb6c10c2d977c20@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

>
> The floating point errors are deterministic, so with one and the same
> POV-Ray build they are always the same from frame to frame.

Yeah, after my post, I dimly recalled that this topic was discussed long ago; I
should have remembered this fact.
>
> However, they may differ between builds, depending on floating point
> compiler settings... So if you split up an animation on a
> heterogenous render farm, results may differ between frames.

I would imagine that huge render farms (hundreds to thousands of machines, as in
the professional CGI effect companies) would have to be strenuously maintained
to have the same builds etc., across the board, if only to minimize or eliminate
this very situation.


Post a reply to this message

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