1. Show ALL your code; we have to be able to run it.
2. You don't actually say WHAT your problem is.
3.
is a silly statement. From the rest of your working (particularly the value of t) I would guess it meant that the equation of the plane is
2x+y+0z-4=0
i.e.
N.
x+d=0
but there are multiple ways of expressing the equation of a plane and that last sign is crucial.
Let's assume that the vector equation of the ray is
x =
a + t
b (where
a=start and
b=dir in your notation)
and the equation of the plane is
N.
x+d=0 (you still have to define whether that d is on the left or right).
Then the value of the parameter t (if there is one) comes from the intersection:
t = -(d+
N.
a)/(
N.
b)
and the intersection point is then
a + t
b
That will work EXCEPT when
N.
b=0 (corresponding to the ray direction being parallel to the plane. So calculate
N.
b first. There are three cases:
(i)
N.
b=0 and d+
N.
a = 0
The ray lies IN the plane; any value of t will do.
(ii)
N.
b=0 and d+
N.
a is not equal to 0
There is NO intersection - ray is parallel to the plane.
(iii)
N.
b not equal to 0: then the solution is
t = -(d+
N.
a)/(
N.
b)
intersection =
a + t
b
You need to consider those possibilities
in that order.
Obviously, testing for equality of floating-point numbers is fraught with difficulties associated with floating-point accuracy, so compare them with 0 up to a small tolerance (as your code appears to be trying to do).