Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

How this code snippet works?

Правка en2, от Furcifer, 2015-10-19 22:08:11

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; }  
Теги geometry

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Furcifer 2015-10-19 22:08:11 74
en1 Английский Furcifer 2015-10-19 22:05:24 650 Initial revision (published)