Describing point inside square using its corners

I am faced with a problem of transforming point from 3d-coordinate system $$\mathcal{S} \subset \mathbb{R}^3$$ to 2d-coordinate system $$\mathcal{T} \subset \mathbb{R}^2$$.

I have 4 corners points of a square $$S$$, $$s_i \in \mathcal{S}, \forall i \in \{1, 2, 3, 4\}$$. The points $$t_i \in \mathcal{T}, \forall i \in \{1, 2, 3, 4\}$$ represent the corner points of the same square $$S$$. Here $$t_1$$ is the origin.

In order to map a point $$s \in \mathcal{S}$$ to a point $$t \in \mathcal{T}$$, I assume the following:

By calculating a weight vector $$w \in \mathbb{R}^4$$ such that $$s = \sum_iw_is_i$$ with $$\forall i, w_i \geq 0, \sum_{i=1}^{4}w_i = 1$$, I can calculate $$t$$ using $$t = \sum_iw_it_i$$.

I calculate the weight vector as follows: $$\forall i, w_i = \frac{\exp\left(\frac{1}{\lVert s - s_i \rVert_2}\right)}{\sum_i\exp\left(\frac{1}{\lVert s - s_i \rVert_2}\right)}$$.

However, the I am getting errors based on this calculation. Is my logic wrong ? Is there any other better way to perform this transformation ? Any help in this regard is highly appreciated.

• I just realized that I could formulate this as a constrained optimization problem $$\min_w \lVert Sw-s\rVert_2^2 \text{ subject to } \forall i, w_i \geq 0, \sum_iw_i = 1$$ where $S$ here represents a matrix whose columns are $s_i$. I am just wondering if there exists a closed form solution to this problem Commented Aug 12, 2021 at 13:19

For every point $$s$$ in the square there exist unique $$a,b\in[0,1]$$ such that $$s=s_1 + a(s_2-s_1)+b(s_3-s_1).$$ You can then map $$s\in\mathcal{S}$$ to $$t\in\mathcal{T}$$ by replacing the $$s_i$$ by the $$t_i$$.
Writing $$s-s_1=(x,y)$$ and $$s_i=(x_i,y_i)$$ for $$i=2,3$$ we can write this as $$\begin{pmatrix} x_2&x_3\\ y_2&y_3 \end{pmatrix} \cdot \begin{pmatrix} a\\ b \end{pmatrix} = \begin{pmatrix} x\\ y \end{pmatrix} ,$$ which shows that you can find $$a$$ and $$b$$ by inverting the matrix.
• It appears to me that in your formulation, $s_i \in \mathbb{R}^2$. However, $s_i \in \mathbb{R}^3$. Is it fine to ignore the 3rd coordinate ? Commented Aug 12, 2021 at 14:24