Find a t value of a parametric given the X and Y coordinates

parametric

(Sorry for the seemingly simple question)

I need to find the t value of a set of parametric equations that corresponds to an (x, y) point on the parametric curve. The parametric curve will always be a circle. I'm given:

  • The parametric equation will ALWAYS be a circle
  • A cartesian point (x, y)
  • The radius of the circle
  • The point at which the circle is centered (h, k)
  • The parametrics will be in the standard parametric circle form:
    • x(t) = r*cos(t) + h
    • y(t) = r*sin(t) + k

I found the t value corresponding to any point on the circle in quadrants I, II, and IV (and on the axes) easily with arccos() and arcsin(), but I can't find a way to find it for a point in quadrant III.

This is for a program I'm writing, so the best way I have found is to brute-force find the point by starting with t = pi, taking the distance formula between (x(pi), y(pi)) and the given point (x, y), and iterating on t and repeating the distance formula until the distance converges to 0. But, I would like a faster and more direct method, if it exists.

Best Answer

Your question is a bit unclear, and you talk about both using arccos()/arcsin() and using an iterative method. Perhaps you're using different strategies depending on the quadrant?

Regardless, you're hitting a common problem in that arcccos() and arcsin(), each taken separately, don't fully distinguish between all the quadrants. To cover all four quadrants you have to inspect the signs of both values and do a case-by-case treatment. But luckily it's already been done, and it's named arctan2(), (or sometimes atan2()).

From your equations it looks like it should be as simple as

$$ t = \arctan2( y-k, x-h)$$

You don't need to divide by $r$; atan2() handles the 'normalization' for you.

Just be sure to check what range of values your implementation of atan2() returns. Usually its $-\pi \lt t \le \pi$, but some use $0 \le t \lt 2\pi$, so if you want something different you would have to adjust the returned value by $2\pi$ for some ranges of returned values.