Given a vector, get the coordinates of the same vector on a rectangle.

107 Views Asked by At

I have a circle and a known size vector starting from the center of that circle which comes out of a rectangle. My goal is to know the coordinates (x, y) of the vector being located on the rectangle and of the same size as the first vector.


Let's see an exemple:

exemple

The vector AB comes out of the rectangle, so I would like to know the coordinates of the vector AE of the same size as AB. If this is possible, I would like to get the closest vector (in this case AE but not AG)

1

There are 1 best solutions below

8
On

Say center of the circle is at the origin $O$.

Radius of the circle = $r$. Lengths of the sides of the rectangle are $c, d \, (c \geq d \geq r)$. $c$ is horizontal sides in your diagram and $d$ is vertical sides.

A position vector $A (a_1,a_2)$ is out of a given rectangle and $OA = \vec{a}$.

You can find points on the rectangle with the magnitude of vector $\vec{a}$, only if

$r \leq |\vec{a}| \leq \sqrt{c^2 + d^2} - r \sqrt2 \, \,$ ($c, d$ are sides of the rectangle).

Say we need to find a position vector $B (b_1, b_2)$ on the perimeter of the rectangle such that $\vec{b} = \vec{a} \, \, (\vec{OB} = \vec{b})$.

Any point on the sides of the rectangle are given by (depending on which side it is)

$(\pm x, r), (-(c-r), \pm y), (\pm x, -(d-r)), (r, \pm y)$.

Equate distance on each side of the rectangle to the magnitude of $|\vec{a}|$ to find the possible points.

For example, $x^2 + r^2 = |\vec{a}|^2$ should give you possible points on the upper horizontal side of the rectangle. Now how do you know this point works or not? Using the constraints for the points to be on the rectangle,

$-(c-r) \leq x \leq r$

$-(d-r) \leq y \leq r$

Once you know the points on the rectangle, you know all possible vector $\vec{b}$.

How do you know which one is closest? Do a dot product and find the angle between them. The lowest angle between them will give you the closest position vector $\vec{B}$ to $\vec{A}$.

$\vec{a} \cdot \vec{b} = |\vec{a}| \, |\vec{b}| \, \cos \theta$