POV-Ray : Newsgroups : povray.general : Q: reflected vector : Re: Q: reflected vector Server Time
12 Aug 2024 21:19:18 EDT (-0400)
  Re: Q: reflected vector  
From: John VanSickle
Date: 1 Jan 1999 12:47:14
Message: <368D0AA0.3019DD1C@erols.com>
Margus Ramst wrote:
> 
> Hi all, I'm once again having math trouble :(
> A macro I'm writing needs to calculate reflected vectors (it simulates
> reflected caustics in Superpatch, I'll probably post it soon...)
> However, the function I use to calculate the reflected vectors has 2
> shortcomings:
> 1) it doesn't work when the incoming ray is parallel/anti-parallel with the
> surface normal (the vaxis_rotate function would have the rotation axis of
> <0,0,0>)
> 2) because I use asin, the reflecion vector is incorrect when the ray hits the
> surface at >=0 degrees (for example when surface normals point into the object
> in CSG)
> Here's the macro I use to calculate the vector; if anybody could provide a
> solution to these problems or give a more optimal method, I'd be thankful
> indeed.
> 
> Margus
> 
> //V - ray direction vector (from intersection to origin)
> //N - surface normal
> 
> #macro v_mirror(V,N)
>     (
>     vnormalize
>         (
>         vaxis_rotate
>             (
>             (V),
>             vcross((V),N),
>             2*degrees(asin(vlength(vcross(vnormalize((V)),vnormalize(N)))))
>             )
>         )
>     )
> #end

The formula you appear to be using is really strange looking.

Why not use this:

#macro v_mirror(V,N)
  ( V-2*N*vdot(V,N) )
#end

Regards,
John


Post a reply to this message

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