Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以使用Javascript在画布中的椭圆周长上等距绘制化身?_Javascript_Html5 Canvas - Fatal编程技术网

是否可以使用Javascript在画布中的椭圆周长上等距绘制化身?

是否可以使用Javascript在画布中的椭圆周长上等距绘制化身?,javascript,html5-canvas,Javascript,Html5 Canvas,我在画布上画一个椭圆没有问题,但是我怎么能在椭圆的周长上画出等距排列的项目(在我的例子中,最多8个玩家化身)?关键是将360°除以玩家数量,然后计算每个化身的角度,并使用余弦和正弦确定位置: const w=can.width=window.innerWidth; 常数h=can.height=window.innerHeight; const con=can.getContext(“2d”); 常数tau=Math.PI*2; //画布内的中心椭圆 常数cx=w/2, cy=h/2; 常数r

我在画布上画一个椭圆没有问题,但是我怎么能在椭圆的周长上画出等距排列的项目(在我的例子中,最多8个玩家化身)?

关键是将360°除以玩家数量,然后计算每个化身的角度,并使用余弦和正弦确定位置:

const w=can.width=window.innerWidth;
常数h=can.height=window.innerHeight;
const con=can.getContext(“2d”);
常数tau=Math.PI*2;
//画布内的中心椭圆
常数cx=w/2,
cy=h/2;
常数rx=w/2.5,
ry=rx*0.3;
con.beginPath();
con.椭圆(cx,cy,rx,ry,0,0,tau);
con.closePath();
con.stroke();
//示例:7个化身
常数总数=7;
对于(变量i=0;i
正文{
保证金:0;
}
#能{
显示:块;
高度:100vh;
}

假设cx,cy是中心,rx,ry是两个半径,椭圆上的一点是
cx+Math.cos(角度)*rx,cy+Math.sin(角度)*ry
其中角度在
[0;2*Math.PI]的范围内。
如果用“等间距”表示45°的角距离,这很简单;就圆周距离而言,“等间距”有点难。