I have the following problem that I am unable to solve, even after a long search on the internet.
How calculates the intersection of the plane in ray?
The plane is described by four points:
A (ax, ay, 0)
B (bx, by, 0)
C (cx, cy, 0)
D (dx, dy, 0)
Ray have:
Vector3f origin;
Vector3f direction;
And now, i want write a method for checking HIT. Could someone show me a solution?
public Boolean checkHit(Ray myRay){
.
.
.
}
Thank you
A plane can be defined by a unit normal vector
(nx,ny,nz)
and a scalar distance from the origind
such that the equation of the plane isnx*x+ny*y+nz*z=d
. You need to get the plane from 3 points to this format in order to proceed. If you don't know how you can look up finding a plane from three points.Now the line can be specified by a unit direction vector
(ex,ey,ez)
and some point along the line(rx,ry,rz)
s=(nx*ex+ny*ey+nz*ez)
. If it is zero then there is no intersectiont=(d-(nx*rx+ny*ry+nz*rz))/s
c=(rx+ex*t, ry+ey*t, rz+ez*t)