## center from radius and two intersections

In part 1 of how-to-draw-circles given arbitrary details about them I discussed how to find a circle’s radius given the length of the arc & chord. Now what?

Well if you are given radius (r) and (x1,y1) and (x2,y2) as two points on the circle’s edge, you can calculate (cx, cy) the center of the circle. Once this information is aquired, you can construct the circle using any graphics rending method you choose.

Quite simple compared to finding the radius actually:

dx = x2 – x1

dy = y2 – y1

d2x = x2² – x1²

d2y = y2² – y1²

q = -dx / dy

s = (d2x + d2y) / (2 * dy)

a = 1 + q²

b = 2(s.q – q.y1 – x1)

c = x1² + y1² – 2.y1.s + s² – r²

cx = (-b +/- sqrt(b² – 4ac)) / (2a)

cy = s + q.cx

What if y1 equals y2 (i.e. dy is zero)?

Then: cy == y1 == y2 is true, and that means that cx = (y2 + y1) / 2.