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
Summary. The length of any arc is s = r θ , where is the length of the arc, is the radius, and is the measure of the angle in radians.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With