gpt4 book ai didi

javascript - 围绕圆画小线的数学

转载 作者:太空狗 更新时间:2023-10-29 15:31:20 26 4
gpt4 key购买 nike

我必须围绕一个圆圈画线(就像时钟一样)。我如何使用 for 循环实现此目的? alt text

最佳答案

我不确定如何在 Java 中实际绘制一条线,但要从中心点 (cx,cy) 计算坐标使用

px = cx+sin(a)*r
py = cy+cos(a)*r

a 是 Angular (以弧度为单位 - 我认为即 180 degress=π 弧度),r 是半径。

要在外部绘制小线,您需要使用半径为 100 和半径为 105 的公式,并在两组坐标之间绘制。

例如

for (var a=0,aMax=(2*Math.PI),aStep=(Math.PI/30); a<aMax; a+=aStep){
px1 = cx+Math.sin(a)*r;
py1 = cy+Math.cos(a)*r;
px2 = cx+Math.sin(a)*(r+5);
py2 = cy+Math.cos(a)*(r+5);

//draw line between (px1,py1) and (px2,py2)
};

关于javascript - 围绕圆画小线的数学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3810768/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com