本文介绍了我怎样画与像素任意方向像素的椭圆形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过像素绘制任意大小和方向像素的椭圆。它似乎pretty的容易绘制椭圆,其长轴和短轴对准x和y轴,而是通过以任意角度旋转的椭圆似乎棘手。起初,我虽然它可能工作绘制未旋转的椭圆和应用旋转矩阵的每个点,但它好像可能导致错误做四舍五入,我需要相当高precision。

I have to draw an ellipse of arbitrary size and orientation pixel by pixel. It seems pretty easy to draw an ellipse whose major and minor axes align with the x and y axes, but rotating the ellipse by an arbitrary angle seems trickier. Initially I though it might work to draw the unrotated ellipse and apply a rotation matrix to each point, but it seems as though that could cause errors do to rounding, and I need rather high precision.

时我怀疑这个方法是否正确?我怎么能完成这个任务更precisely?

Is my suspicion about this method correct? How could I accomplish this task more precisely?

我在C ++程序设计(尽管这应该没什么关系,因为这是一个更加面向算法的问题)。

I'm programming in C++ (although that shouldn't really matter since this is a more algorithm-oriented question).

编辑:大卫指出的那样,我想我可能真的不知道该怎么办像素插值

as David pointed out, I guess I may really be wondering how to do pixel interpolation.

推荐答案

使用:

x = X cos(a) - Y sin(a)
y = Y cos(a) + X sin(a)

其中, A 是逆时针旋转的角度,(X,Y)是新坐标,(X,Y)是旧的。

Where a is the angle of anticlockwise rotation, (x, y) are the new coordinates, and (X, Y) are the old.

您应该使用花车以preserve precision。刚刚经历的每一点,应用转换,就万事大吉了。

You should use floats to preserve precision. Just go through every point, apply the transformation, and voilà.

编辑:经过一番搜索,这里是微软的一些code:的,吸引光栅扫描圆锥曲线。

after some searching, here's some code from Microsoft: http://research.microsoft.com/en-us/um/people/awf/graphics/bres-ellipse.html that draws rastered conic sections.

这篇关于我怎样画与像素任意方向像素的椭圆形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:16