光栅化椭圆

发布于 2024-12-27 09:26:18 字数 391 浏览 2 评论 0原文

是否有一种有效的算法来查找一般椭圆中的像素索引?

本质上,我想做的是在二维数组中找到对应于参数化椭圆的索引,该椭圆跨越可能的数组索引的“二维表面”。 正如我上面的第一个问题一样,这个问题可以与椭圆的光栅化进行比较。

我发现一些扫描线算法可以满足我对轴对齐椭圆的要求,但现在我想知道是否有类似的算法可以用于倾斜和旋转的椭圆。肯定存在,因为矢量图形软件能够填充倾斜和/或旋转的椭圆。

为了澄清我的意思,我最近在这里解决了一个类似的问题:二维数组中的特殊多边形 for 循环

/Nick

Is there a efficient algorithm out there to find the indicies of pixels in a general ellipse?

Essentially, what I want to do is to find the indicies in a two dimensional array that corresponds to a parameterized ellipse that spans over the "2-D surface" of possible array indicies.
This problem can, as in my first Q above, be compared to the rasterization of an ellipse.

I have found some Scan Line algorithms that do what I want for axis-aligned ellipses, but now I wonder if there are any similar ones for ellipses that are skewed and rotated. There must be since vector graphics SW out there manage to fill ellipses that are skewed and/or rotated.

To clearify what I mean, I recently had one similar question to this resolved here: Special polygonial for loop in two dimensional array

/Nick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

破晓 2025-01-03 09:26:18

您可以采用已找到的用于光栅化椭圆的算法,并简单地对坐标应用旋转或倾斜变换,然后测试它们是在椭圆内部还是外部。例如,如果您想测试旋转 45 度的椭圆,您可以执行以下操作:

for (x = 0; x < maxX; x++)
{
    for (y = 0; y < maxY; y++)
    {
        double newX, newY;
        Transform (x, y, rotationMatrix, &newX, &newY);
        if (PointInEllipse (newX, newY, ellipse))
        {
            ...do whatever here....
        }
    }
}

其中 Transform 只是将 2x2 旋转矩阵应用于 x 和 y,并将结果放入 newX、newY 中。

You can take the algorithms that you've found for rasterizing an ellipse and simply apply a rotation or skew transform to the coordinates before testing whether they're inside or outside the ellipse. For example, if you want to test for an ellipse rotated 45 degrees, you could do something like this:

for (x = 0; x < maxX; x++)
{
    for (y = 0; y < maxY; y++)
    {
        double newX, newY;
        Transform (x, y, rotationMatrix, &newX, &newY);
        if (PointInEllipse (newX, newY, ellipse))
        {
            ...do whatever here....
        }
    }
}

Where Transform simply applies a 2x2 rotation matrix to x and y and puts the result in newX, newY.

奶气 2025-01-03 09:26:18

我建议对椭圆进行三角测量并使用标准三角形填充例程,大多数图形 API 很可能都是这样做的,因为 OpenGL 和 DirectX 往往只能在一天结束时绘制三角形。

椭圆的简单三角剖分看起来就像披萨,只是向外缩放。如果您需要更高的质量,只需增加披萨的切片数量即可。

I would recommend triangulating your ellipse and using the standard triangle fill routines, odds are good that is how it is done by most graphics APIs, as OpenGL and DirectX tend to only be able to draw triangles at the end of the day.

A simple triangulation of an ellipse looks like a pizza except scaled outwards. If you need higher quality, you just up the number of slices in the pizza.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文