开发者

Determine the centre/center of a circle using multiple points

I was wondering if somebody could help me, I can do it on pen and paper using a compass, but can't do it in Actionscript 3.

As the title says, essentially I need to find the centre of a circle using multipl开发者_运维知识库e points from the radius.


You want the Equation for a Circle from 3 Points. Dr. Math also has some nice explanations on your question.

Edit: I've implemented this in JavaScript + SVG; you can see the interactive result on my website:
http://phrogz.net/SVG/3-point-circle.xhtml

Here's the relevant code (I've created a Point class like in ActionScript with .x and .y properties):

function findCircleCenter(p1,p2,p3){
  var d2  = p2.x*p2.x + p2.y*p2.y;
  var bc  = (p1.x*p1.x + p1.y*p1.y - d2) / 2;
  var cd  = (d2 - p3.x*p3.x - p3.y*p3.y) / 2;
  var det = (p1.x-p2.x) * (p2.y-p3.y) - (p2.x-p3.x) * (p1.y-p2.y);
  if (Math.abs(det) > 1e-10) return new Point(
    (bc * (p2.y-p3.y) - cd * (p1.y-p2.y)) / det,
    ((p1.x-p2.x) * cd - (p2.x-p3.x) * bc) / det
  );
}

Edit 2: For fun, instead of 3 points defining one circle, how about 6 points defining 20? :)
http://phrogz.net/SVG/3-point-circle2.xhtml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜