How to calculate (x,y) for a fixed arc length away from a point on a circumference
Asked Answered
D

3

9

I've spent so many hours on this I can feel my sanity slowly slipping. So any help would be really truly appreciated. I'll try and be as succinct as possible.

I have a circle on a 2D plane. I know the cartesian coordinates for it's central point(C) and the radius(R).

My confusion stems from this problem. When provided with a point on the plane outside of the circle; I can calculate the point(P) on the circle's circumference closest to that point.

What I want to do is determine the (x,y) coordinates of 2 points on the circumference. Let's call them P1 and P2. P1 and P2 are two ends of an arc. The arc is of a fixed length(X). P is the midway point between P1 and P2. As such, the arc length from P to P1 & P to P2 are both X/2.

In short: given C, R, P, X ; I need to calculate P1 and P2.

I am trying to code this in c++ but any suggestions or pseudo-code would be great.

EDIT: X is an arc length, not a straight line between P1 and P2

Dichlorodifluoromethane answered 5/11, 2010 at 23:47 Comment(1)
How about some of the examples from the following: codeproject.com/KB/recipes/Wykobi.aspx They are very efficient and somewhat elegant, look for "Closest Point On Circle From External Points" and "Circle Tangent Line Segments"Gratulation
H
4

On a circle, an angle theta corresponds to an arc length of theta * R, meaning your arc will subtend an angle of theta = X / R. So if start with your point

P = C + R * (sin(u), cos(u))

then just go up/down by theta/2:

P1 = C + R * (sin(u + theta/2), cos(u + theta/2))

and

P2 = C + R * (sin(u - theta/2), cos(u - theta/2))
Hexone answered 5/11, 2010 at 23:53 Comment(0)
D
3

An arc that subtends an angle of θ (in radians) has an arc length of θR. So, you want a half-angle of θ = X/(2R). You then need to take the vector (P -C), rotate it by angles of ±θ, and add back in C to get P1 and P2. To rotate a vector by an angle, multiply it by a rotation matrix.

So, in pseudocode, it would look like this:

θ = X/(2R)
A = 2x2 rotation matrix corresponding to a rotation by θ radians
A' = transpose of A
P1 = C + A * (P - C)
P2 = C - A' * (P - C)
Diaphaneity answered 5/11, 2010 at 23:57 Comment(0)
D
0

There's a few things that could help. Not gonna write the code but I imagine the solution is going to be based on triangles. Consider:

Any radius is the same length.

Thus the triangle drawn from P1-P1-C is isosceles.

Any tangent is perpendicular to the radius.

I'd be hard pressed to prove it out right here and now, but if you extend the lines from C through P1/P2 to the tangent that intersects the circle at C->P also form an isosceles.

Should be easy to figure out from there.

Dustindustman answered 6/11, 2010 at 0:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.