A kind of method that when plane is drawn, polygon merges
Technical field
The invention belongs to mobile applicating developing technology field, a kind of method that when particularly plane is drawn, polygon merges.
Background technology
Android is a milestone in Mobile Development technical development course, is a mobile applications framework on modern mobile device development technique basis.
In modern mobile device, smart mobile phone and panel computer are more and more subject to people's favor, the number of mobile phone users in the whole world has exceeded 3,000,000,000, cut-off in 2013 is divided according to operating system the second quarter, Android operating system remains the king in smart mobile phone market, occupy the global smart mobile phone market share nearly 80%, modern smart mobile phone increased popularity, adds high speed handpiece data and WiFi focus and also gets more and more, and this makes market increasing to the demand of advanced mobile application program.Plane drawing practice based on Android system has changed the method that current PC equipment is master's drafting planimetric map.
Early stage manual drawing, staff holds the writing brush of several different thicknesses, T-square, the instrument such as set square and drawing curve is ceaselessly changed in hand, once drawing mistake redoes, patch up seems that drawing is very dirty and messy, had in succession occur after computer CAD CORAIDRAW Photo ship CAXA mapping software, although these mapping software computational accuracies and speed are that manual drawing is incomparable, but can only graphing in Windows operating system be housed, if on-the-spot drawing is drawn, want carrying notebook computer, 3G wireless Internet card, the instruments such as measuring appliance, it is main that the data of drawing mainly rely on hand-kept, the collection inconvenience of data, after artificially collecting data-switching, input computer, expend time in many, Portable device inconvenience, notes battery flying power deficiency.
Therefore, mobile applicating developing technology field urgent need is a kind of can make multiple rectangles by rapid drawing under the Android operating environment of touch-screen, and multiple rectangles can be merged into polygon, the method that when plane that susceptibility is high, degree of accuracy is high is drawn, polygon merges.
Summary of the invention
A kind of method that while the invention provides plane drawing, polygon merges, technical scheme is as follows:
The method that when plane is drawn, polygon merges, is characterized in that, comprises the steps:
Step 1: recording user pulls or draw the position of rectangle;
Step 2: whether whether this rectangle of real-time judge has overlappingly with the rectangle of other draftings, can merge;
Step 3: the intersection point that calculates overlapping rectangle;
Draw the length of four angular coordinates obtaining rectangle after rectangle, catercorner length and four edges, then according to 4 of rectangle limits, carry out the calculating of intersection point, the intersection point calculating is preserved, concrete steps are as follows:
Known two straight line A, B, 2 point coordinate of A are (x1, y1), (x2, y2), 2 of B is (x3, y3), (x4, y4);
The straight-line equation of A is: y-y1=(y2-y1) (x-x1)/(x2-x1),
The straight-line equation of B is: y-y3=(y4-y3) (x-x3)/(x4-x3);
By the straight-line equation simultaneous of A, B, the horizontal ordinate, the ordinate that solve intersecting point coordinate are respectively:
x=[(x2-x1)×(x3-x4)×(y3-y1)-x3×(x2-x1)×(y3-y4)+x1×(y2-y1)×(x3-x4)]/[(y2-y1)×(x3-x4)-(x2-x1)×(y3-y4)];
y=[(y2-y1)×(y3-y4)×(x3-x1)-y3×(y2-y1)×(x3-x4)+y1×(x2-x1)×(y3-y4)]/[(y2-y1)×(y3-y4)-(y2-y1)×(x3-x4)];
Step 4: reject the point blocking after merging;
Step 5: the set of statistics point, comprises 4 angular coordinates and the intersecting point coordinate of original rectangle and block point coordinate;
Step 6: fall into a trap and calculate X, Y-axis coordinate figure and minimum point thereof in a set;
Step 7: calculate second point of series connection by smallest point, by that analogy to the last for smallest point stops;
Step 8: generate new polygon object according to the series connection point order of extrapolating.
The method that when a kind of plane as above is drawn, polygon merges, wherein, step 6 is nested by conventional bubbling algorithm, first obtains minimum X coordinate, then calculates the coordinate points hour of Y under X minimum.
The method that when a kind of plane as above is drawn, polygon merges, wherein, step 7 is that step 7 is constant by the coordinate X-axis of basic point, and Y-axis numerical value successively decreases, and whether has coincide point in real-time judge set, if preserve this coordinate points while there is coincide point, from set, reject this coordinate points simultaneously, then calculate the next coordinate points of this coordinate points, obtain successively multiple coordinate points, until Y-axis is decremented at 0 o'clock while also not finding coincide point, continue next step; Further, coordinate Y-axis by basic point is constant, X-axis numerical value increases progressively, in real-time judge set, whether there is coincide point, if preserve this coordinate points while there is coincide point, from set, reject this coordinate points simultaneously, calculate again the next coordinate points of this coordinate points, obtain successively multiple coordinate points, until X-axis does not also find coincide point while being incremented to maximum X, continue next step; Further, coordinate X-axis by basic point is constant, Y-axis numerical value increases progressively, in real-time judge set, whether there is coincide point, while there is coincide point, preserve this coordinate points, from set, reject this coordinate points simultaneously, calculate again the next coordinate points of this coordinate points, obtain successively multiple coordinate points, until Y-axis does not also find coincide point while being incremented to maximum Y, continue next step; Coordinate Y-axis by basic point is constant, X-axis numerical value successively decreases, in real-time judge set, whether there is coincide point, while there is coincide point, preserve this coordinate points, from set, reject this coordinate points simultaneously, then calculate the next coordinate points of this coordinate points, obtain successively multiple coordinate points, until X-axis does not also find coincide point while being incremented to maximum X, with smallest point closure.
The invention has the beneficial effects as follows and can under the Android operating environment of touch-screen, make multiple rectangles by rapid drawing, and multiple rectangles can be merged into polygon, susceptibility is high, degree of accuracy is high, overcome the restriction of drawing under can only windows environment on PC, draw more quick and easyly, applicability is stronger.
Accompanying drawing explanation
Below in conjunction with the drawings and specific embodiments, describe the present invention in detail:
The structural representation of the method that when Fig. 1 is a kind of plane drawing of the present invention, polygon merges.
Fig. 2 is the reckoning sequential schematic in step 7 of the present invention.
Fig. 3 is the new polygon forming after rectangle of the present invention merges.
Embodiment
For measure, creation characteristic that the technology of the present invention is realized, reach object and effect is easy to understand, below in conjunction with concrete diagram, further set forth the present invention.
A kind of method that while the invention provides plane drawing, polygon merges, comprising:
Step 1: recording user pulls or draw the position of rectangle, and acquisition approach is as follows:
public?boolean?onTouchEvent(MotionEvent?event);
if(event.getAction()==MotionEvent.ACTION_DOWN);
if(event.getAction()==MotionEvent.ACTION_MOVE);
if(event.getAction()==MotionEvent.ACTION_UP);
Step 2: whether whether this rectangle of real-time judge has overlappingly with the rectangle of other draftings, can merge;
The structural representation of the method that when Fig. 1 is a kind of plane drawing of the present invention, polygon merges, the four angular coordinate of known two rectangles, utilize coordinate points to judge that whether rectangle is overlapping, if one of them angle of rectangle one of meets the following conditions, to be just considered as two rectangles overlapping, can merge:
(1)Rect.Left.x≤Rect1.Angle1.x≥Rect.Right.x;
Rect.Top.y≤Rect1.Angle1.y≥Rect.Bottom.y;
(2)Rect.Left.x≤Rect1.Angle2.x≥Rect.Right.x;
Rect.Top.y≤Rect1.Angle2.y≥Rect.Bottom.y;
(3)Rect.Left.x≤Rect1.Angle3.x≥Rect.Right.x;
Rect.Top.y≤Rect1.Angle3.y≥Rect.Bottom.y;
(4)Rect.Left.x≤Rect1.Angle4.x≥Rect.Right.x;
Rect.Top.y≤Rect1.Angle4.y≥Rect.Bottom.y;
Wherein, Rect.Left.x is the x min coordinates of rectangle, Rect.Right.x is the x maximum coordinates of rectangle, Rect.Top.y is the y maximum coordinates of rectangle, Rect.Bottom.y is the y min coordinates of rectangle, Rect1.Angle1.x is the min coordinates of the x at the right angle 1 in rectangle overlapping region in Fig. 1, Rect1.Angle2.x is the maximum coordinates of the x at the right angle 2 in rectangle overlapping region in Fig. 1, Rect1.Angle3.x is the min coordinates of the x of the overlapping point 3 in rectangle overlapping region in Fig. 1, Rect1.Angle4.x is the maximum coordinates of the x of the overlapping point 4 in rectangle overlapping region in Fig. 1, Rect1.Angle1.y is the maximum coordinates of the y at the right angle 1 in rectangle overlapping region in Fig. 1, Rect1.Angle2.x is the min coordinates of the y at the right angle 2 in rectangle overlapping region in Fig. 1, Rect1.Angle3.x is the min coordinates of the y of the overlapping point 3 in rectangle overlapping region in Fig. 1, Rect1.Angle4.x is the maximum coordinates of the y of the overlapping point 4 in rectangle overlapping region in Fig. 1,
Step 3: the intersection point that calculates overlapping rectangle;
Draw the length of four angular coordinates obtaining rectangle after rectangle, catercorner length and four edges, then according to 4 of rectangle limits, carry out the calculating of intersection point, the intersection point calculating is preserved, concrete steps are as follows:
Known two straight line A, B, 2 point coordinate of A are (x1, y1), (x2, y2), 2 of B is (x3, y3), (x4, y4);
The straight-line equation of A is: y-y1=(y2-y1) (x-x1)/(x2-x1),
The straight-line equation of B is: y-y3=(y4-y3) (x-x3)/(x4-x3);
By the straight-line equation simultaneous of A, B, the horizontal ordinate, the ordinate that solve intersecting point coordinate are respectively:
x=[(x2-x1)×(x3-x4)×(y3-y1)-x3×(x2-x1)×(y3-y4)+x1×(y2-y1)×(x3-x4)]/[(y2-y1)×(x3-x4)-(x2-x1)×(y3-y4)];
y=[(y2-y1)×(y3-y4)×(x3-x1)-y3×(y2-y1)×(x3-x4)+y1×(x2-x1)×(y3-y4)]/[(y2-y1)×(y3-y4)-(y2-y1)×(x3-x4)];
Step 4: reject merge after the point that blocks, the point 1 and 2 in being in figure;
Step 5: the set of statistics point, comprises 4 angular coordinates and the intersecting point coordinate of original rectangle and block point coordinate;
Step 6: fall into a trap and calculate X, Y-axis coordinate figure and minimum point thereof in a set;
Step 7: calculate second point of series connection by smallest point, by that analogy to the last for smallest point stops;
Fig. 2 is the reckoning sequential schematic in step 7, first, carry out 5, constant by the coordinate X-axis of basic point, Y-axis numerical value successively decreases, in real-time judge set, whether there is coincide point, if preserve this coordinate points while there is coincide point, from set, reject this coordinate points simultaneously, calculate again the next coordinate points of this coordinate points, obtain successively multiple coordinate points, until Y-axis is decremented at 0 o'clock while also not finding coincide point, proceed 6;
Further, constant by the coordinate Y-axis of basic point, X-axis numerical value increases progressively, and whether has coincide point in real-time judge set, if preserve this coordinate points while there is coincide point, rejects this coordinate points simultaneously, then calculate the next coordinate points of this coordinate points from set.Obtain successively multiple coordinate points, until X-axis does not also find coincide point while being incremented to maximum X, proceed 7;
Further, coordinate X-axis by basic point is constant, Y-axis numerical value increases progressively, in real-time judge set, whether there is coincide point, while there is coincide point, preserve this coordinate points, from set, reject this coordinate points simultaneously, calculate again the next coordinate points of this coordinate points, obtain successively multiple coordinate points, until Y-axis does not also find coincide point while being incremented to maximum Y, proceed 8;
Further, coordinate Y-axis by basic point is constant, X-axis numerical value successively decreases, in real-time judge set, whether there is coincide point, while there is coincide point, preserve this coordinate points, from set, reject this coordinate points simultaneously, calculate again the next coordinate points of this coordinate points, obtain successively multiple coordinate points, until X-axis does not also find coincide point while being incremented to maximum X, with smallest point closure;
Step 8: generate new polygon object according to the series connection point order of extrapolating, as shown in Figure 3.
In another embodiment of the present invention, step 6 is nested by conventional bubbling algorithm, first obtains minimum X coordinate, then calculates the coordinate points hour of Y under X minimum.
The invention has the beneficial effects as follows and can under the Android operating environment of touch-screen, make multiple rectangles by rapid drawing, and multiple rectangles can be merged into polygon, susceptibility is high, degree of accuracy is high, overcome the restriction of drawing under can only windows environment on PC, draw more quick and easyly, applicability is stronger.
More than show and described ultimate principle of the present invention, principal character and advantage of the present invention.The technician of the industry should understand; the present invention is not restricted to the described embodiments; that in above-described embodiment and instructions, describes just illustrates principle of the present invention; the present invention also has various changes and modifications without departing from the spirit and scope of the present invention, and these changes and improvements all fall in the claimed scope of the invention.The claimed scope of the present invention is defined by appending claims and equivalent thereof.