Calculating the center point of an Arc.
Finding yourself on a random point on an arc you may want to begin to find out some information about your location so that you can do some planning and coordination to reach your end goal at the unknown location marked below as point pX.
The first step is to define a coordinate system. To begin with, we will use rectangular coordinates or Cartesian coordinates. You can place this coordinate system randomly in both location and rotation. We will start Starting with how to locate the center point of an arc or circle using three random points along the arc/circumference.
Using the points; pA , pB and pC, we will locate point pO using some linear algebra and square matrices. We will be using larger matrices and will calculate the determinate of the matrix’s minors.
For this example the following data will be used;
pA.X = -5.0000 pA.Y = 2.1962 pA.X^2 = 25 pA.Y^2 = 4.82329444 pB.X = -4.0000 pB.Y = 2.6569 pB.X^2 = 16 pB.Y^2 = 7.05911761 pC.X = 3.9161 pC.Y = -4.0000 pC.X^2 = 15.33583921 pC.Y^2 = 16
Matrices and Laplace Expansion
Define M as a matrix as follows;
(x2+y2 x y 1) ( x2+ y2 x y 1) pA(x2+y2 x y 1) (29.82329444 -5.000 2.1962 1) pB(x2+y2 x y 1) = (23.05911761 -4.000 2.6569 1) = 0 pC(x2+y2 x y 1) (31.33583921 3.9161 -4.0000 1)
Using this 4×3 matrix we will use Laplace expansion as follows to return the matrix’s minors determinate values.
|M| = determinate of matrix M which requires several calculations as laid out below.
To compute the center point of the arc described above we will use three minors of the 4×3 grid matrix M. We will use minors [mA, mB, mC] of the matrix as |M| as follows;
(a b c) mX = (d e f) >> |mX| => a * det (e f) – b * det(d f) + c * det(d e) (g h i) (h i) (g i) (g h) Function det(w x) is computed as; w * z – x * y (y z) (pA.X pA.Y 1) (pA.X2+pA.Y2 pA.Y 1) (pA.X2+pA.Y2 pA.X 1) mA = (pB.X pB.Y 1) mB= (pB.X2+pB.Y2 pB.Y 1) mC= (pB.X2+pB.Y2 pB.X 1) (pC.X pC.Y 1) (pC.X2+pC.Y2 pC.Y 1) (pC.X2+pC.Y2 pC.X 1) (-5.000 2.1962 1) (29.82329444 2.1962 1) (29.82329444 -5.0000 1) mA=(-4.000 2.6569 1) mB=(23.05911761 2.6569 1) mC=(23.05911761 -4.0000 1) ( 3.9161 -4.0000 1) (31.33583921 -4.0000 1) (31.33583921 3.9131 1) |mA| = -10.3038 |mB| = 41.2152 |mC| = -61.8228 pO.X = |mB|/|mA|/2 = -2 pO.Y = |mC|/|mA|/2 * -1 = -3
Gathering Initial Data
We now can determine the radius of the arc or circle with a distance from the points; pO to pB [ = 6.00000]. Please refer to the earlier article for information on Calculating Distancesbetween 2 coordinates.
Now we can talk about our location on this arc at pB and begin gathering data about our destination and the distance and time required to reach this random point pX.
We will need to know the starting angle of our position on the arc or circle also. We can calculate this using slopes, calculating angles is also covered in an earlier article. The slope between pO and pB = -2.82845 with θ = 109.47107500715°.
We know; Our location on the arc = -4.0000, 2.6569 The center point; = -3.0000,-2.0000 The radius of the arc: = 6.0000 The circumference: 2πr = 37.6991118431 The angle from pO to pB = 109.4710750°
Considering Rate Of Travel
Say we can travel along this arc at a rate of 0.34285 units per time sample, for now, we will count time samples in terms of calculations. For planning or reporting purposes we may need to be able to determine where would we be in calculation n+30?
We can calculate that our average distance covered in n+30 cycles as 0.34285*30 = 10.2855 units of movement along the circumference. Now we need to find the Cartesian (x,y) coordinates of this location.
We will need to know the angle between our start location and the end location, We can calculate this quickly using percentages; 10.2855 unit of movement covers 27.28313611951189% of the circumference of the implied circle. 27.28313611951189% of the full circle θ = 360° is the value of angle aX = θ = 98.2192900302428°.
Calculating Arc Length
Calculating the Arc Length between pB and pX can be accomplished utilizing the angle between lines lOB and lOX [θ = 98.2°]. Using the percentage value of 98.2°/360° we know that 27.3% of the circumference is covered which calculates to 10.29 units.
Calculating point pX coordinates
Polar Coordinates: (r, θ)
We can now rotate our position easily from the center point of the circle knowing the radius (r = 6.000) and our current angle (θ = 109.5). Using the angle of change above we can simply subtract this angle from the angle value of our new polar coordinates. Starting at our position at pB (6,109.5), we can now calculate our new polar coordinate as (6,109.5) – (6,98.2) = our new point pX = (6,11.3), this calculation also provides the value of angle aY = θ = 11.3°.
Cartesian Coordinate Conversion; (r, θ) -> (x,y)
To give us a Cartesian coordinate we will convert from the Polar coordinate (6,11.3) @ point pX. We will need the Sine and Cosine of the angle. You can use a calculator or you can read how to calculate sine and cosine by hand in the below sections. [See below for steps to calculate cosine(x)/sine(x)]
Calculating cos(191.3) yields -0.98061465854 and sin(191.3) = -0.19594614425
Our X coordinate can be derived from the following equation utilizing the cosine of our angle. The same ideal can be used to formulate the Y coordinate utilizing the sine of our angle.
cos(radians) = x/radius. This gives way to; x = radius[cos(radians)]. sin(radians) = y/radius => ; y = radius[sin(radians)] pX.x = 6 * 0.98061465961 = 5.88368795766 pX.y = 6 * 0.19594613887 = 1.17567683324
Please note that converting from Polar coordinates to Cartesian coordinates resets the origin to x=0,y=0. To obtain the true location of the pX we need to add the original origin point’s coordinates to our conversion values.
pX.x = 5.88368795766 + (-2.000) = 3.88368795766 [pX.X = pX.X + pO.X] pX.y = 1.17567683324 + (-3.000) = -1.82432316676 [pX.Y = pX.Y + pO.Y] Finally; pX.x = 3.88368795766 pX.y = -1.82432316676
Learning more about our arc and pathway.
Using the points pB and pX we can calculate the chord distance and angle using methods in the previous article.
The chord length of line lBX = 9.07169645 (half chord = 4.535848225) with an angle = 330.
To calculate the height or Sagitta of the arc;
Half chord^2 = 20.57391912023565 r^2 = 36 r^2 – half chord^2 = sumA = 15.42608087976435sqrt(sumA) = 3.927604980107387 r- sqrt(sumA) = Sagitta = 2.072395019892613
Calculating Factorials, Sine and Cosine
Factorials!
Before we can calculate the two values we need to be able to understand factorials expressed as x!. Calculate factorials following the pattern;
2! = 1*2 = 2 3! = 1*2*3 = 6 10! = 1*2*3*4*5*6*7*8*9*10 = 3,628,800
Power Series
Next, an infinite number series will be used where greater recursion yields more accurate results.
These series are called power series and will accept an angle measured in radians. For Sine the formula is ; sin(x) = x – x3/3! + x5/5! – x7/7! + x9/9! – ··· For Cosine the formula is ; cos(x) = 1 – x2/2! + x4/4! – x6/6! + x8/8! – ···
Pseudo code for Sine(x)
Result = x; O = True; C = 10 For I = 3 to C*2+3 step 2 If O Then Result -= sinX^I/I! ; O = False; ElseIF Not(O) Then Result += sinX^I/I! ; O = True; Next
Pseudo code for Cosine(x)
Result = 1;
O = True;
C = 10
For I = 2 to C*2+2 step 2
If O Then
Result -= cosX^I/I! ;
O = False;
ElseIF Not(O) Then
Result += cosX^I/I! ;
O = True;
Next
Example code in LiSP for calculating the center of an arc/circle based on three points on the arc/circumference;
We will use a couple of sub-functions, det2x2 and det3x3. Det3x3 will yield the determinate of a 3×3 matrix utilizing minors of the matrix. Det2x2 will yield the determinate of the 2×2 square matrix. The main function requires 3 points along an arc separated by pntX and pntY.
(defun det2x2(a b c d)
(- (* a d)(* b c))
)
(defun det3x3(a b c d e f g h i)
(+(- (* a (det2x2 e f h i)) (* b (det2x2 d f g i))) (* c (det2x2 d e g h)))
)
(defun CalcCirc3pnt(aX aY bX bY cX cY)
(setq aProd (+ (expt aX 2) (expt aY 2))
(setq bProd (+ (expt bX 2) (expt bY 2))
(setq cProd (+ (expt cX 2) (expt cY 2))
(setq tempA (det3x3 aX aY 1 bX bY 1 cX cY 1))
(setq tempB (det3x3 aProd aY 1 bProd bY 1 cProd cY 1))
(setq tempC (det3x3 aProd aX 1 bProd bX 1 cProd cX 1))
(setq tempB2 (/ (/ tempB tempA) 2) )
(setq tempC2 (* (/ (/ tempC tempA) 2) -1) )
(princ (strcat "CenterPoint : " (rtos tempB2 2 2) "," (rtos tempC2 2 2)))
)
To wrap up; To the right is a flowchart showing the how to calculate the center point of an arc or circle using three points.