POV-Ray : Newsgroups : povray.general : Q: reflected vector : Q: reflected vector Server Time
12 Aug 2024 21:27:29 EDT (-0400)
  Q: reflected vector  
From: Margus Ramst
Date: 31 Dec 1998 16:17:00
Message: <368BE775.4778132F@peak.edu.ee>
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


Post a reply to this message

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