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))))
> 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
> 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
So, the min() could probably be safely removed.
#macro VAngle(V1, V2)
Post a reply to this message