gpt4 book ai didi

javascript - 是否可以画一个包含婴儿床或棕褐色的完整圆圈?

转载 作者:行者123 更新时间:2023-11-30 13:48:20 25 4
gpt4 key购买 nike

我有这样的代码可以将多个点画成一个圆

    var cxt=c.getContext("2d");
var centerX = 500;
var centerY = 500;
cxt.moveTo(centerX, centerY);

var increment = 1/100;
var distance = 100;

for( theta=0;theta <100; theta++) {
var newX = centerX +distance *Math.cos(theta*2*Math.PI*increment);
var newY = centerY +distance *Math.sin(theta*2*Math.PI*increment);
cxt.fillText("0",newX, newY);
}
cxt.stroke();

结果:

enter image description here

我尝试用 tancot (1/tan) 重写代码,但我得到的通常是 eclipse 或椭圆形。我们可以使用这些函数从给定的点中做出一个完美的圆吗?

最佳答案

是的,这是可能的 - tan 就足够了 ( formulas here )

var cxt = c.getContext("2d");
var centerX = 100;
var centerY = 100;
cxt.moveTo(centerX, centerY);

var increment = 1 / 50;
var distance = 90;

for (let theta = 0; theta < 100; theta++) {
var t = Math.tan(theta * Math.PI * increment);
var newX = centerX + distance * (1 - t*t)/(1 + t*t);
var newY = centerY + distance * 2 * t/(1 + t*t);
cxt.fillText("0", newX, newY);
}
cxt.stroke();
<canvas id=c width=200 height=200></canvas>

关于javascript - 是否可以画一个包含婴儿床或棕褐色的完整圆圈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58841414/

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