With the whole X subtraction thing, It doesnt matter what the two coordinates are subtracted since it's just finding 2 vectors lying on the surface so any coordinates can be used.
Also I've pretty much tried learning about vectors just now since I haven't needed then until now. I havn't even gone over them yet in school. Which makes your explanation very hard for me to understand.
So anyways I also worked on an equation for figuring out the point on a line, its more of an algebraic equation.
Now for a line, we have the points X1,Y1,Z1 to X2,Y2,Z2 and the formula <X1,Y1,Z1>+FL*<X3,Y3,Z3>
where <X1,Y1,Z1> is the position vector of the first point, FL is the a factor of the line that is multiplied with the vector and the <X3,Y3,Z3> is the direction vector from x1,y1,z1 to x2,y2,z2.
This simplifies to the vector that lies on the plane
<X1+FL(X3),Y1+FL(Y3),Z1+FL(Z3)>
Now since this point lies on the plane it can be plugged into the plane equation
PFX(X1+FL(X3))+PFY(Y1+FL(Y3))+PFZ(Z1+FL(Z3))=PR
Where PFX,PFY, and PFZ are factors by which the point on the plane is multiplied by to equate to PR.
We have all values except for FL which once we solve for, finding the point on the line is easy.
So I took this equation and simplified it to
`````PR-(PFX(X1)+PFY(Y1)+PFZ(Z1))
FL`=`------------------------------
`````PFX(X3)+PFY(Y3)+PFZ(Z3)
Then using this you have FL to find the point of intersection with.
<X1+FL(X3),Y1+FL(Y3),Z1+FL(Z3)>
So that's how I choose to do it since thats as far as I figured out so far. But I'd also like to know how the method you posted works.
EDIT/UPDATE: Ok so I coded it in but came up with inexplicable results that were wrong.
Rem Project: Plane Equation
Rem Created: Sunday, March 27, 2011
Rem ***** Main Source File *****
sync on
sync
autocam off
PX1=-5 ; PX2=4 ; PX3=5
PY1=-3 ; PY2=3 ; PY3=1
PZ1=2 ; PZ2=4 ; PZ3=3
LX1=0 ; LX2=0
LY1=-1 ; LY2=5
LZ1=0 ; LZ2=0
InitPlaneEquation()
CreatePlaneEquation(PX1,PY1,PZ1, PX2,PY2,PZ2, PX3,PY3,PZ3)
LineIntersectsPlane(LX1,LY1,LZ1, LX2,LY2,LZ2)
Make object triangle 1, PX1,PY1,PZ1, PX2,PY2,PZ2, PX3,PY3,PZ3
make object sphere 2,0.2
make object sphere 3,0.2
make object sphere 4,0.2
`Make object triangle 5,LX1,LY1,LZ1, LX2,LY2,LZ2, LX2,LY2,LZ2
color object 1,rgb(255,255,0)
color object 2,rgb(0,255,0)
color object 3,rgb(0,255,0)
color object 4,rgb(255,0,0)
position object 2, LX1,LY1,LZ1
position object 3, LX2,LY2,LZ2
position object 4, PEIntersectX#,PEIntersectY#,PEIntersectZ#
position camera 0,10,-10
do
rotate camera camera angle x()+mousemovey()/2.0,camera angle y()+mousemovex()/2.0,0
line object screen x(2),object screen y(2),object screen x(3),object screen y(3)
if scancode()<>0 then end
text 0,0,"Equation X Factor: "+str$(PEXF#)
text 0,10,"Equation Y Factor: "+str$(PEYF#)
text 0,20,"Equation Z Factor: "+str$(PEZF#)
text 0,30,"Equation Result: "+str$(PEResult#)
text 0,40,"Equation: "+str$(PEXF#)+"X+"+str$(PEYF#)+"Y+"+str$(PEZF#)+"Z="+str$(PEResult#)
text 0,60,"Line Intersects At: "+str$(PEIntersectX#)+", "+str$(PEIntersectY#)+", "+str$(PEIntersectZ#)
sync
loop
Function InitPlaneEquation()
// Variables containing the factors for the plane equation
Global PEXF# as float
Global PEYF# as float
Global PEZF# as float
// Variable of the result of the plane equation
Global PEResult# as float
// Returns the point of intersection of the line and plane
Global PEIntersectX# as float
Global PEIntersectY# as float
Global PEIntersectZ# as float
// Returns a 1 if intersection occurs and a 0 if the line is parallel to the plane
Global PEValidIntersect as byte
Endfunction
Function CreatePlaneEquation(X1#,Y1#,Z1#,X2#,Y2#,Z2#,X3#,Y3#,Z3#)
// 3 vector ID variables, U and V are for vectors on the plane and N is the normal vector of the plane
local U as integer = 1
local V as integer = 2
local N as integer = 3
// Create the 3 vectors
Null=Make Vector3(U)
Null=Make Vector3(V)
Null=Make Vector3(N)
PX1#=X2#-X1#; PY1#=Y2#-Y1#; PZ1#=Z2#-Z1#
PX2#=X3#-X1#; PY2#=Y3#-Y1#; PZ2#=Z3#-Z1#
// Places vector U and V on the plane
Set vector3 U,PX1#,PY1#,PZ1#
Set vector3 V,PX2#,PY2#,PZ2#
// Finds the perpendicular vector of the plane
Cross product vector3 N,U,V
// Stores the factors and result
PEXF#=X Vector3(N)
PEYF#=Y Vector3(N)
PEZF#=Z Vector3(N)
PEResult#=(PEXF#*X1#)+(PEYF#*Y1#)+(PEZF#*Z1#)
Null=Delete Vector3(U)
Null=Delete Vector3(V)
Null=Delete Vector3(N)
Endfunction
Function PointOnPlane(X#,Y#,Z#)
if PEXF#*X#+PEYF#*Y#+PEZF#*Z#=PEResult# then exitfunction 1
Endfunction 0
Function LineIntersectsPlane(X1#,Y1#,Z1#,X2#,Y2#,Z2#)
// This uses the line formula <X1,Y1,Z1>+t<XD,YD,ZD>
// where <X1,Y1,Z1> is the starting point of the line and <XD,YD,ZD> is the direction vector of the line.
LX#=X2#-X1#; LY#=Y2#-Y1#; LZ#=Z2#-Z1#
// Equation for finding the factor multiplied with the direction vector of the line
N1#=PEXF#*X1#+PEYF#*Y1#+PEZF#*Z1#
N2#=PEXF#*LX#+PEYF#*LY#+PEZF#*LZ#
PELF#=(PEResult#-N1#)/N2#
// Plugged into the original formula now that we have found the factor to find the intersection point
PEIntersectX#=X1#+PELF#*LX#
PEIntersectY#=Y1#+PELF#*LY#
PEIntersectZ#=Z1#+PELF#*LZ#
Endfunction
And also @pictionaryjr
Its to make the entire environment in my game destructable, so say you have several trees blocking your view, just place a pack of C4 and problem solved.