在javascript中生成一系列描述弧线的点?

Jor*_*ren 0 javascript

我想使用 JS 生成一个半圆点,但不知道如何实现这一点。我会使用什么公式?使用我可以管理的公式。

Pat*_*ans 5

查找圆上一点的 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)