如何制作一个函数,该函数取圆的半径并返回一个在 OpenGL 坐标中绘制圆的点数组?

How do I make a function that takes in a radius of a circle and returns an array of points that draws a circle in OpenGL coordinantes?

提问人:Ned August 提问时间:11/5/2023 最后编辑:Rabbid76Ned August 更新时间:11/5/2023 访问量:25

问:

我有一个函数可以在画布坐标中为我画一个圆,但我找不到将这些坐标转换为 webgl 坐标的方法。这是我的功能:

function circlearray(diameter, accuracy) {
    const circle = [];
    let theta = 0;
    let dtheta = (2 * Math.PI) / accuracy;

    for (let i = 0; i < accuracy; i++) {
        circle.push([Math.cos(theta) * diameter, Math.sin(theta) * diameter]);
        theta += dtheta;
    }

    return circle;
}

精度基本上是一种告诉函数绘制一定数量的点的方法(出于性能或精度原因)

我试图将画布坐标转换为 webgl 坐标,但我找不到准确的方法:(

JavaScript 数组 数学

评论

1赞 LJᛃ 11/5/2023
NDC 空间是 -1 到 1,所以如果你的“直径”(实际上是半径)应该是像素,那么你必须分别除以 和。canvas.width / 2canvas.height / 2

答: 暂无答案