1

I want to calculate the X,Y coordinates of a point on a circle given only the distance and angle traveled, without calculating the radius as an intermediate step.

My starting point (0,0) is at the top of the circle. I know how far I have traveled around the circumference, and I know the angle I have subtended.

Because the angle could be very small or zero and this has to be performed in 32bit floating point arithmetic I want to avoid having to calculate the radius or location of the center of the circle (which could be infinite or very, very large)

Peeling
  • 111

1 Answers1

1

That's simple: if $r$ is the radius and angles, measured w.r.t. the vertical axis, are in radians, the distance travelled is $d=r\theta$.

On the other hand, $x=r\cos\bigl(\frac\pi2+\theta\bigr)=-r\sin\theta\:$ and $\:y=r\sin\bigl(\frac\pi2+\theta\bigr)-r =r(\cos\theta -1) $, so that \begin{cases} x=-\dfrac{d\sin \theta}\theta,\\[1ex] y=\dfrac{d(\cos\theta-1)}\theta. \end{cases}

Bernard
  • 175,478
  • Technically correct, but it doesn't actually help :) You've used d = rθ to express the equations without mentioning the letter r, but in practice those equations still involve calculating r in all but name (ie, they both involve d/θ) which means the problem with θ=0 or θ being very small remains. It is interesting that sinθ/θ tends to 1 and (cosθ-1)/θ tends to zero though :) – Peeling Apr 13 '19 at 13:01
  • My point was only to have a formula involving only the distance and the angle. – Bernard Apr 13 '19 at 13:12
  • Right - which would be fine if I were answering a math problem on paper. But I'm writing a computer program, and your equations still involve "d/θ", which is inaccurate or non-computable as θ approaches zero. The equations aren't using the LETTER r, but they are using the VALUE of r (i.e. d/θ) which is the problematic part :) – Peeling Apr 25 '19 at 14:55
  • My final formuæ involve only $d$ and $\theta$, not $r$, which is used only for their justification. Your question says these data are given. And as far as I know, there are programs which can determine a limit with a good approximation. – Bernard Apr 25 '19 at 16:43
  • I can't verify if this is useful here, but sometimes you can do a little bit better by computing the natural log of a quantity. So, you could compute $\ln{x} = \ln{d}+\ln{\sin{\theta}}-\ln{\theta}$. Which can be better as long as all three terms are not very close to one another. If they are, the subtraction will cause you to lose precision through cancellation. – Chessnerd321 Feb 15 '22 at 21:17
  • You may also just be able to use a small angle approximation. If $\theta$ is small then $\frac{\sin{\theta}}{\theta} \approx 1$ within an error of $\frac{\theta^2}{6}$. So if $\theta$ is prohibitively small then $\theta^2$ is minuscule. – Chessnerd321 Feb 15 '22 at 21:26