Minimize positive distance from a integer lattice point to a line in $n$-dimension

53 Views Asked by At

My goal is to minimize the distance from a point to a line while keeping it positive.

In mathematical terms:
In an Euclidean n-space $\bf{E}^n$, given a line $L$ defined by $k\bf{v}$ (with $k \in \mathbb{R}$ and $\bf{v} \in \mathbb{Q}^n$) and a point $A$ and $\mathbf{w}=\vec{OA}$, the distance between $A$ and $L$ is given by

$$\epsilon = \|\mathbf{w} - \frac{\mathbf{w}.\mathbf{v}}{\|\mathbf{v}\|^2}\mathbf{v}\| = \|\mathbf{w} - (\mathbf{w}.\mathbf{\hat{v}})\hat{\mathbf{v}}\|$$

I am looking for a way to find $A \in \mathbb{Z}^n$ such that $\epsilon > 0$ is minimized.

(Background: I am trying to make a python script to calculate the coefficients of elements in a compound, given their corresponding ratios. However, due to inaccurate measurement and floating point limitations, the result could be off by a considerable amount: for example, a 1:3 ratio could be presented as 47:140. So far I've only managed to handle such cases with only 2 coefficients with Bézout's identity, yet I've not found a way to simplify $\epsilon$ nor to minimize it.)