Find nearest points on the circumference of a circle based on reference coordinates and centre coordinates given

380 Views Asked by At

For a programming purpose I've been asked to plot few points next to a point on a circular diagram. The only given values are the reference point coordinates and distance from/to of the new point to plot based on the reference point and the center coordinates. So how can I find the nearest points on the circumference with that data only?

This is the diagram. Also Ive been given the radius too. enter image description here

Little update based on a comment So as a summary, I've the coordinates of the reference point Q on the circumference and I need to plot P in specific given distance from Q. Also radius r is given.

2

There are 2 best solutions below

1
On

Your comments indicate you want a more general case than that in the diagram. I assume that $0<d<2r$ so that there are always two solutions.

For radius $r$, centre $(h,k)$, we are looking for a point $(x,y)$. I assume the reference point $(a,b)$ is still a distance $r$ from the centre. We start by taking coordinates relative to the centre: $X=x-h,Y=y-k,A=a-h,B=b-k$.

We have $X^2+Y^2=r^2,A^2+B^2=r^2,(X-A)^2+(Y-B)^2=d^2$. Subtracting the last from the first we get $2AX+2BY=2r^2-d^2$. Substituting for $Y$ into $X^2+Y^2=r^2$ we get: $$r^2X^2-A(2r^2-d^2)X+\frac{(2r^2-d^2)^2}{4}-r^2(r^2-A^2)=0$$ Solutions: $$X=A-\frac{Ad^2}{2r^2}\pm\frac{d\sqrt{(r^2-A^2)(4r^2-d^2)}}{2r^2}$$ Reverting to the usual coordinates, we get $$x=a-\frac{(a-h)d^2}{2r^2}\pm\frac{d\sqrt{(r^2-(a-h)^2)(4r^2-d^2)}}{2r^2}$$ Having found the two possible values of $x$ you get the corresponding $y$ from the linear equation $2(a-h)(x-h)+2(b-k)(y-k)=2r^2-d^2$.

3
On

We can find these points by rotating $Q$ around $C$ through an angle $\pm\theta$ that satisfies $\sin{\frac\theta2}={d\over2r}$. This can be accomplished by translating to $C$, rotating, and then translating back, giving $$\begin{align} x_p&=(x_q-x_c)\cos\theta\mp(y_q-y_c)\sin\theta+x_c \\ y_p&=(y_q-y_c)\cos\theta\pm(x_q-x_c)\sin\theta+y_c \end{align}$$ where $\sin\theta$ and $\cos\theta$ are given by the double-angle formulas:$$ \sin\theta = 2\sin{\frac\theta2}\cos{\frac\theta2} = \frac dr\sqrt{1-{d^2\over4r^2}} \\ \cos\theta = \cos^2{\frac\theta2}-\sin^2{\frac\theta2} = 1-{d^2\over2r^2} $$