查找圆上一点的 x/y 坐标的基本公式是:
X = 圆X + ( 圆半径 * 余弦( 角度 ) )
Y = 圆Y + ( 圆半径 * 正弦( 角度 ) )
其中circleX和circleY是圆中心的x/y坐标
//Math functions use radians so we will need to convert degrees to radians
var radPerDeg = Math.PI/180;
function genPoint(centerX,centerY,degree,radius){
var x = centerX + ( radius * Math.cos(degree*radPerDeg) );
var y = centerY + ( radius * Math.sin(degree*radPerDeg) );
var p = document.createElement("div");
p.style.left = x+"px";
p.style.top = y+"px";
document.body.appendChild(p);
}
for(var i=0; i<=180; i+=10){
genPoint(200,100,i,50);
}Run Code Online (Sandbox Code Playgroud)
div {
border-radius:5px;
width:5px;
height:5px;
background:#000;
position:absolute;
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1386 次 |
| 最近记录: |