The invention relates to graphic processing, and particularly relates to a method and apparatus for approximating a curve and a graphic display control method and apparatus.
In computer graphics applications, rendering characters is an important branch. Two-dimensional characters are generally formed by quadratic Bezier curves, cubic Bezier curves, and elliptical curves etc., in a two-dimensional plane.
It is inefficient, for a Graphics Display Controller (GDC) chip, to render curves pixel by pixel by tracking along the curves. With appropriate precision, it is reasonable to approximate a curve with straight lines. It is a tradeoff between precision and speed. For many applications of GDC chips, speed overwhelms precision, such as car navigation, mobile phone, and amusement displayer.
Approximating a curve with straight lines needs to firstly subdivide the curve with subdividing points, then calculate coordinates of the subdividing points, and finally connect adjacent subdividing points via straight lines. It is a long existing problem to approximate a curve. There exist many solutions to approximate Bezier curves, such as direct method, recursive subdivision, forward differencing, and hybrid method. However, these methods are not fast enough.
As Bezier curves are commonly represented by polynomials of parameter t (for example, x(t)=a·t2+b·t+c, y(t)=d·t2+e·t+f for quadratic Bezier curve, where the coefficients a, b, c, d, e, and f can be calculated by control points of the quadratic Bezier curve), the coordinate values of each subdividing point can be calculated directly, given the parameter t at each subdividing point. Although this method is simple and direct, it needs too many multiplications for each subdividing point.
Recursive subdivision is a recursive procedure, to find step by step subdividing points by calculating the middle points on each edge of a control polygon. Connecting adjacent subdividing points will form straight lines. Setting an appropriate threshold of flatness, the straight lines will approximate a curve with reasonable precision. However, the recursive procedure and calculating flatness will take a large amount of time.
Forward differencing is suitable for Bezier curves. The coordinate values of a next subdividing point can be got by adding the coordinate values of a previous subdividing point with difference values. With a fixed step, the coordinate values of each subdividing point can be calculated by just several addition operations. Therefore, the speed is very high. However, the number of the subdividing points (i.e. the step) needs to be determined before calculating the coordinates.
The hybrid method combines recursive subdivision and forward differencing together. It first uses recursive subdivision and flatness to obtains the parameter of each subdividing point, and then uses forward differencing to calculate the coordinate values of each subdividing point. This method is complex for implementation.
Therefore, a method and/or apparatus for approximating a curve, used in curve rendering and more efficient than the abovementioned methods, are needed.
In view of one or more of the above problems, this invention proposes a method and apparatus for approximating a curve and a graphic-display control method and apparatus.
The method for approximating a curve according to an aspect of the invention, comprising the steps of: acquiring number information of subdividing points for subdividing a curve needed to be approximated based on coordinate information of control points of the curve; acquiring coordinate information of the subdividing points based on the number information of the subdividing points and the coordinate information of the control points; and connecting the subdividing points with straight lines based on the coordinate information of the subdividing points.
The apparatus for approximating a curve according to another aspect of the invention, comprising: a number acquiring unit configured to acquire number information of subdividing points for subdividing a curve needed to be approximated based on coordinate information of control points of the curve; a coordinate acquiring unit configured to acquire coordinate information of the subdividing points based on the number information of the subdividing points and the coordinate information of the control points; and a curve approximating unit configured to connect the subdividing points with straight lines based on the coordinate information of the subdividing points.
The graphic-display control method according to still another aspect of the invention, comprising the steps of: acquiring number information of subdividing points for subdividing a curve needed to be approximated based on coordinate information of control points of the curve; acquiring coordinate information of the subdividing points based on the number information of the subdividing points and the coordinate information of the control points; and connecting the subdividing points with straight lines based on the coordinate information of the subdividing points and drawing the straight lines connecting the subdividing points according to rendering parameters.
The graphic-display control apparatus according to still another aspect of the invention, comprising: a number acquiring unit configured to acquire number information of subdividing points for subdividing a curve needed to be approximated based on coordinate information of control points of the curve; a coordinate acquiring unit configured to acquire coordinate information of the subdividing points based on the number information of the subdividing points and the coordinate information of the control points; and a curve rendering unit configured to connect the subdividing points with straight lines based on the coordinate information of the subdividing points and draw the straight lines connecting the subdividing points according to rendering parameters.
To sum up, the invention achieves efficient curve approximation and efficient graphic-display control by acquiring the number information of the subdividing points for subdividing a curve by means of using the coordinate information of the control points of the curve, acquiring the coordinate information of the subdividing points according to the number information of the subdividing points and the coordinate information of the control points.
The invention can be easily understood from the following description of the preferred embodiments of this invention in conjunction with the drawings, in which
Features in respective aspects and exemplary embodiments of the invention will be described in detail below. In the following detailed description, a number of specific details are proposed to provide thorough understanding of the invention. However, it is obvious to those skilled in the art that the invention can be implemented without some of the specific details. The following descriptions of the embodiments are merely to provide better understanding of the invention by illustrating examples of the invention. The invention is not limited to any specific configuration and algorithm mentioned below, and covers any modification, substitution and improvement of the elements, components and algorithms without departing from the spirit of the invention. In the figures and the following description, well-known structures and techniques are not disclosed to avoid unnecessarily obscuring the invention.
The parametrical equation of the quadratic Bezier curve is
x(t)=(1−t)2x0+2t(1−t)x1+t2x2
y(t)=(1−t)2y0+2t(1−t)y1+t2y2 (1)
where 0≦t≦1. The parametrical equation of the quadratic Bezier curve can be set as another form:
x(t)=aqxt2+bqxt+cqx
y(t)=aqyt2+bqyt+cqy (2)
where aqx=x2−2x1+x0, bqx=2(x1−x0), cqx=x0, aqy=y2−2y1+y0, bqy=2(y1−y0), and cqy=y0.
The parametrical equation of the cubic Bezier curve is
x(t)=(1−t)3x0+3t(1−t)2x1+3t2(1−t)x2+t3x3
y(t)=(1−t)3y0+3t(1−t)2y1+3t2(1−t)y2+t3y3 (3)
where 0≦t≦1. The parametrical equations of the cubic Bezier curve can also be set as another form:
x(t)=acxt3+bcxt2+ccxt+dcx
y(t)=acyt3+bcyt2+ccyt+dcy (4)
wherein acx=x3−3x2+3x1−x0, bcx=3x2−6x1+3x0, ccx=3x1−3x0, dcx=x0, acy=y3−3y2+3y1−y0, bcy=3y2−6y1+3y0, ccy,=3y1−3y0 and dcy=y0.
The parametrical equation of the elliptical curve is
where θ is the parameter of any point on the elliptical curve, and rot is the rotation angle of the elliptical curve relative to the coordinate system. The elliptical curve can be regarded as a result of affine transforming a unit circle (cos θ, sin θ).
The area difference ΔA between the area of a curve segment corresponding to a subdividing step Δt with respect to X coordinate axis and the area of a line segment between two points corresponding to the subdividing step on the curve with respect to X coordinate axis can be obtained by the following expression:
ΔA=A−Aa, (6)
where A is the area of the curve segment corresponding to Δt with respect to X coordinate axis, and Aa is the area of the line segment between two end points on the curve segment with respect to X coordinate axis.
If the curve segment is part of the quadratic Bezier curve, then there exist the following equations
Therefore, the area difference between the area of the curve segment corresponding to Δt with respect to X coordinate axis and the area of the line segment between the two points on the curve segment corresponding to the subdividing step with respect to X coordinate axis is
As can be seen from the above expression, the area difference has no relationship with the parameter t, but with Δt. If ΔA is set to a threshold T, (5 pixels, for example), Δt can be obtained by the following expression:
If the curve segment is part of the cubic Bezier curve, then there exist the following equations:
As Δt is between (0,1] under general conditions, two items Δt5Δt4 can be omitted, then the above mentioned equation (13) becomes
If the maximum value of
can be obtained, then the abovementioned equation (14) will be
ΔA≈Cmax·Δt3 (15)
As in general cases, the scope of t is [0.0,1.0], to find the maximum value of C(t) is to find the maximum value of among t=0.0, t=1.0 and
These three values are
Therefore,
C
max=max(valt=0,valt=1,valt=−M/(2L)) (17)
Finally, if ΔA is set to a threshold T (5 pixels, for example), then the following expression will be gotten:
If the curve segment is part of the elliptical curve, which is centered at the original point of the coordinate system, and has no rotation relative to X coordinate axis, then there exist the following equations:
The absolute value of ΔA is
Finally, if ΔA is set to a threshold T, (5 pixels, for example), then
After the subdividing step Δt is obtained, the number of the subdividing points can be obtained by the following expression:
n=int(1/Δt)+1 (24)
As the elliptical curve can be obtained by affine transforming a unit circle curve, coordinate information of the subdividing points can be calculated on the unit circle curve. As the number n of the subdividing points has already been obtained and the angle of the circular arc on the unit circle curve corresponding to the elliptical curve is θ1−θ0 all, the angle difference between two adjacent subdividing points on the circular arc of the unit circle is (θ1−θ0)/n . From θ0 to θ1, the coordinates of each subdividing point on the circular arc are calculated according to x=cos θ and y=sin θ. Herein, the number of subdividing points on the circular arc of the unit circle is the same as that of the elliptical curve.
P
t+Δt=Pt+ΔPt (25)
If Pt+Δt is treated as parameter equations, then
x(t+Δt)=x(t)+Δx(t)
y(t+Δt)=y(t)+Δy(t) (26)
If the curve is a quadratic Bezier curve, then
Δx(t)=2(X1−X0)Δt·t+(X1−X0)Δ2t+2X0Δt
Δy(t)=2(Y1−Y0)Δt·t+(Y1−Y0)Δ2t+2Y0Δt (27)
where X0=x1−x0, Y0=y1−y0, X1=x2−x1, and Y1=y2−y1.
Δx(t+Δt)=Δx(t)+Δ2x(t)
Δy(t+Δt)=Δy(t)+Δ2y(t) (28)
So,
Δ2x(t)=Δ(Δx(t))=2(X1−X0)Δ2t
Δ2y(t)=Δ(Δy(t))=2(Y1−Y0)Δ2t (29)
If the curve is defined in iterative terms xn+1=xn+Δxn, Δxn=Δxn−1+Δ2xn−1, and yn+1=yn+Δyn, yn+1=yn+Δyn, then xn+1 and yn+1 can be obtained in an iterative way.
The coordinate values of the first subdividing point, Δx and Δy between the second and first subdividing points can be obtained by substituting the value of t on the first subdividing point into the expressions (1) and (27) respectively. Herein, the value of t can be, for example, 0.
If the curve is a cubic Bezier curve, then
Δx(t)=3AxΔt·t2+3(AxΔ2t+2BxΔt)t+(AxΔ3t+3BxΔ2t+3CxΔt)
Δy(t)=3AyΔt·t2+3(AyΔ2t+2ByΔt)t+(AyΔ3t+3ByΔ2t+3CyΔt) (30)
where Ax=(X2−X1)−(X1−X0), Bx=(X1−X0), Cx=X0, X2=x3−x2, Ay=(Y2−Y1)−(Y1−Y0), By=(Y1−Y0), Cy=Y0 and Y2=y3−y2.
Likewise,
Δ2x(t)=Δ(Δx(t))=6AxΔ2t·t+6AxΔ3t+6BxΔ2t
Δ2y(t)=Δ(Δy(t))=6AyΔ2t·t+6AyΔ3t+6ByΔ2t (31)
and
Δ3x(t)=Δ(Δ2x(t))=6AxΔ3t
Δ3y(t)=Δ(Δ2y(t))=6AyΔ3t (32)
If the curve is defined in iterative terms xn+1=xn+Δxn, Δxn=Δxn−1+Δ2xn−1, Δ2xn−1=Δ2xn−2+Δ3xn−2, and yn+1=yn+Δyn, yn+1=yn+Δyn, Δ2yn−1=Δ2yn−2+Δ3yn−2, then xn+1 and yn+1 can be calculated in an iterative way. Likewise, the coordinate values of the first subdividing point, Δx and Δy between the second and first subdividing points, and Δ2x and Δ2y between the second and first subdividing points can be obtained by substituting the value of t on the first subdividing point into the expressions (3), (30) and (31) respectively. Herein, the value of t on the first subdividing point can be, for example, 0.
x=rh·cos(rot)·cos θ−rv·sin(rot)·sin θ+xc
y=rh·sin(rot)·cos θ+rv·cos(rot)·sin θ+xc (33)
To sum up, the invention acquires the number information of subdividing points for subdividing a curve by using coordinate information of control points of the curve, and then acquires coordinate information of the subdividing points according to the number information of the subdividing points and the coordinate information of the control points, thereby achieving high efficient curve approximation and further high efficient graphic-display control.
What needs to be noted is that respect modules and/or units shown in
Those skilled in the art will understand that there exist more optional embodiments and modifications for implementing the embodiments of this invention, and the above-mentioned embodiments and examples are only descriptions of one or more embodiments. Therefore, the scope of this invention is restricted only by the claims attached.
Number | Date | Country | Kind |
---|---|---|---|
200910142113.4 | May 2009 | CN | national |