Given 3 points A, B and C
How can I find and arc that begins at A, ends at C and pass through B; its center's coordinates, radius and angles for r and r' ?
Equation of circle in general form is x² + y² + 2gx + 2fy + c = 0 and in radius form is (x – h)² + (y -k)² = r², where (h, k) is the centre of the circle and r is the radius.
The best way to deal with angle computation is to use atan2(y, x) that given a point x, y returns the angle from that point and the X+ axis in respect to the origin. double result = atan2(P3. y - P1. y, P3.
The center of the circle is equidistant to the three given points:
(X-Xa)^2+(Y-Ya)^2 = (X-Xb)^2+(Y-Yb)^2 = (X-Xc)^2+(Y-Yc)^2
Subtracting the first member from the second and the third, we get after regrouping:
2(Xa-Xb) X + 2(Ya-Yb) Y + Xb^2+Yb^2-Xa^2-Ya^2 = 0
2(Xa-Xc) X + 2(Ya-Yc) Y + Xc^2+Yc^2-Xa^2-Ya^2 = 0
This linear system of two equations in two unknowns is easy to solve with Cramer's rule.
The radius and angles can be found using the Cartesian-to-polar transform around the center:
R= Sqrt((Xa-X)^2+(Ya-Y)^2)
Ta= atan2(Ya-Y, Xa-X)
Tc= atan2(Yc-Y, Xc-X)
But you still miss one thing: what is the relevant part of the arc ? Smaller or larger than a half turn ? From Ta
to Tb
or from Tb
to 2 Pi
to Ta + 2 Pi
, or what ? The answer is much less obvious than it seems, try it (because the three angles Ta
, Tb
and Tc
are undeterminate to a multiple of 2 Pi
and you cannot sort them) !
Hint: consider the sign of the area of the triangle ABC, precisely the half of the determinant of the system. It will tell you if B lies on the left or the right of AC.
There are a few ways to do this. Here is one algorithm:
Get your COORDS
A = {xA,yA}
B = {xB,yB}
C = {xC,yC}
d = {xd,yd}
Calculate Mid-points of lines AB and BC
mid_AB = { (xA+xB)/2, (yA+yB)/2 }
mid_BC = { (xB+xC)/2, (yB+yC)/2 }
Find slopes of lines AB and BC
slope_AB = (yB-yA)/(xB-xA)
slope_BC = (yC-yB)/(xC-xB)
Construct lines running through mid-points PERPENDICULAR to AB and BC (thank you to Yves for catching the negative!)
Slope_perp_AB = -(slope_AB)^(-1)
Slope_perp_BC = -(slope_BC)^(-1)
*** Line with Slope_perp_AB runs through mid_AB
*** Line with Slope_perp_BC runs through mid_BC
Set the two equations equal to each other and solve to find intersection! This gives you point d={xd,yd} !!!
Calculating the radius and angles is now trivial with the center-point d!
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