Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm to find an arc, its center, radius and angles given 3 points

Tags:

algorithm

math

Given 3 points A, B and C

enter image description here

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' ?

enter image description here

like image 886
ibrabeicker Avatar asked Apr 01 '14 16:04

ibrabeicker


People also ask

How do you find the center and radius of a circle given three points?

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.

How do you find the angle between three coordinates?

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.


2 Answers

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.

like image 144
Yves Daoust Avatar answered Oct 24 '22 00:10

Yves Daoust


There are a few ways to do this. Here is one algorithm:

  1. Get your COORDS

    A = {xA,yA}

    B = {xB,yB}

    C = {xC,yC}

    d = {xd,yd}

  2. Calculate Mid-points of lines AB and BC

    mid_AB = { (xA+xB)/2, (yA+yB)/2 }

    mid_BC = { (xB+xC)/2, (yB+yC)/2 }

  3. Find slopes of lines AB and BC

    slope_AB = (yB-yA)/(xB-xA)

    slope_BC = (yC-yB)/(xC-xB)

  4. 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

  5. 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!

like image 41
Joshua Avatar answered Oct 24 '22 01:10

Joshua