Problem
So basically I have a bunch of triangles that are defined by 3 points:
X0, Y0, Z0
X1, Y1, Z1
X2, Y2, Z2
I have two points that form a line:
Xl0, Yl0, Zl0
Xl1, Yl1, Zl1
I have a point in space (P) defined as:
Xp0, Yp0, Zp0
I want to know first, how can I determine an equation of the line that is parallel with the original line, but goes through my new point P?
Secondly, using that new line, how can I determine if and where on my triangle it intersects?
I would like to try and create a function that takes the inputs that I have presented and outputs a point which is the intersection of the triangle and a boolean value if it did intersect.
Now I would like to do this through c# or VB .NET but the actual solution really is just math based so answers that are expressed as math and not code would definitely help too.
What I have tried
I thought that calculating the new line would simply be the new point and a second point where
Xnew = Xl0 + (Xp0 - Xl1)
Ynew = Yl0 + (Yp0 - Yp1)
Znew = Zl0 + (Zp0 - Zp1)
then plotting the new line from (Xnew, Ynew, Znew) to (Xp0, Yp0, Zp0) should be a parallel line to my first one, however in doing so they are not parallel which means my calculation is wrong.
Any help would be greatly appreciated!
Update
After trying what was suggested below, the line that is drawn doesn't seem to be correct yet:
The camera's location to the origin is what creates the first line. The second line that we determined is the line from our cursor location, to the new calculated point which should be parallel to the line that goes from the origin to the camera, which as you see is not the case. Am I wrong in my thought process or am I not coding it correctly?
My code doing the calculation like suggested below:
GL.Begin(PrimitiveType.Lines)
GL.Color3(Color.Orange)
Dim XL0, YL0, ZL0 As Single
XL0 = 0
YL0 = 0
ZL0 = 0
'origin is at 0,0,0
Dim XL1, YL1, ZL1 As Single
XL1 = camx
YL1 = camy
ZL1 = camz
Dim XS, YS, ZS As Single
XS = XL1 - XL0
YS = YL1 - YL0
ZS = ZL1 - ZL0
Dim length As Single = Sqrt(XS * XS + YS * YS + ZS * ZS)
XS /= length
YS /= length
ZS /= length
Dim XPN, YPN, ZPN As Single
XPN = returnvec.X - XS * length
YPN = returnvec.Y - YS * length
ZPN = returnvec.Z - ZS * length
GL.Vertex3(XPN, YPN, ZPN)
GL.Vertex3(returnvec.X, returnvec.Y, returnvec.Z)
GL.End()
Trial 1
Trial 2
I drew the lines and they are indeed parallel. I think what is happening is that since I am viewing the line as a perspective view, it appears to converge inward. That means that my math for creating a parallel line is correct which is technically my question. The parallel line however is not what I need to do ray casting.