Ray(s) to plane (flat) intersection?
BlitzMax Forums/BlitzMax Programming/Ray(s) to plane (flat) intersection?
| ||
I want some fast code to calculate the 3D point of intersection of a ray against a plane (which is actually flat - stretching out in the X and Z planes only - so might be faster). Also, I'm wondering if there is any way to speed this up for multiple parallel rays against the same plane (ignoring that I only need to calculate the plane equation once). Anyone got any pointers? |
| ||
'AB is a line, not a ray 'flags '1 - two-sided '2 - infinite ray Function LineIntersectsPlane:Int(Ax#,Ay#,Az#,Bx#,By#,Bz#,nx#,ny#,nz#,d#,flags=0,epsilon#=0.0) Local vec:TVec3 Local u# If Not (1 & flags) If PointPlaneDistance#(Ax#,Ay#,Az#,nx#,ny#,nz#,d#)>=-epsilon Return 0 EndIf u#=(-nx*Ax-ny*Ay-nz*Az+d)/(-nx*(Ax-Bx)-ny*(Ay-By)-nz*(Az-Bz)) If (u>=epsilon And u<=1.0+epsilon)=True Or (2 & flags)<>0 VECTOR_x=Ax+(Bx-Ax)*u VECTOR_y=Ay+(By-Ay)*u VECTOR_z=Az+(Bz-Az)*u Return 1 EndIf Return 0 EndFunction |