Background technology
To same vector graphics multiple mathematical description can be arranged, with the elliptic arc is example, the elliptic arc of software drafting all is that promptly the major axis of elliptic arc or minor axis are parallel to the x axle or the y axle (being designated hereinafter simply as the elliptic arc of standard) of rectangular coordinate system respectively not through the elliptic arc of rotation generally speaking.As shown in Figure 1, the parameter of describing a standard ellipse arc has: and the coordinate of the top left corner apex of transverse length a, ellipse short shaft length b, oval circumscribed rectangle (x, y), the start angle α of elliptic arc and the angle β of elliptic arc start angle and termination point.
The standard ellipse arc has been owing to set up mathematical model, thus can access the coordinate of each point on the elliptic arc, and then finish the drafting of camber line.Specifically, the mathematical model of complete ellipse has been arranged at present, has comprised ripe elliptic equation:
Wherein, (x0 y0) is the oval center of circle, and a is oval transverse axis, and b is the oval longitudinal axis.According to this equation, can determine each point coordinate on the standard ellipse, the angle of the start angle of combined standard elliptic arc and start angle and termination point again, each point coordinate on the elliptic arc that can settle the standard, and then on display screen, draw this standard ellipse arc.
Yet in many cases, the elliptic arc that the user need draw not is to be standard, but has certain anglec of rotation.That is to say that the ellipse of ellipse of revolution arc correspondence is an ellipse of revolution, its major axis and minor axis also are not parallel to the x axle and the y axle of rectangular coordinate system, but form certain angle with x axle and y axle, are called the anglec of rotation.
As in SVG (but vector graphics of scaling), just there is the ellipse of revolution arc that forms certain angle with the x axle.The characterising parameter of elliptic arc is: rx, ry, x-axis-rotation, large-arc-flag, sweep-flag, x1, y1, x2, y2.Wherein, x-axis-rotation is the anglec of rotation, promptly is the x axle of ellipse at this section arc place and the angle of horizontal direction; Rx is oval semi-major axis length; Ry is oval semi-minor axis length; Large-arc-flag and sweep-flag have determined the drafting direction of elliptic arc, and value is 0 or 1, and large-arc-flag is 1 expression wide-angle camber line, are 0 to represent the low-angle camber line; Sweep-flag be 1 the representative from the origin-to-destination camber line around the elliptical center clockwise direction, be 0 represent the counter clockwise direction; X1, y1 are starting point coordinates, and x2, y2 are terminal point coordinates.
For example, elliptic arc starting point A as shown in Figure 2, terminal point B, semi-major axis a, semi-minor axis b, the anglec of rotation is r (a scope 0-180 degree), large-arc-flag is 1: get orthodrome, sweep-flag is 0: counterclockwise (draw counterclockwise from A to B).
Elliptic arc starting point A as shown in Figure 3, terminal point B, major axis a, minor axis b, the anglec of rotation is r (a scope 0-180 degree), large-arc-flag is 1: get orthodrome, sweep-flag is 1: clockwise direction (drawing clockwise from A to B).
Owing to do not have the mathematical model of moulding at present for ellipse of revolution, the formula that does not also have corresponding ellipse of revolution, so software can't directly obtain each point coordinate on the ellipse of revolution, thereby can't directly draw the ellipse of revolution arc, can only draw major axis or minor axis (is the transverse axis and the longitudinal axis, can transverse axis be major axis, also can minor axis be major axis) the standard ellipse arc parallel with transverse axis.In addition,,, and then draw the ellipse of revolution arc, will reduce the render speed of ellipse of revolution arc if pass through to calculate the equation of ellipse of revolution because the calculating of ellipse of revolution is very complicated.
Summary of the invention
The technical matters that the present invention mainly solves provides a kind of method for drafting of ellipse of revolution arc, makes software can pass through less operand, and is easy and draw the ellipse of revolution arc apace.
In order to solve the problems of the technologies described above, the invention provides a kind of method for drafting of ellipse of revolution arc, comprise following steps:
The ellipse of revolution of ellipse of revolution arc correspondence is decomposed into standard ellipse and this standard ellipse is transformed into the required transformation matrix of this ellipse of revolution, and the major axis or the minor axis of described standard ellipse are parallel to transverse axis;
Determine each point coordinate of described ellipse of revolution arc correspondence on described standard ellipse, each corresponding on described standard ellipse point coordinate is combined with described transformation matrix, obtain each point coordinate on the ellipse of revolution arc;
According to each point coordinate on the described ellipse of revolution arc, on display screen, draw described ellipse of revolution arc.
As improvement of the technical scheme, described ellipse of revolution with ellipse of revolution arc correspondence is decomposed in the step of standard ellipse and transformation matrix, can comprise following substep:
A obtains the parameter of ellipse of revolution arc to be drawn, and comprises semi-major axis length, the semi-minor axis length of the ellipse of revolution of starting point coordinate, terminal point coordinate, this ellipse of revolution arc correspondence, the anglec of rotation of this ellipse of revolution arc;
B determines the standard ellipse of described ellipse of revolution arc correspondence according to described starting point coordinate, terminal point coordinate and semi-major axis length, semi-minor axis length;
C determines the conversion starting point and the conversion terminal point of described ellipse of revolution arc correspondence on described standard ellipse according to the anglec of rotation of described ellipse of revolution arc, the starting point coordinate and the terminal point coordinate of described ellipse of revolution arc;
D determines that according to the origination data of the described anglec of rotation, described ellipse of revolution arc and/or original equipment manufacturer coordinate, corresponding conversion starting point and/or conversion terminal point coordinate on described standard ellipse described standard ellipse is transformed to the required transformation matrix of described ellipse of revolution.
As improvement of the technical scheme, among the described step B, comprise following substep:
With described origination data coordinate, original equipment manufacturer coordinate and semi-major axis length, semi-minor axis length substitution elliptic equation
Try to achieve the central coordinate of circle of described standard ellipse, determine the elliptic equation of described standard ellipse.
As improvement of the technical scheme, the central coordinate of circle of described standard ellipse can for:
y
0=A+Bx
0Perhaps,
y
0=A+Bx
0;
Wherein,
C=b
2+a
2B
2;D=-2a
2(y
1-A)B-2b
2x
1;E=a
2(y
1-A)
2+b
2x
1 2-a
2b
2;
The parameter of described ellipse of revolution arc can also comprise: the camber line size indicates, and being used to indicate described ellipse of revolution arc is wide-angle camber line or low-angle camber line; Draw hand designations, the origin-to-destination that is used to indicate described ellipse of revolution arc is a clockwise direction or counterclockwise;
Indicate and described drafting hand designations unique central coordinate of circle of determining described standard ellipse among the described step B according to described camber line size.
As improvement of the technical scheme, among the described step C, can comprise following substep:
Origination data coordinate and original equipment manufacturer coordinate according to described ellipse of revolution arc are determined straight line, and this straight line is rotated counterclockwise, and the angle of rotation is the anglec of rotation of this ellipse of revolution arc;
With postrotational straight line under the constant situation of slope, intersect with standard ellipse, the profound length that intersects 2 formations equals the profound length that described ellipse of revolution arc origination data coordinate and original equipment manufacturer coordinate constitute, and described crossing 2 be the conversion starting point and the conversion terminal point of described ellipse of revolution arc correspondence on described standard ellipse.
As improvement of the technical scheme, equal in the profound length of described intersection point under the condition of the profound length that described ellipse of revolution arc origination data coordinate and original equipment manufacturer coordinate constitute, if the straight line that intersects with described standard ellipse is more than one, then according to the anglec of rotation of described ellipse of revolution arc, select wherein described crossing straight line, unique conversion starting point and conversion terminal point of determining described ellipse of revolution arc correspondence on described standard ellipse.
As improvement of the technical scheme, among the described step D, can comprise following substep: the transformation matrix between described standard ellipse and the described ellipse of revolution is
Wherein, tx is the coordinate figure that moves horizontally, and ty is the coordinate figure of vertical moving, and a is the anglec of rotation of described ellipse of revolution arc;
Described conversion starting point or conversion terminal point are rotated a angle along initial point, obtain postrotational conversion starting point coordinate or postrotational conversion terminal point coordinate, the origination data coordinate or the original equipment manufacturer coordinate of described ellipse of revolution arc are deducted this postrotational conversion starting point coordinate or postrotational conversion terminal point coordinate, obtain the coordinate figure tx that moves horizontally between described standard ellipse and the ellipse of revolution and the coordinate figure ty of vertical moving.
As improvement of the technical scheme, the parameter of described ellipse of revolution arc also comprises: the camber line size indicates, and being used to indicate described ellipse of revolution arc is wide-angle camber line or low-angle camber line; Draw hand designations, the origin-to-destination that is used to indicate described ellipse of revolution arc is a clockwise direction or counterclockwise;
In the step of described definite ellipse of revolution arc each corresponding point coordinate on described standard ellipse, can indicate and described drafting hand designations according to the conversion starting point of determining among the standard ellipse of determining among the described step B, the described step C and conversion terminal point, described camber line size, obtain each point coordinate of described ellipse of revolution arc correspondence on described standard ellipse.
Embodiment of the present invention compared with prior art, the key distinction and effect thereof are: the present invention has utilized the mathematical model of existing standard ellipse, the ellipse of ellipse of revolution arc correspondence is decomposed into standard ellipse+transformation matrix, the elliptic equation of the standard ellipse by correspondence, determine each point coordinate of ellipse of revolution arc correspondence on this standard ellipse, again these coordinates are combined with transformation matrix, obtain each point coordinate on the ellipse of revolution arc, under the prerequisite of the mathematical model that need not to set up ellipse of revolution, by less operand, finish the drafting of ellipse of revolution arc, method for drafting is easy and consume system resources is few.
Embodiment
For making the purpose, technical solutions and advantages of the present invention clearer, embodiments of the present invention are described in further detail below in conjunction with accompanying drawing.
First embodiment of the invention relates to a kind of method for drafting of ellipse of revolution arc.Present embodiment is an example with the ellipse of revolution arc among the SVG, concrete method for drafting is described, as shown in Figure 4.
Step 401, obtain the parameter value of ellipse of revolution arc to be drawn, comprise starting point coordinate A (x1, y1), terminal point coordinate B (x2, y2), semi-major axis (transverse axis) the length a of the ellipse of revolution of this ellipse of revolution arc correspondence, semi-minor axis (longitudinal axis) length b, the anglec of rotation α of this ellipse of revolution arc (promptly is the transverse axis of this ellipse of revolution and the angle of transverse axis, oval transverse axis is rotated counterclockwise by transverse axis and obtains then being positive-angle, clockwise rotate and obtain then being negative angle), the camber line size indicates large-arc-flag, large-arc-flag is 1 expression wide-angle camber line, is 0 to represent the low-angle camber line; Draw hand designations sweep-flag, sweep-flag is that 1 representative is drawn around the elliptical center clockwise direction from the origin-to-destination camber line, is that 0 representative is counterclockwise drawn around elliptical center from the origin-to-destination camber line.Need to prove that in the present embodiment, the anglec of rotation is the angle of transverse axis and transverse axis, but in concrete the application, different according to definition, the anglec of rotation also can be the angle of angle, transverse axis and Z-axis of angle, the longitudinal axis and the Z-axis of the longitudinal axis and transverse axis.
Step 402 according to starting point coordinate A, terminal point coordinate B and semi-major axis length a, semi-minor axis length b, is determined the standard ellipse of ellipse of revolution arc correspondence, and the anglec of rotation of standard ellipse is zero, as shown in Figure 5.
Specifically, general standard ellipse arc has had mathematical model, standard ellipse equation formula:
The mode of drawing the standard ellipse arc can be the standard ellipse formula of the elliptic arc correspondence that settles the standard, and according to this formula, can obtain the oval coordinate of going up each point, in conjunction with the starting point and the terminal point of elliptic arc, just can determine this standard ellipse arc again.Yet, so in the present embodiment, need the ellipse of revolution of this ellipse of revolution arc correspondence is converted to standard ellipse+transformation matrix because the ellipse (being the ellipse that there are certain angle in transverse axis and transverse axis) of rotation does not have mathematical model.
In this step, under the constant situation of semi-major axis length a, semi-minor axis length b, according to known starting point coordinate A and the terminal point coordinate B ellipse that settles the standard.
Basic elliptic equation formula:
Terminal A and B brought into obtain:
(2)-(1) obtain:
b
2(x
2 2-x
1 2)+2b
2x
0(x
1-x
2)+a
2(y
2 2-y
1 2)+2a
2y
0(y
2-y
2)=0
Order:
y
0=A+Bx
0????(3)
(3) substitution (1) is obtained:
b
2(x
1-x
0)
2+a
2(y
2-A+Bx
0)
2-a
2b
2=0
b
2(x
1 2-2x
1x
0+x
0 2)+a
2((y
1-A)
2-2(y
1-A)Bx
0+B
2x
0 2)-a
2b
2=0
b
2x
1 2-2b
2x
1x
0+b
2x
0 2+a
2(y
1-A)
2-2a
2(y
1-A)Bx
0+a
2B
2x
0 2-a
2b
2=0
Order: C=b
2+ a
2B
2D=-2a
2(y
1-A) B-2b
2x
1E=a
2(y
1-A)
2+ b
2x
1 2-a
2b
2, obtain:
Cx
0 2+Dx
0+E=0
Use radical formula:
Ax
2+ bx+c=0 radical formula:
Solve an equation: Cx
0 2+ Dx
0+ E=0
:
Substitution (3) y
0=A+Bx
0
Try to achieve y
0
So just determined oval central coordinate of circle, one has 2 satisfactory central coordinate of circle, is respectively:
Wherein,
C=b
2+a
2B
2;D=-2a
2(y
1-A)B-2b
2x
1;E=a
2(y
1-A)
2+b
2x
1 2-a
2b
2。
Indicate large-arc-flag and draw hand designations sweep-flag according to the camber line of ellipse of revolution arc size then, determine adopt which value as the center of circle:
Suppose that two centers of circle determining are respectively θ 1, θ 2, as shown in Figure 6.Calculate respectively
The angle of (to be positive dirction counterclockwise) is α 1, and α 2, can draw α 1 according to the principle of similitude, and 2 two angle additions of α equal 360 degree.
Below divide the situation discussion:
|
??α1>α2 |
??α2>α1 |
Orthodrome is counterclockwise |
??θ1 |
??θ2 |
Orthodrome is clockwise |
??θ2 |
??θ1 |
Little circular arc is counterclockwise |
??θ2 |
??θ1 |
Little circular arc is clockwise |
??θ1 |
??θ2 |
Table 1
The parameter and the table 1 of this elliptic arc are compared, can be unique determine the center of circle of this standard ellipse, and then the ellipse formula of unique this standard ellipse of affirmation.
In step 403,, determine the conversion starting point A ' and the conversion terminal point B ' of this ellipse of revolution arc correspondence on this standard ellipse according to the anglec of rotation of this ellipse of revolution arc.
Specifically, the standard ellipse that obtains in the step 402 is that ellipse of revolution oppositely reverses α (anglec of rotation of ellipse of revolution arc) and obtains, yet as can be seen from Figure 5, this ellipse of revolution reverses in the process of standard ellipse, and being not is along the oval center of circle or certain point of fixity rotates.
Though ellipse of revolution is not around the fixing rotation of certain point to standard ellipse, it can be considered as rotating around the oval center of circle earlier, and translation takes place after the rotation again.Equally, the starting point A of ellipse of revolution arc and terminal point B also can regard as earlier and rotate around the oval center of circle, and translation takes place after the rotation again, correspond to the starting point A ' on the standard ellipse, terminal point B '.The angle of rotation is known, be-α, the position of translation can't be determined, can be by rotating the straight line AB that forms by ellipse of revolution arc starting point and terminal point earlier, the angle of rotation is-α, again postrotational straight line is intersected with standard ellipse under the constant situation of slope, the profound length that intersects 2 formations equals the profound long AB that ellipse of revolution arc origination data A and original equipment manufacturer B constitute, and by intersecting of obtaining of this method 2 are ellipse of revolution arc corresponding conversion starting point A ' and conversion terminal point B ' on this standard ellipse.Specific as follows:
1) at first calculates the profound length of 2 of AB
2) determine the slope of straight line AB then by A, B two point coordinate
Obtain the angle tag θ=k of straight line AB and horizontal x axle
1Get θ=arctank
1AB is rotated counterclockwise α with straight line, obtains total angle and is (α+θ), rotate back straight slope K
2=tag (α+θ).
With postrotational straight-line equation y=k
2X+t substitution standard ellipse equation
Obtain rotating the intersection point of back straight line and standard ellipse:
b
2(x-x
0)
2+a
2(k
2x+t-y
0)
2=a
2b
2
(b
2+a
2k
2 2)x
2+(-2b
2x
0+2a
2k
2(t-y
0))x+b
2x
0 2+a
2(t-y
0)
2-a
2b
2=0
Order: F=(b
2+ a
2k
2 2) G=(2b
2x
0-2a
2k
2y
0) H=b
2x
0 2-a
2b
2
Then equation becomes:
Fx
2+(G+2a
2k
2t)x+H+a
2(t-y
0)
2=0
Radical formula must rotate the coordinate of the intersection point of back straight line and standard ellipse, promptly the starting point A of ellipse of revolution arc (x1, y1) and terminal point B (x2, y2) on standard ellipse corresponding starting point A ' (x3, y3) with terminal point B ' (x4, coordinate y4):
(being x3, x4) formula (5)
Y=k
2X+t; (being y3, y4)
At this moment, t does not also find the solution.
According to the chord length formula:
(1+k
2)((G+2a
2k
2t)
2-4F(H+a
2(t-y
0)
2))=L
2F
2
Order: [=4a
4k
2 2-4Fa
2:]=4Ga
2k
2+ 8y
0Fa
2:
Then equation becomes:
It
2+Jt+K=0
Solve two roots of equation:
Total can obtain two groups and separate, respectively two straight line l1, l2 in the corresponding diagram 7.
Two orthoscopic parallel relation can be determined by the slope of straight line, and then the upper and lower relation of two straight lines can be determined.If the anglec of rotation is the 0-180 degree, then get top straight line l1,
If 180-360 or-the 180-0 degree then takes off the straight line l2 of face,
Get
Substitution formula (5) obtains, and the anglec of rotation is 0-180 when spending, and the starting point A of ellipse of revolution arc and terminal point B corresponding starting point A ' and the coordinate of terminal point B ' on standard ellipse are:
(be x3, x4)
(be y3, y4)
Get
Substitution formula (5) obtains, the anglec of rotation be 180-360 or-when 180-0 spent, the starting point A of ellipse of revolution arc and terminal point B corresponding starting point A ' and the coordinate of terminal point B ' on standard ellipse were:
(be x3, x4)
(be y3, y4)
Wherein, K
2=tag (α+θ), F=(b
2+ a
2k
2 2) G=(2b
2x
0-2a
2k
2y
0) H=b
2x
0 2-a
2b
2
In step 404,, determine the transformation matrix between this standard ellipse and this ellipse of revolution according to the anglec of rotation of this ellipse of revolution arc, the beginning or end coordinate of this ellipse of revolution arc, corresponding beginning or end coordinate on this standard ellipse.
This transformation matrix is made up of translation and rotation two parts, and the matrix form of expression of existing computer graphic fractal transform is as follows:
Translation matrix:
Rotation matrix:
Existing translation has the transformation matrix of rotation to be again:
Wherein, tx is the coordinate figure that moves horizontally, and ty is the coordinate figure of vertical moving; A is the angle of rotation.
This standard ellipse is transformed to the angle that this ellipse of revolution rotates and is the transverse axis of this ellipse of revolution arc and the angle of transverse axis in the present embodiment, and corresponding rotation matrix is:
The displacement coordinate value of translation is unknown.
In this step, at first (x3 y3) is set to the 3*1 matrix with A ' coordinate points
Again with rotation matrix
Dot product A ' coordinates matrix
Obtain postrotational A " coordinates matrix
Wherein, x
5=cos (α) x
3-sin (α) y
3y
5=sin (α) x
3+ cos (α) y
3
(x1 y1) deducts A, and " (x5 y5), has just obtained translational coordination to coordinate with the A point coordinate.According to this translational coordination and the anglec of rotation, can determine the transformation matrix between this standard ellipse and this ellipse of revolution
Tx is the coordinate figure (being x1-x5) that moves horizontally, and ty is the coordinate figure (being y1-y5) of vertical moving; A is anglec of rotation α.
In step 405, according to the ellipse of revolution arc of determining in the equation of the standard ellipse that calculates in the step 402 and the step 403 corresponding starting point and terminal point on this standard ellipse, obtain each point coordinate of ellipse of revolution arc correspondence on this standard ellipse, the transformation matrix of determining in these point coordinate and the step 404 is multiplied each other, obtain each point coordinate on the ellipse of revolution arc.
In step 406,, on display screen, draw this ellipse of revolution arc according to each point coordinate on the ellipse of revolution arc.Specifically can utilize drawing instrument, as GDI (Graphics Device Interface: Graphics Device Interface), GDI+, openG1 (high performance graphics algorithm industry standard) etc. directly draw these coordinate points, and these coordinate points are formed elliptic arc.
In sum, present embodiment has been utilized the mathematical model of existing standard ellipse, the ellipse of ellipse of revolution arc correspondence is decomposed into standard ellipse+transformation matrix, the elliptic equation of the standard ellipse by correspondence, determine each point coordinate of ellipse of revolution arc correspondence on this standard ellipse, again these coordinates are combined with transformation matrix, obtain each point coordinate on the ellipse of revolution arc, thereby under the prerequisite of the mathematical model that need not to set up ellipse of revolution, by less operand, finish the drafting of ellipse of revolution arc, method for drafting is easy and consume system resources is few.
Need to prove that to be example with the SVG figure be illustrated the method for drafting of ellipse of revolution arc present embodiment, in actual applications, can use the present invention to draw the ellipse of revolution arc of the extended formatting except that the SVG figure equally.
Though pass through with reference to some of the preferred embodiment of the invention, the present invention is illustrated and describes, but those of ordinary skill in the art should be understood that and can do various changes to it in the form and details, and without departing from the spirit and scope of the present invention.