Move vector to given distance so that it is still a unit vector

195 Views Asked by At

I have two high dimensional unit vectors $\vec a$ and $\vec b $ and the distance $d$ between them.

I want to change the vector $\vec a$ so that it is still a unit vector but the distance to $\vec b $ is now $d'$ .

I already tried it this way: $$\vec a' = \vec a + ( \vec b - \vec a * (1 - \frac {d'}{d}))$$

But then the new vector does not have unit length.

Anyone any idea?

Thank you in advance.

2

There are 2 best solutions below

2
On

First of all, it should be clear that what you are trying to do is impossible if $d'>2$, since

$$d' = \|\vec{a}' - \vec b\|\leq \|\vec{a}'\| + \|\vec b\| = 2$$

Second of all, if $d'\leq 2$, then any vector $\vec x = [x_1,\dots ,x_n]$ that satisfies the equation

$$\sqrt{(x_1-b_1)^2 + \cdots + (x_n-b_n)^n} = d'$$

is at a distance $d'$ from the vector $\vec b$. This means that there is an entire hypersphere of possibilities for $a'$.

0
On

I'll show you one solution for $d,\,d^\prime<2$. Note first that$$d^2=(a-b)\cdot(a-b)=2(1-a\cdot b)\implies 2a\cdot b=2-d^2.$$Attempt a unit vector $c=Aa+Bb,\,A>0$ so $1=c^2=A^2+B^2+2ABa\cdot b$ and$$d^{\prime2}=(c-b)^2=(Aa+(B-1)b)^2=A^2+(B-1)^2+2A(B-1)a\cdot b=2-2B-2Aa\cdot b.$$Hence $B=1-A(1-\tfrac12d^2)-\tfrac12d^{\prime2}$ and$$\begin{align}1&=A^2+(1-A(1-\tfrac12d^2)-\tfrac12d^{\prime2})^2+A(1-A(1-\tfrac12d^2)-\tfrac12d^{\prime2})(2-d^2)\\&=A^2+(1-A(1-\tfrac12d^2)-\tfrac12d^{\prime2})(1+A(1-\tfrac12d^2)-\tfrac12d^{\prime2})\\&=A^2+(1-\tfrac12d^{\prime2})^2-A^2(1-\tfrac12d^2)^2\\\implies A&=\frac{d^\prime}{d}\sqrt{\frac{4-d^{\prime2}}{4-d^2}}.\end{align}$$