Get intersection Ray with square I have a class Ray and Square

public class Rayo {

public Point origen;
public Vector direction;

Square{
X,Y,Widht, height;
}


I need intersection between this two, how? my code crossProduct in java is 

public static Vector productoCruz(Vector a, Vector b) {
        return new Vector(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X);
    }


To apply the product point you need two vectors, and I only have 1 (the ray vector), where do I get the other vector?
The best algorithm depends on the condition like whether or not the square is axis aligned for example. I'm gonna discuss the more general case which can find find intersection for any arbitrary oriented square. The algorithm works by first checking the intersection of ray with the plane containing the square or rectangle etc. Then check if the ray is within bounds of the square.

For this you require the following information

Ray's in the form $R =e+td $ where $e$ is the origin or eye point and $d$ is the direction vector.

Secondly you need to define your square by using the following information  


Poisition - This might be the vector to the center or any corner of the square. The algorithm I'm describing assumes it is one of the corners.
Normal - Self explanatory.
Width and Height not as scalars but as vectors. These can be called the two edge vectors. I will denote them as $e1$ and $e2$. Note that both edge vectors need to grow outward from the corner of the square chosen in point 1.


After you have the following information you first need to compute Ray - plane intersection. The plane being where your square lies. This is done as follows. We know the point normal form of a plane as,

$(p-p1).n= 0$

If we suppose $p$ is our ray here and $p1 = position$, then we will have,

$(e+td - p1).n=0$
$(e+td - p1).n=0$
$e.n + td.n - p1.n = 0$
$t = p1.n - e.n/d.n$
$t = (p1-e).n/d.n$

If $t \geq 0$ then we have an intersection. Now all we need to do is check whether the ray lies inside the square or anywhere else on the plane. This is easy to do.

$intersect\_point = e + td$
$v = intersect\_point - p1$

$width = ||e1||$
$height = ||e2||$

$proj1 = v.e1 /width $
$proj2 = v.e2 / height$  

$if((proj1 &lt; width \;\&amp;\&amp;\; proj1 &gt; 0) \;\&amp;\&amp;\; (proj2  &lt; height \;\&amp;\&amp;\; proj2 &gt; 0) )$
$return \, true$

Note that the above assumes that the edge vectors grow outward from the corner, i.e. A square with the corners A,B,C,D in clockwise fashion starting from  the top left. If we choose corner $A$ then the edge vectors are $\vec{AB}$ and $\vec{AD}$.