Project vector onto a discrete subspace

discrete geometryprojection

I apologise that my explanations aren't very rigorous; I hope you will still get the idea of the question.

Let $\vec v =(v_1, v_2, v_3)$ be the vector to project.

Let P be a plane defined by the unit vectors $\vec e_1$ and $\vec e_2$.

What I want is project $\vec v$ onto P with the constrain that the projected vector $\vec v_p$ must be rounded, i.e. $\vec v_p = (v_{p1}, v_{p2}, v_{p3})$ with $(v_{p1}, v_{p2}, v_{p3})$ $\in \mathbb{Z^3}$.

If $\vec e_1$ and $\vec e_2$ were equal to (1, 0, 0) and (0, 1, 0), respectively, one could do: $$\vec v_{pi} = \operatorname{Round}(\vec v \cdot \vec e_i) \vec e_i \qquad i = 1, 2, 3$$
Which results in $\vec v_p$ having integer components.

In my case however, $\vec e_1$ and $\vec e_2$ are not integers. They are equal, for example, to $(1/\sqrt{2}, 1/\sqrt{2}, 0)$ and $(-1/\sqrt{2}, 1/\sqrt{2}, 0)$, respectively.

Because of that, the previous method won't work.

Rounding $\vec v_p$ after the projection is not possible either, as this would no longer guarantee that $\vec v_p$ is in the plane.

Would there be another way to project a vector on a plane and round its components, while still guaranteeing that the projected vector is in the plane?

— Edit: I want the projected vector to have integer components with respect to the standard basis.

Thanks in advance.

Best Answer

As I understand the question, we have a plane $P$ in $\Bbb{R}^3$, and we wish to compute the projection of a point $x \in \Bbb{R}^3$ onto the set $P \cap \Bbb{Z}^3$.

The first thing to do is find a normal vector $n = (n_1, n_2, n_3) \neq 0$ to $P$, i.e. $P$ is the set of vectors perpendicular to $n$. Compute the dimension of the set $\operatorname{span}_\Bbb{Q}\{n_1, n_2, n_3\}$ as a vector space over $\Bbb{Q}$.

Since $n \neq 0$ the dimension is at least $1$. If the dimension is $3$, then $P \cap \Bbb{Z}^3 = \{(0, 0, 0)\}$, and the projection is constantly $(0, 0, 0)$. If the dimension is $2$, then $P \cap \Bbb{Z}$ consists of a equally spaced points along a line, which is easy enough to work with (project onto the line, and round to the nearest point). Otherwise, the dimension is $1$, which is the trickiest case.

In this case $n_1, n_2, n_3$ are rational multiples of the same number $k$. By scaling $n$ as necessary, we may assume that $n_1, n_2, n_3$ are all integers, whose gcd is $1$.

We are now trying to solve a homogeneous linear diophantine equation in three variables. Specifically, we need to find integer solutions $(x_1, x_2, x_3)$ to $$n_1 x_1 + n_2 x_2 + n_3 x_3 = 0.$$ Solving this yields solutions in two integer parameters $a$ and $b$, which will reduce to the form $x = (x_1, x_2, x_3) = ay + bz$, where $y, z \in \Bbb{Z}^3$. In particular, this gives us a lattice of points, though no longer rectangular.

So, we have reduced the problem down to projecting onto points with integer coordinates in a basis $B = (y, z)$ that is (typically) not orthonormal. I suggest following the following procedure:

  • Compute the projection $p$ of a point $x$ onto $P$,
  • Compute the coordinates $(a, b)$ of $p$ with respect to the basis $B$,
  • Compute the distance from $x$ to the (typcially) four points of the form $a'y + b'z$, where $a' \in \{\lfloor a \rfloor, \lceil a \rceil \}$ and $b' \in \{\lfloor b \rfloor, \lceil b \rceil \}$, and
  • Return the point out of the previous $4$ points which is closest.
Related Question