Drawing Circle
Given an image with width and height . Then any pixel in the image satisfies that , , and , are integers.
Let be the circle of radius with center at
Let , we can obtain
Furthermore,
in which is the rounding operation.
Since we are drawing the circle of the formula in a discrete space, the allowing error is , then it gets
Let , combine with formula , we can obtain 4 points in the space , i.e.
They divide the circle into four arcs in counter-clockwise direction, i.e. , , , .
Now let us consider arc , we know that , according to formula , it has
in which
and is the rounding operation.
Formula determine all the edge points(pixels) in the arc .
Notice that is symmetric to with respect to the straight line , is symmetric to with respect to the center , and is symmetric to with respect to the straight line , then it can determine all the edge points of the other three arcs on the basis of formula .
Explicitly, for an arbitrary point in the arc , then is on the arc , is on the arc , and is on the arc , in which
it’s obvious that these four arcs form a complete circle.
Suppose we plot a black circle in a white background image. Next, we need to deal with the anti-aliasing problem. We have discussed that the circle is symmetrical, so it only have to settle the staircase artifact of the arc , and the other three will be resolved in the same way.
And the arc is determined by . Let and denote the arcs determined by the formulas of and respectively. Moreover, is symmetric to with respect to the straight line .
We will see that arc consists of vertical straight line segments.
For
we obtain the following straight line segment
Let , , , in which is an arbitrary point in the straight line segment .
For an arbitrary pixel in the image, its color was denoted by (Notice: We only discuss the three channels image here).
In order to settle the staircase artifact, we need to find a proper color of and which make the transition between the circle and the white background more smooth.
We set be the background color (white) and be the front color (black), then is a black pixel.
Here, we give a simple solution, we just let .
Asserstion 1:
Arc and arc consist of vertical straight line segments respectively.
Assertion 2:
Arc and arc consist of horizontal straight line segments respectively.
By the symmetrical of the circle, we just need to consider arc . And if we can proof that consists of vertical straight line segments, then the above assertions are correct.
Assertion 3:
Arc is make up of vertical straight line segments.
Given two adjacent straight line segments of arc which are determined by as follow
if we can verify , then the assertion 3 is correct.
Let
Define the difference value as follow:
According to formula , it gets
where .
Then we have
Let
it is easy to show that is monotonic increasing, then
in which , combine formula , and if , we obtain
Hence, for any .
Let , , ,, if , then the circle is formed by these four points.
It is obivious that and is connected by point , and joint the four arcs together, so it have formed a complete circle.
Done !
Elliptic Curve
I just want to show the elliptic curve here.
in which
本文链接: https://spongedog20.github.io/2019/12/17/draw-circle/
版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!