javascript 试图围绕圆的边缘绘制坐标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13608186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trying to plot coordinates around the edge of a circle
提问by user1503606
I am trying to plot coordinates around a circle programmatically. Here it is hard-coded to show what I am after:
我正在尝试以编程方式围绕圆绘制坐标。这是硬编码以显示我所追求的内容:
var iteration = 4;
var left = [94,200,104,-6];
var top = [-6,94,200,94];
for(var i=0; i<iteration; i++){
$("#center").append("<div class='point' style='left:"+left[i]+"px;top:"+top[i]+"px'></div>");
}
Math is definitely not my strong point.
数学绝对不是我的强项。
I need to represent people as small Circles standing around a large circle. However, there will be random numbers of people and they all need to be equidistant. I'm not sure whether I should be working from a central point.
我需要将人们表示为站在大圆圈周围的小圆圈。然而,会有随机数量的人,他们都需要等距。我不确定我是否应该从一个中心点开始工作。
回答by John Ledbetter
Assuming that (x0, y0)
is the center of your circle, and r
is the radius:
假设这(x0, y0)
是圆的中心,r
是半径:
var items = 4;
for(var i = 0; i < items; i++) {
var x = x0 + r * Math.cos(2 * Math.PI * i / items);
var y = y0 + r * Math.sin(2 * Math.PI * i / items);
$("#center").append("<div class='point' style='left:"+ x +"px;top:"+ y +"px'></div>");
}