admin管理员组

文章数量:1334150

Suppose I have a circle with a center point at origin (0,0) and a 90deg point from it at (0,10)... from this 2 obvious points the radius of the circle would definitely be 10, right?

I researched that the formula of finding the radius based on center point and another point is:

Math.sqrt( ((x1-x2)*2)  + ((y1-y2)*2) )

but I'm getting a value of 4.47213595499958 instead of what I thought would be 10.

Can anyone teach me the correct formula I should use to make a perfect circle from a center point to another point?

Suppose I have a circle with a center point at origin (0,0) and a 90deg point from it at (0,10)... from this 2 obvious points the radius of the circle would definitely be 10, right?

I researched that the formula of finding the radius based on center point and another point is:

Math.sqrt( ((x1-x2)*2)  + ((y1-y2)*2) )

but I'm getting a value of 4.47213595499958 instead of what I thought would be 10.

Can anyone teach me the correct formula I should use to make a perfect circle from a center point to another point?

Share edited Jul 15, 2014 at 20:40 Dan Is Fiddling By Firelight 6,06118 gold badges80 silver badges131 bronze badges asked Apr 14, 2013 at 3:16 Chinchan ZuChinchan Zu 9185 gold badges20 silver badges40 bronze badges 3
  • Isn't 90deg (10,0)? I thought 0deg was pointing up. – Fabrício Matté Commented Apr 14, 2013 at 3:19
  • 1 Generally speaking, with cartesian systems the mon interpretation of zero degrees is pointing to the right – slebetman Commented Apr 14, 2013 at 3:23
  • @slebetman Yes I'm probably too sleepy.. with css3 gradients which just changed the vendor-prefixed 0deg pointing to the right to the now standard 0deg pointing up I'm probably mixing this with basic Cartesian plane as well. – Fabrício Matté Commented Apr 14, 2013 at 3:25
Add a ment  | 

2 Answers 2

Reset to default 6

Power in javascript is done by using Math.pow:

Math.sqrt( Math.pow((x1-x2), 2) + Math.pow((y1-y2), 2) )

In javascript, the * operator means multiply, not raise to the power. The correct formula should be:

Math.sqrt( ((x1-x2)*(x1-x2)) + ((y1-y2)*(y1-y2)) )

本文标签: mathJavascript compute the radius of circle given center point and another pointStack Overflow