 # [Solved] Compute the center of a circle given 2 points and radius

Given 2 points and radius, is there a function in the library to calculate the center of a circle or arc?
Googling references to this document and some code from
stackoverflow refers to this page but my there are multiple cases where the result is incorrect.

Here is the code I used to calculate the center of the arc

``````    /// calculate the center point this arc
fn center(&self) -> (Point, Point) {
let start = self.start;
let end = self.end;
let q = start.distance(&end);
let y3 = (start.y + end.y) / 2.0;
let x3 = (start.x + end.x) / 2.0;

let rr_q22 = (self.radius.powf(2.0) - (q / 2.0).powf(2.0)).sqrt();

let base_x = rr_q22 * (start.y - end.y) / q;
let base_y = rr_q22 * (end.x - start.x) / q;

let cx = x3 + base_x;
let cy = y3 + base_y;
let c1 = Point::new(cy, cy);

let cx = x3 - base_x;
let cy = y3 - base_y;
let c2 = Point::new(cy, cy);

(c1, c2)
}
``````

Solve: it’s just a typo on my code
let c2 = Point::new(cy cx, cy);