POV-Ray : Newsgroups : povray.general : Why only a +1 clamp with VAngle, VAngleD macros in math.inc? : Re: Why only a +1 clamp with VAngle, VAngleD macros in math.inc? Server Time
27 Jul 2021 00:33:47 EDT (-0400)
  Re: Why only a +1 clamp with VAngle, VAngleD macros in math.inc?  
From: Alain Martel
Date: 6 May 2021 10:28:33
Message: <6093fd11$1@news.povray.org>
Le 2021-05-06 à 09:06, William F Pokorny a écrit :
> In creating some testing for include file macros I came across code for 
> the two VAngle* macros (and two similar rotation related macros):
> 
> #macro VAngle(V1, V2)
>         acos(min(1, vdot(vnormalize(V1), vnormalize(V2))))
> #end
> 
> The min(1,..) is obviously trying to protect acos from domain errors.
> 
> Why only the clamp to the positive side? Aren't we as exposed to <-1.0?
> 
> Often enough in code - including POV_Ray's own - I've seen code clamping 
> to a [-1..1] range after a dot product into acos() for acos domain 
> concerns.
> 
> I cannot come up with reasoning to clamp only the positive side. Anyone 
> else? If valid to do, we might be able to slightly streamline some 
> internal code.
> 
> Bill P.
> 

The reason is quite simple : Normally, the vdot function of two 
normalized vectors can not return a value that is less than -1 nor more 
than 1.

So, the min() could probably be safely removed.

#macro VAngle(V1, V2)
	acos(vdot(vnormalize(V1), vnormalize(V2)))
#end


Post a reply to this message

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