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
2 Answers
Reset to default 6Power 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
版权声明:本文标题:math - Javascript: compute the radius of circle given center point and another point - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742261853a2442660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论