How this code snippet works?

Revision en1, by Furcifer, 2015-10-19 22:05:24

This code snippet is from CP 3 by Steven Halim.This function takes 2 points on a circle and its radius and then calculates the center of the circle.Can someone explain the geometry behind? ~~~~~ **bool circle2PtsRad(point p1, point p2, double r, point &c) { double d2 = (p1.x — p2.x) * (p1.x — p2.x) + (p1.y — p2.y) * (p1.y — p2.y); double det = r * r / d2 — 0.25; if (det < 0.0) return false; double h = sqrt(det); c.x = (p1.x + p2.x) * 0.5 + (p1.y — p2.y) * h; c.y = (p1.y + p2.y) * 0.5 + (p2.x — p1.x) * h; return true; } ** ~~~~~

Tags geometry

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Furcifer 2015-10-19 22:08:11 74
en1 English Furcifer 2015-10-19 22:05:24 650 Initial revision (published)