Find the lenght of the segment that links a point to the vertical diameter

28 Views Asked by At

Given a circumference and a point on that, how can I compute the length of the line that links the point to the vertical diameter?

What I know is: the coordinates of the center (cx and cy), the angle theta1, the radius and the coordinates of the point.

example

This is what I tried:

theta1 = degToRad(225°)
p1x = r * cos(theta1)
p1y = r * sin(theta1)
theta2 = 2 * PI - abs(PI - theta1)
p2x = r * cos(theta2)
p2y = r * sin(theta2)
dist = distance(p1, p2)

The idea is find the point p2 which is the point mirrored with respect to the diameter and then compute the distance between two points. It doesn't work, I think the problem is the computation of theta2.

1

There are 1 best solutions below

0
On BEST ANSWER

You're overcomplicating things. This is a right triangle:

enter image description here

So basic trigonometry says $$ ? = r\sin\left(\theta - \frac{\pi}{2}\right). $$