开发者

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

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


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))


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜