Finding points in plane that form a square

3dplane-geometryvectors

I have a vector and a point in space. Following that vector from that point I have drawn a plane with that vector as a normal. Now, on this plane I need 4 points that form a square centred on where the vector out of the point hits the plane.

Sketch of problem

enter image description here

The solution needs to be generic because the vector and point might change. It's for a game project. If it makes any difference, the line between the top two points in the square, and the line between the bottom two points, will always be perpendicular to the Z axis.

Thanks!

Best Answer

Let's call the normal vector $\boldsymbol{n}$.

Let's call the position vector of your given point $\boldsymbol{p}$

Equation of plane is given by $\boldsymbol{r} . \boldsymbol{n}= \boldsymbol{p} . \boldsymbol{n}$

The vector joining the top two points of your square must be perpendicular to $\boldsymbol{n}$ and perpendicular to $\left( \begin{array}{c} 0 \\ 0 \\ 1 \end{array} \right)$ (the direction vector of the $z$-axis)

Let this vector be $\boldsymbol{x}$.

$\boldsymbol{x}$ must be parallel to the cross product of $\boldsymbol{n}$ and $\left( \begin{array}{c} 0 \\ 0 \\ 1 \end{array} \right)$ and it must have magnitude $a$ (if I understand your diagram correctly).

Then $\boldsymbol{x}$ = $a \frac {\boldsymbol{n} \times \left( \begin{array}{c} 0 \\ 0 \\ 1 \end{array} \right)}{\left |{\boldsymbol{n} \times \left( \begin{array}{c} 0 \\ 0 \\ 1 \end{array} \right)} \right |}$

The vector joining the two points on the side of your square must be perpendicular to $\boldsymbol{n}$ and perpendicular to $\boldsymbol{a}$

Let this vector be $\boldsymbol{y}$.

$\boldsymbol{y}$ must be parallel to the cross product of $\boldsymbol{n}$ and $\boldsymbol{a}$ and it must also have magnitude $a$.

Then $\boldsymbol{y}$ = $a \frac {\boldsymbol{n} \times \boldsymbol{a}}{\left |{\boldsymbol{n} \times \boldsymbol{a}} \right |}$