Ok, wrote this with DB 5.8, but it should work in classic. I didn't use anything specific to Pro. I tested it with some simple numbers that I could easily calculate in my head, and as far as I can tell it works.
Just to clarify on the plane equation for you:
Ax + By + Cz + D = 0
A,B,C would be the normal of the plane.
D is the distance from the origin(0,0,0) to the plane.
I put in a few comments to let you know what each chunk of code is doing. You check the value of t# because if its not within [0,1] then the intersection happens beyond the length of your ray.
You really only need 3 points to define your plane. Once you have an intersection point, check to see if that point is within the boundaries of your actual plane object. I'm sure you already know this tests an infinite plane. To check for intersection within your plane's boundaries, project the plane and intersection point onto the axis with the greatest component value.
lets say your plane's normal is (0.24,0.45,0.78)
We can turn this into a 2d problem by projecting it onto the X plane because it has the smallest component. So basically, just ignore the X-component. Assuming your plane's point are in a clockwise order, you can check to see if the intersection point is to the right of all 4 lines.
The picture I just attached shows the direction the lines should be in along with the direction of their normals. The normals point to the right of the line.
rem 4 points of your plane
p1x# = 0
p1y# = 100
p1z# = 200
p2x# = 1000
p2y# = 100
p2z# = 200
p3x# = 1000
p3y# = 0
p3z# = 200
p4x# = 0
p4y# = 0
p4z# = 200
rem ray vector
r1x# = 300
r1y# = 50
r1z# = 0
r2x# = 300
r2y# = 50
r2z# = 400
rem intersection point
ix# = 0
iy# = 0
iz# = 0
rem form two vectors from the plane
ax# = p2x#-p1x#
ay# = p2y#-p1y#
az# = p2z#-p1z#
bx# = p3x#-p2x#
by# = p3y#-p2y#
bz# = p3z#-p2z#
rem cross product of the 2 above vectors
nx# = ay#*bz# - az#*by#
ny# = az#*bx# - ax#*bz#
nz# = ax#*by# - ay#*bx#
rem normalize vector
length# = sqrt(nx#*nx# + ny#*ny# + nz#*nz#)
nx# = nx# / length#
ny# = ny# / length#
nz# = nz# / length#
rem check for backface culling
if dot_product3#(nx#,ny#,nz#,rx2#-rx1#,ry2#-ry1#,rz2#-rz1#) <= 0
nmx# = p1x#-r1x#
nmy# = p1y#-r1y#
nmz# = p1z#-r1z#
num# = dot_product3#(nx#, ny#, nz#, nmx#, nmy#, nmz#)
dnx# = r2x# - r1x#
dny# = r2y# - r1y#
dnz# = r2z# - r1z#
den# = dot_product3#(nx#, ny#, nz#, dnx#, dny#, dnz#)
t# = num# / den#
if t# >= 0 and t# <= 1
ix# = r1x# + (r2x#-r1x#)*t#
iy# = r1y# + (r2y#-r1y#)*t#
iz# = r1z# + (r2z#-r1z#)*t#
endif
endif
rem dot product of two 3d vectors
function dot_product3#(x1#,y1#,z1#,x2#,y2#,z2#)
d# = x1#*x2# + y1#*y2# + z1#*z2#
endfunction d#
rem worthless function because I can't return more than one number
function cross_product(x1#,y1#,z1#,x2#,y2#,z2#)
cx# = y1#*z2# - z1#*y2#
cy# = z1#*x2# - x1#*z2#
cz# = x1#*y2# - y1#*x2#
endfunction
Here's a function I wrote in Pro awhile ago that might help you out with the final intersection check.
REM if point(px,py) is right or left of line segment (x1,y1),(x2,y2)
REM return negative if left, positive if right, 0 if on
function point_line(px#,py#, x1#,y1#,x2#,y2#)
dp# = (x2# - x1#) * (py# - y1#) - (px# - x1#) * (y2# - y1#)
endfunction dp#
gee thx baggers,
now you tell me.
PETA - People for the Eating of Tasty Animals
