作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这样的代码可以将多个点画成一个圆
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();
结果:
我尝试用 tan
和 cot (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/
我是一名优秀的程序员,十分优秀!