Computer Graphics (ii) output graph element _6_opengl curve function _1_ Circle generation algorithm

Source: Internet
Author: User
Tags polyline square root

OpenGL curve Function
functions that generate basic curves such as circles and ellipses are not included in the OpenGL core library as primitive functions . However, the library includes the ability to display a Bezier spline, which is a polynomial defined by a set of discrete points . The OpenGL utility Library (GLU) contains three-dimensional surface functions, such as spherical and cylindrical surfaces, and functions for generating B-splines, which are a total of splines containing spline curves that simplify Bezier curves. We can use rational B-splines to display circles, ellipses, and other two-dimensional curves . In addition, the OpenGL Utility Kit (GLUT) has functions that can be used to display certain three-dimensional surfaces, such as spheres, cones, and other forms. However, all of these functions are more applied than the basic primitives described in this chapter, so we'll discuss this set of functions further in the 7th chapter.
We can also use polylines to approximate simple curves . You only need to determine the points on a set of curves and concatenate them into a set of straight segments. The more segments in a polyline, the smoother the curve. Figure 3.15 shows several of the polyline displays used to represent arcs.


The third option is to write your own curve generation function as shown below . First, a high-speed algorithm for generating circles and ellipses is discussed, and then a function for generating other two curves, polynomial, and spline curves is then seen.


Circle Generation algorithm

because circles are often used in graphics, functions that generate circles and arcs are included in most graphics software. These software also sometimes provide a general function that displays a variety of curves, including circles and ellipses.


Characteristics of the Circle

we define the circle as the set of all points from the center position (XC,YC) to the given value R (see Figure 3.16). For arbitrary dots (x, y), this distance relationship can be defined as the Pythagorean theorem in the Cartesian coordinate system

Using this equation, we can calculate the corresponding Y value from Xc-r to xc+r in the unit step along the x-axis to get the position of each point on the circumference:

But this is not the best way to create a circle. One problem with this approach is that each step contains a lot of computational weight. And, as shown in 3.17, the spacing between the painted pixel positions is inconsistent. We can adjust the spacing by swapping X and Y (that is, stepping y values and calculating x values) after the absolute value of the circle slope is greater than 1. However, this method increases the computational amount and process required by the algorithm.
Another way to eliminate the unequal spacing in Figure 3.17 is to use polar coordinates r and θ (see figure 3.16) to calculate points along the circumference.
The equations are expressed in the form of parametric polar coordinates, which can be obtained:




When you use the above method to generate a display result with a fixed angle of step, you can draw a circle by using an offset point along the circumference. To reduce the amount of computation, we can approximate the path of a circle by using a large angular interval between adjacent points and connecting the adjacent points with the segments. Set the angular interval to 1/r in the raster display to obtain a more contiguous boundary. The pixel position plotted in this way is approximately one unit apart. Although the polar coordinate system provides equidistant points, trigonometric calculations are time-consuming.
For any of these round generation algorithms, consideration of the symmetry of the circle can reduce the computational amount. The shape of the circle is similar in each quadrant. Therefore, if we determine the position of the circle in the first quadrant, you can generate the portion of the circle in the second quadrant of the XY plane, because the two arc segments are symmetrical for the y-axis. Considering the symmetry of the x-axis, arcs in the third and fourth quadrants can be obtained based on the arcs in the first and second quadrants. There is also symmetry between the eight of the circle, so it can be further refined, the adjacent eight circular arc in a quadrant is symmetrical for the 45-degree line that splits two parts. This symmetry can be found in Figure 3.18, where a point on the One-eighth circle (x, y) is mapped to the other seven eight-point points of the XY plane. This method takes advantage of the symmetry of the circle, and only calculates the points from x=0 to x = y segments to get all the pixel positions of the entire circle. In this eight-minute circle, the arc slope absolute value is less than or equal to 1.0. x = 0 O'Clock the slope of the circle is 0, and the slope of the circle when x = y is-1.0.

Using symmetry and equation (3.26) or equation (3.28) to determine the pixel position on the circumference still requires a lot of computational time. The flute Descartes equation (3.26) includes multiplication and square root operations, while the parametric equation contains multiplication and trigonometric operations. The more efficient circle algorithm is the same as the Bresenham line algorithm based on the incremental calculation of decision parameters, which only includes simple integer processing.
By setting the decision parameters that are closest to the circumference pixels in each sampling step, the Bresenham line algorithm of the grating system can be transplanted into the circle algorithm. However, the circular equation (3.26) is nonlinear, and the square root operation must be performed to calculate the distance between the pixel and the circle. The Bresenham circle algorithm avoids the square root operation by comparing the square of the distance between the pixel and the circle.
However, it is possible to directly compare distances without doing a square operation. The basic idea of this method is to test the middle position between two pixels to determine whether the midpoint is within or outside the circle boundary. This method is easier to apply to other conic sections, and for integer circle radii, the midpoint method generates the same pixel position as the Bresenham circle algorithm. And when using the midpoint test, the pixel position determined along any conic section curve is limited to 1/2 of the pixel interval.

Computer Graphics (ii) output graph element _6_opengl curve function _1_ Circle generation algorithm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.