A rounded corner drawing method, device, and storage medium
By obtaining the fillet size and polygon parameters, the fillet is drawn automatically, which solves the problem of lack of fillet polygon drawing function in existing office software and realizes the fast and accurate drawing of polygon fillets.
Patent Information
- Application Number
- CN202010331988.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-24
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2040-04-24
AI Technical Summary
Existing office software lacks the function of drawing rounded polygons, which requires users to perform manual operations and is inefficient.
By obtaining the fillet size parameters and polygon graphics parameters, the fillet drawing parameters of each vertex are determined, and the fillet is drawn using the curve nodes and control handle parameters to achieve automatic fillet drawing.
It realizes automatic, fast and accurate rounded corner drawing of polygons, avoiding the tedious process of manual drawing.
Smart Images

Figure CN113553810B_ABST
Abstract
Description
Technical Field
[0001] This article relates to computing and technology, and more particularly to a method, device, and storage medium for drawing rounded corners. Background Art
[0002] When using similar office software such as WPS Office or Microsoft Office, it is sometimes necessary to create rounded polygons. However, existing tools only provide conventional sharp-cornered polygon drawing tools and rounded rectangle drawing tools, and fail to provide functions related to drawing rounded polygons of other shapes (such as rounded hexagons, rounded arrows, etc.). Users can only draw manually, which is often inefficient and takes a lot of users' time. Summary of the Invention
[0003] The present application provides a rounded corner drawing method, device, and storage medium, which can achieve the function of automatically drawing rounded corners for polygons.
[0004] This application provides a method for drawing rounded corners, comprising: upon receiving an instruction to round the corners of a selected polygon, obtaining fillet size parameters for drawing the rounded corners; determining fillet drawing parameters corresponding to each vertex of the selected polygon based on the obtained fillet size parameters and the graphical parameters of the selected polygon; the fillet drawing parameters including the coordinates of a curve node and the curve's control handle parameters; the control handle parameters including the coordinates of the control point and the length of the control handle; and setting and drawing a curve node for each vertex of the selected polygon based on the determined fillet drawing parameters, replacing the original angle of the vertex with the drawn curve; the graphical parameters including the coordinates of each vertex of the selected polygon and the angle parameters of each vertex. This application can realize the function of automatically drawing rounded corners for polygons.
[0005] Compared with the related technology, the embodiment of the present application determines the rounded corner drawing parameters corresponding to each vertex of the selected polygon by obtaining the rounded corner size parameters and the graphic parameters of the selected polygon, thereby realizing the function of automatically, quickly and accurately drawing rounded corners for the polygon, avoiding the tediousness of manually drawing rounded corners.
[0006] In an exemplary embodiment, the embodiment of the present application can realize the drawing of the radius of the fillet with equal radius and the radius of the fillet with equal cross-section, thereby realizing the drawing of fillets that provide multiple effects.
[0007] Other features and advantages of the present application will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present application. Other advantages of the present application can be realized and obtained by the solutions described in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] The accompanying drawings are used to provide an understanding of the technical solution of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the technical solution of the present application and do not constitute a limitation on the technical solution of the present application.
[0009] Figure 1 This is a flow chart of the rounded corner drawing method according to an embodiment of the present application;
[0010] Figure 2 Schematic diagram of a polygon with equal radius and equal cross-section, with rounded corners, according to an embodiment of the present application;
[0011] Figure 3 Schematic diagram of a polygon with equal radius rounded corners and equal cross-section rounded corners in extreme cases according to an embodiment of the present application;
[0012] Figure 4 Draw a polygon with equal radius rounded corners and a display diagram of equal cross-section rounded corners for the triangle in the embodiment of the present application;
[0013] Figure 5 A schematic diagram comparing equal radius fillets and equal cross-section fillets is drawn for various different graphics in the embodiments of the present application;
[0014] Figure 6 This application shows the process of drawing equal radius fillets on polygon vertices Figure 1 ;
[0015] Figure 7 This application shows the process of drawing equal radius fillets on polygon vertices Figure 2 ;
[0016] Figure 8 This application shows the process of drawing equal radius fillets on polygon vertices Figure 3 ;
[0017] Figure 9 This application shows the process of drawing equal radius fillets on polygon vertices Figure 4 ;
[0018] Figure 10 This application shows the process of drawing equal radius fillets on polygon vertices Figure 5 ;
[0019] Figure 11 This application shows the process of drawing equal radius fillets on polygon vertices Figure 6 ;
[0020] Figure 12 This application shows the process of drawing equal radius fillets on polygon vertices Figure 7 ;
[0021] Figure 13 This application shows the process of drawing equal radius fillets on polygon vertices Figure 8 ;
[0022] Figure 14 This application shows the process of drawing equal radius fillets on polygon vertices Figure 9 ;
[0023] Figure 15 This application shows the process of drawing equal radius fillets on polygon vertices Figure 10 ;
[0024] Figure 16 This application shows the process of drawing equal radius fillets on polygon vertices Figure 10 one;
[0025] Figure 17 This application shows the process of drawing equal radius fillets on polygon vertices Figure 10 two;
[0026] Figure 18 This is an example diagram of the first part of the computer processing process for drawing equal-radius fillets on polygon vertices in this application;
[0027] Figure 19 This is an example diagram of the second part of the computer processing process for drawing equal-radius fillets on polygon vertices in this application;
[0028] Figure 20 This is a schematic diagram of the rounded corner drawing device module according to an embodiment of the present application. DETAILED DESCRIPTION
[0029] This application describes multiple embodiments, but this description is exemplary rather than restrictive, and it will be apparent to those skilled in the art that there may be more embodiments and implementations within the scope of the embodiments described herein. Although many possible feature combinations are shown in the drawings and discussed in the detailed description, many other combinations of the disclosed features are also possible. Unless specifically limited, any feature or element of any embodiment may be used in combination with any other feature or element in any other embodiment, or may replace any other feature or element in any other embodiment.
[0030] This application includes and contemplates combinations of features and elements known to those of ordinary skill in the art. The embodiments, features, and elements disclosed in this application may also be combined with any conventional features or elements to form a unique inventive solution defined by the claims. Any features or elements of any embodiment may also be combined with features or elements from other inventive solutions to form another unique inventive solution defined by the claims. Therefore, it should be understood that any feature shown and / or discussed in this application may be implemented individually or in any appropriate combination. Therefore, except for the limitations made according to the appended claims and their equivalents, the embodiments are not subject to other limitations. In addition, various modifications and changes may be made within the scope of protection of the appended claims.
[0031] In addition, when describing representative embodiments, the specification may have presented the method and / or process as a specific sequence of steps. However, to the extent that the method or process does not rely on the specific order of the steps described herein, the method or process should not be limited to the steps in the specific order described. As will be understood by those skilled in the art, other orders of steps are also possible. Therefore, the specific order of the steps set forth in the specification should not be interpreted as a limitation to the claims. In addition, the claims for the method and / or process should not be limited to performing their steps in the order written, and those skilled in the art can readily understand that these orders can be changed and still remain within the spirit and scope of the embodiments of the present application.
[0032] like Figure 1 As shown, the rounded corner drawing method of the embodiment of the present application includes the following operations:
[0033] S1. Upon receiving an instruction to round the corners of a selected polygon, obtaining fillet size parameters for rounding the corners;
[0034] S2. Determine the fillet drawing parameters corresponding to each vertex of the selected polygon based on the obtained fillet size parameters and the graphic parameters of the selected polygon; the fillet drawing parameters include the coordinates of the curve nodes and the control handle parameters of the curve; the control handle parameters include the coordinates of the control point and the length of the control handle; the graphic parameters include the coordinates of each vertex of the selected polygon and the angle parameters of each vertex
[0035] S3. According to the determined rounded corner drawing parameters, a curve node is set for each vertex of the selected polygon and drawn, and the original corner of the vertex is replaced by the drawn curve; the curve forms a rounded corner.
[0036] The embodiment of the present application determines the fillet drawing parameters corresponding to each vertex of the selected polygon by obtaining the fillet size parameters and the graphic parameters of the selected polygon, thereby realizing the function of automatically, quickly and accurately drawing fillets for the corners of the polygon, avoiding the tediousness of manually drawing fillets.
[0037] The vertices of the selected polygon mentioned above refer to each point on the polygon outline that forms an angle, or the intersection of each two adjacent line segments. For example Figure 4 As shown, a triangle has three vertices; a five-pointed star has ten vertices in the embodiment of the present application, including obtuse angles. Another example is an arrow-shaped figure with seven vertices.
[0038] The above-mentioned curve node refers to the node used to form a curve segment in the drawing of office software. By setting the position of a curve node and the position of the control point on the control handle of the curve node, a curve segment including the curve node can be obtained; the embodiment of the present application determines the parameters of the curve node through clever design, so that the curve segment formed by multiple curve nodes can be used as a rounded corner to replace the original corner on the polygon.
[0039] In an exemplary embodiment, the angle parameters of each vertex include the angle α between the two edges connected to the vertex P1, the relative angle β2 from the vertex P1 to the next adjacent vertex P2, and the relative angle β0 from the vertex P1 to the previous adjacent vertex P2.
[0040] In an exemplary embodiment, the angle α between the two edges connected to each vertex is obtained in the following manner:
[0041] Based on the coordinates of the selected polygon's current vertex (x1, y1), the coordinates of the adjacent previous vertex (x0, y0), and the coordinates of the adjacent next vertex (x2, y2), a first predetermined formula is used to determine the length n0 of the line segment connecting the current vertex and the adjacent previous vertex, the length n1 of the line segment connecting the current vertex and the adjacent next vertex, and the length a of the line segment connecting the adjacent previous vertex and the adjacent next vertex. In an exemplary embodiment, the first predetermined formula is: n0 = ((x1-x0) 2 +(y1-y0) 2 ) 0.5 ; n1=((x2-x 1) 2 +(y2-y1) 2 ) 0.5 ; a=[(x2-x0) 2 +(y2-y0) 2 ] 0.5 .
[0042] Based on the determined length n0 of the line segment connecting the current vertex and the adjacent previous vertex, the length n1 of the line segment connecting the current vertex and the adjacent next vertex, and the length a of the line segment connecting the adjacent previous vertex and the adjacent next vertex, a second predetermined formula is used to determine the angle α between the two sides connected to the current vertex; in an exemplary embodiment, the second predetermined formula is: α=Arccos((n1 2 +n0 2 -a 2 ) / 2n1n0).
[0043] In an exemplary embodiment, the relative angle β2 between the current vertex P1 and the adjacent next vertex P2 and the relative angle β0 between the current vertex P1 and the adjacent previous vertex P2 are obtained in the following manner:
[0044] Obtain the coordinates of the current vertex P1 and the adjacent next vertex P2, and the coordinates of the current vertex P1 and the adjacent previous vertex P0, and use a third predetermined formula to respectively determine the relative angle β2 between the current vertex and the adjacent next vertex; in an exemplary embodiment, the third predetermined formula is: β0 = Arctan((y0-y1) / (x0-x1), β2 = Arctan((y2-y1) / (x2-x1).
[0045] In an exemplary embodiment, operation S2, determining the fillet drawing parameters corresponding to each vertex of the selected polygon based on the acquired fillet size parameters and the graphic parameters of the selected polygon, includes:
[0046] Perform the following operations on each vertex:
[0047] If the angle α of the vertex P1 is less than 90 degrees, then:
[0048] S21. Based on the vertex coordinates (x1, y1) of the vertex, the vertex coordinates (x1, y1) of the vertex, the distance t from the vertex P1 to the first curve node CP0 / CP2, the relative angle β0 between the vertex P1 and the previous vertex, and the relative angle β2 between the vertex P1 and the next vertex, a fourth predetermined formula is used to determine the coordinates (CP0x, CP0y) of the first curve node CP2 and the coordinates of the second curve node (CP2x, CP2y) in the fillet drawing parameters corresponding to the vertex P1. The fourth predetermined formula is: CP0x=x1+t×Cos(β0), CP0y=y1+t×Sin(β0); CP2x=x1+t×Cos(β2), CP2y=y1+t+Sin(β2).
[0049] The first curve node is the point of tangency between the line connecting the current vertex and the adjacent previous vertex and the fillet corresponding to the current vertex; the second curve node is the point of tangency between the line connecting the current vertex and the adjacent next vertex and the fillet corresponding to the current vertex;
[0050] S22, according to the vertex coordinates (x 1, y1), the distance o from the vertex P1 to the intersection point of the line connecting the vertex P1 and the center point of the fillet and the fillet, and the inclination angle γ of the line connecting the vertex P1 and the center point of the corresponding fillet, and using a fifth predetermined formula to determine the coordinates of the third curve node (CP1x, CP1y) in the fillet drawing parameters corresponding to the vertex; the fifth predetermined formula is: CP1x=x1+o×cos(γ), and the vertical coordinate CP1y=y1+o×sin(γ);
[0051] If the angle α of the vertex P1 is greater than 90 degrees, then:
[0052] S23. According to the vertex coordinates (x1, y1) of the current vertex, the distance t from the current vertex P1 to the point where the fillet is tangent, the relative angle β0 between the current vertex P1 and the adjacent previous vertex, and the relative angle β2 between the current vertex P1 and the adjacent next vertex, the fourth predetermined formula is used to respectively determine the first curve node coordinates (CP0x, CP0y) and the second curve node coordinates (CP2x, CP2y) in the fillet drawing parameters corresponding to the current vertex P1.
[0053] In an exemplary embodiment, operation S2 of determining the fillet drawing parameters corresponding to each vertex of the selected polygon based on the acquired fillet size parameters and the graphic parameters of the selected polygon includes the following operations:
[0054] According to the obtained fillet radius r, and the angle α between the two edges connected to the determined current vertex P1;
[0055] When α is less than 90 degrees, the sixth predetermined formula is used to determine the length u of the control handle of the curve node in the rounded corner drawing parameters corresponding to the current vertex P1; the sixth predetermined formula is: u = 2r×sin((90-α / 2) / 2) / (2cos(90-(270-α / 2) / 2)+1); when α is greater than or equal to 90 degrees, the seventh predetermined formula is used to determine the length u of the control handle of the curve node in the rounded corner drawing parameters corresponding to the current vertex P1; the seventh predetermined formula is: u = 2r×sin(90-α / 2) / (2cos(90-α / 2)+1).
[0056] In an exemplary embodiment, operation S2, determining the fillet drawing parameters corresponding to each vertex of the selected polygon based on the acquired fillet size parameters and the graphic parameters of the selected polygon, includes:
[0057] Perform the following operations on each vertex of the selected polygon:
[0058] If the angle α of the vertex P1 is less than 90 degrees, including:
[0059] S24, based on the determined length of the control handle, the vertex coordinates (x1, y1) of the current vertex, the distance t between the current vertex P1 and the curve node, the relative angle β0 between the current vertex and the next adjacent vertex P2, the relative angle β2 between the current vertex P1 and the previous adjacent vertex P0, the two control point coordinates (CP0B1x, CP0B1y) and (CP0B2x, CP0B2y) of the control handle of the first curve node and the two control point coordinates (CP2B1x, CP2B1y) and (CP2B2x, CP2B2y) of the handle of the second curve node in the rounded corner drawing parameters using the eighth predetermined formula;
[0060] In an exemplary embodiment, the eighth predetermined formula is: CP0B1x=x1+(t+u)×cos(β0), CP0B1y=y1+(t+u)×sin(β0); CP0B2x=x1+(t1-u)×cos(β0), CP0B2y=y1+(tu)×sin(β0); CP2B1x=x1+(tu)×cos(β2), CP2B1y=y1+(tu)×sin(β2); CP2B2x=x1+(t1+u)×cos(β2), CP2B2y=y1+(t+u)×sin(β2);
[0061] S24. Based on the determined length u of the control handle, the coordinates of the third curve node, and the relative angle μ / λ of the control point of the third control handle relative to the third curve node, use a ninth predetermined formula to determine the two control point coordinates (CP1B1x, CP1B1y) and (CP1B2x, CP1B2y) of the control handle of the third curve node in the fillet drawing parameters corresponding to this vertex; in an exemplary embodiment, the ninth predetermined formula is: CP1B1x=CP1x+u×cos(μ); CP1B1y=CP1y+u×sin(μ); CP1B2x=CP1x+u×cos(λ); CP1B2y=CP1y+u×sin(λ).
[0062] If the angle α of the vertex P1 is greater than 90 degrees, including:
[0063] S26. Determine the coordinates of two control points of the handle of the first curve node and the coordinates of two control points of the handle of the second curve node using the eighth predetermined formula based on the determined length of the control handle, the vertex coordinates (x1, y1) of the current vertex, the distance t between the current vertex P1 and the curve node, the relative angle β0 between the current vertex and the next adjacent vertex P2, and the relative angle β2 between the current vertex P1 and the previous adjacent vertex P0.
[0064] In an exemplary embodiment, the relative angle μ / λ of the control point of the third control handle relative to the node of the third curve is determined as follows:
[0065] Based on the inclination angle γ of the line connecting the current vertex and the center point of the corresponding fillet and the relative rotation angle of the control point of the control handle relative to the third curve node, the tenth predetermined formula is used to determine the relative rotation angle μ / λ of the control point of the third control handle relative to the third curve node; in an exemplary embodiment, the tenth predetermined formula is: μ=γ+90; λ=γ-90.
[0066] In an exemplary embodiment, the inclination angle γ of the line connecting the current vertex and the center point of the corresponding rounded corner is obtained in the following manner:
[0067] Based on the determined first relative angle β2 between the current vertex and the next adjacent vertex and the angle α between the two sides connecting the current vertex, the eleventh predetermined formula is used to determine the inclination angle γ of the connecting line from the current vertex to the center point of the corresponding rounded corner; the eleventh predetermined formula is γ=β2+0.5α.
[0068] In an exemplary embodiment, after receiving an instruction to round the corners of the selected polygon, obtaining the size parameters for rounding the corners in operation S1 includes the following operations:
[0069] S10. Upon receiving an instruction to fillet the corners of a selected polygon, determining whether to fillet with equal radius or fillet with equal cross-section according to the instruction; wherein, fillet with equal radius means that fillets with equal radius are drawn on the vertices of the polygon; fillet with equal cross-section means that the fillets drawn on the vertices of the polygon are equal in length to the line connecting the two edges;
[0070] S11. Obtain a specified radius for drawing a fillet from the instruction; if a fillet with a constant radius is drawn, the radius of the fillet is equal to the specified radius; if a fillet with a constant cross-section is drawn, the radius of the fillet is determined according to the following formula:
[0071] r=(2f2)0.5 / 2 / sin(α / 2)×tan(α / 2);
[0072] Among them, f represents the radius of the fillet with constant radius; r represents the radius of the fillet with constant cross-section; α represents the angle α between the two sides connected by the vertices of the polygon.
[0073] like Figure 2-5 As shown, the polygon with equal radius rounded corners ( Figure 2 Left) refers to the polygon with equal radius r for each rounded corner; equal cross-section rounded polygon ( Figure 2 (as shown on the right) means that the length g of the line connecting the points where the fillet meets the straight line is equal.
[0074] like Figure 3 As shown in the figure, the results obtained by the two drawing methods of equal radius rounded polygons and equal cross-section polygons will be different, especially in some extreme cases, when the degrees of the base angle and the vertex angle of the triangle are very different, the equal radius rounded triangle will cause the base angle to be much larger than the vertex angle from the perspective, while the use of equal cross-section rounded polygons will reduce this visual deviation.
[0075] like Figure 4 As shown, under normal circumstances, taking a triangle as an example, there are also differences when drawing rounded corners of the same triangle using equal radius rounded polygons and equal cross sections.
[0076] like Figure 5 As shown in the figure, a comparison of the two drawing methods of polygons with equal radius and polygons with equal cross-section is shown in various situations.
[0077] The embodiment of the present application can realize the drawing of the radius of the fillet with equal radius and the radius of the fillet with equal cross-section, thereby realizing the drawing of fillets that provide multiple effects.
[0078] like Figure 6-19 As shown, the drawing principle and computer processing process embodiment of the equal radius fillet or equal cross-section fillet of the present application are described in detail as follows, taking a corner of a parallelogram as an example:
[0079] The program will traverse each vertex of the polygon selected by the user and use the vertical and horizontal coordinates of each vertex to calculate the length n of the line segment between each vertex and the next vertex (the relative distance between the two vertices). For example, in Figure 6, the distance calculation principle from vertex P1 to vertex P2 is:
[0080] 1. The horizontal coordinate x1 and vertical coordinate y1 of P1 are known, and the horizontal coordinate x2 and vertical coordinate y2 of P2 are also known;
[0081] 2. Then the length of line segment l is y2-y1, and the length of line segment m is x2-x1
[0082] 3. According to the relationship between the lengths of the sides of a right triangle: the square of the hypotenuse = the sum of the squares of the two right-angled sides. When the lengths of the two right-angled sides are known, the length of the hypotenuse can be calculated according to the formula n = (l2 + m2) 0.5. The formula converted to the coordinates of the two right-angled points is: n = ((x2 - x1) 2 +(y2-y1) 2 ) 0.5
[0083] The length of the line segment from each vertex to the next vertex can be calculated. Then, through trigonometric functions and the law of cosines, the angle between the two line segments connected to each vertex (that is, where the vertex is located) can be calculated, such as Figure 7 In the calculation method of angle α, the angle α is:
[0084] 1. Calculate the distance a from P0 to P2 using the formula: a = [(x2-x0) 2 +(y2-y0) 2 ] 0.5
[0085] 2. Calculate the angle α, the formula is: α = Arccos ((n1 2 +n0 2 -a 2 ) / 2n1n0)
[0086] After calculating the degree of α, the value of r corresponding to each α can be calculated through α and f. The calculation steps are:
[0087] 1. Determine whether the user has selected a constant radius fillet or a constant cross-section fillet polygon
[0088] 2. If it is a polygon with equal radius, then r = f
[0089] 3. If it is a polygon with equal cross-section and rounded corners, then = (2f 2 ) 0.5 / 2 / sin(α / 2)×tan(α / 2).
[0090] Then, if Figure 8 As shown, when a circle with radius r is tangent to the two sides of the angle, the distance from the point of tangency to vertex P1 is calculated. This tangent point will be used as vertex CP for drawing the new shape. For example, in the figure below, the distance from vertex P1 to the tangent points CP0 and CP2 is calculated as: t = r / tan(α / 2).
[0091] When drawing rounded corners on a computer, if the angle α is less than 90 degrees, the vertices of the rounded corner are not 2 but 3 vertices to control the curve of the rounded corner (for the specific principle, please refer to the Bezier curve principle). As shown in Figure 9, if the sharp corner of a parallelogram with a smaller angle needs to be rounded, the curve of the rounded corner needs to be controlled by 3 vertices:
[0092] Therefore, when the angle is less than 90 degrees, the length o from P1 to CP1 needs to be calculated. Figure 10 The length of o is calculated as follows: o = r / sin(α / 2)-r
[0093] Then, use the vertical and horizontal coordinates of each vertex to calculate the relative angle from each vertex to the next vertex, for example Figure 11 The relative angle β2 between P1 and P2 (which can be understood as the inclination angle of line segment c) is calculated as: β2 = Arctan(l / m). Converted to the vertical and horizontal coordinates of P1 and P2, it is: β2 = Arctan((y2-y1) / (x2-x1)). Based on this principle, the relative angle between P1 and P0 can be calculated:
[0094] β0 = Arctan((y0 - y1) / (x0 - x1)). If the angle corresponding to vertex P1 is less than 90 degrees, then the inclination of the line segment from P1 to the center of the fillet must also be calculated. For example, the degree of γ in the figure below needs to be calculated. From the figure, it can be quickly determined that γ is a rotation of 0.5α based on β, so γ = β1 + 0.5α
[0095] For understanding of angles, please refer to Figure 12 , the line extending from point θ to the right is 0 degrees relative to θ. When this line starts from 0 degrees: rotating clockwise to the lower vertical line is 90 degrees; rotating clockwise to the left horizontal line is 180 degrees; rotating clockwise to the upper vertical line is 270 degrees; rotating counterclockwise to the upper vertical line is -90 degrees; rotating counterclockwise to the left horizontal line is -180 degrees.
[0096] And so on. Furthermore, using trigonometric functions to calculate the vertical and horizontal coordinates of a point using a specific angle value, and then using trigonometric functions to inversely calculate the angle using these coordinates, the angle calculated for a point between -90 and -180 degrees in the figure below will be between 0 and 90 degrees. This is due to the problem of negative equals positive, especially when it comes to tan and arctan functions. (Thus, the aforementioned γ = β + 0.5α is because n is actually rotating counterclockwise relative to point P1.)
[0097] Then, calculate the vertical and horizontal coordinates of the corresponding fillet vertex of each vertex, such as Figure 13In which, the horizontal coordinate of the fillet vertex CP0 is x=x1+t×Cos(β0), and the vertical coordinate y=y1+t×Sin(β0); the horizontal coordinate of CP2 is x=x1+t×Cos(β2), and the vertical coordinate y=y1+t+Sin(β2).
[0098] When the angle α of the vertex P1 is less than 90 degrees, the vertical and horizontal coordinates of CP1 need to be calculated, such as Figure 14 The horizontal coordinate CP1x of CP1 is CP1x=x1+o×cos(γ), and the vertical coordinate CP1y is CP1y=y1+o×sin(γ).
[0099] Then calculate the distance between the first and second control points of each fillet vertex CP0, CP1, and CP2, that is, the length of the control handle. There are two methods for calculating the length of the first and second control handles of CP1 and CP2:
[0100] The first case: when the angle between the vertices is less than 90 degrees, for example Figure 15 For the P1 vertex, the handle length of CP1 should be combined with that of CP2:
[0101] 1. Line segment u1=u2=u0
[0102] 2.ε=90-α / 2
[0103] 3.v=2r×sin(ε / 2), so v=2r×sin((90-α / 2) / 2)
[0104] 4. The angle between u1 and v is η = 90-(180-ε) / 2, so η = 90-(180-(90-α / 2)) / 2, that is, η = 90-(270-α / 2) / 2
[0105] 5. Since v = 2cos(η)u + u, u = v / (2cos(η) + 1)
[0106] 6. The final formula is u = 2r × sin ((90-α / 2) / 2) / (2cos (90-(270-α / 2) / 2) + 1)
[0107] By calculating the length u of the control handle, we can calculate the vertical and horizontal coordinates of the first and second control points. Figure 15 In the example, the calculation method for the vertical and horizontal coordinates of the first and second control points B1 and B2 of CP1 is:
[0108] 1. The angle between B1 and CP1 is μ = γ + 90. The calculation method of the vertical and horizontal coordinates of CP1 and the horizontal coordinate CP1B1x of B1 is: CP1B1x = CP1x + u × cos (γ + 90). The calculation method of the vertical coordinate CP1B1y of B1 is: CP1B1y = CP1y + u × sin (γ + 90).
[0109] 2. The angle λ of B2 relative to CP1 is γ-90. Then the calculation method of the horizontal coordinate CP1B2x of B2 is: CP1B2x=CP1x+u×cos(γ-90). The calculation method of the vertical coordinate CP1B2y of B2 is: CP1B2y=CP1y+u×sin(γ-90).
[0110] The second case, such as Figure 16 As shown in the figure, when α>=90 degrees, the vertex CP1 does not exist. Referring to the above principle, the calculation method of line segment u is:
[0111] 1. Line segment v = 2r × sin(90-α / 2)
[0112] 2. Line segment u = v / (2cos(90-α / 2)+1)
[0113] 3. The final formula is: u = 2r × sin (90-α / 2) / (2cos (90-α / 2) + 1)
[0114] In either case, u will eventually be calculated, and then the vertical and horizontal coordinates of the first and second control points of CP2 will be calculated, such as Figure 17 The calculation method of the vertical and horizontal coordinates of the first and second control points CP0B1, CP0B2, CP2B1, and CP2B2 in CP0 and CP2 is:
[0115] 1. Given the vertical and horizontal coordinates of P1 and the relative angle β2 of P0 relative to P1, and the lengths of t and u calculated above, the calculation method for the horizontal coordinate CP0B1x of CP0B1 is: CP0B1x = x1 + (t + u) × cos (β0), and the calculation method for the vertical coordinate CP0B1y of CP0B1 is: CP0B1y = y1 + (t + u) × sin (β0)
[0116] 2. The calculation method of the horizontal coordinate CP0B2x of CP0B2 is: CP0B2x=x1+(t1-u)×cos(β0), and the calculation method of the vertical coordinate CP0B2y is: CP0B2y=y1+(tu)×sin(β0)
[0117] 3. Given the vertical and horizontal coordinates of P1 and the angle of β2, and the lengths of t and u calculated above, the horizontal coordinate CP2B1x of CP2B1 is calculated as: CP2B1x = x1 + (tu) × cos(β2), and the vertical coordinate CP2B1y is calculated as: CP2B1y = y1 + (tu) × sin(β2)
[0118] 4. The calculation method of the horizontal coordinate CP2B2x of CP2B2 is: CP2B2x=x1+(t1+u)×cos(β2), and the calculation method of the vertical coordinate CP2B2y is: CP2B2y=y1+(t+u)×sin(β2)
[0119] According to the principles and steps described above, after calculating the vertical and horizontal coordinates of the rounded vertex and its control point corresponding to each vertex, these rounded vertex coordinates are used to create a new graphic at the corresponding coordinates of the document, and a new graphic node is added at each rounded vertex coordinate. Then, according to the coordinates of the first and second control points of the corresponding rounded vertex, the positions of the first and second control points of the node are adjusted. Finally, a new polygonal graphic will be obtained, and the corners of the new polygon are rounded, and the radius or cross-section of the rounded corners is of uniform size.
[0120] like Figure 18 、 Figure 19 The computer processing flow of the rounded corner drawing method of this application is as follows:
[0121] N1. The user selects polygon S and initiates a command to draw a rounded polygon.
[0122] N2. Call up the preset parameter setting interface, the user enters the fillet radius value f, and selects whether to use a polygon with equal radius fillets or a polygon with equal cross-sections.
[0123] N3. Traverse all vertices of S (P1 will be used to represent the vertex pointed to by the current loop, P0 will be used to represent the previous vertex, P2 will be used to represent the next vertex, and P3 will be used to represent the next vertex) and perform operations N4-N26;
[0124] N4. Get the horizontal coordinate x1 and vertical coordinate y1 of P1, get the horizontal coordinate x0 and vertical coordinate y0 of P0, and get the horizontal coordinate x2 and vertical coordinate y2 of P2
[0125] The angle α formed by the lines connecting the three vertices N5, P0, P1, and P2 (i.e., the angle where the P1 vertex is located) is as follows:
[0126] calculate
[0127] N6. Determine whether the user has selected a polygon with equal radius fillets. If so, calculate the fillet radius r using the formula: r = f. If not, calculate the fillet radius r using the formula:
[0128] N7. Calculate the relative angle β0 from P0 to P1. Formula: β0 = tan -1 [(y0-y1)÷(x0-x1)]
[0129] N8. Calculate the relative angle β2 from P1 to P2. Formula: β2 = tan -1 [(y2-y1)÷(x2-x1)]
[0130] N9. Calculate the distance n0 from P0 to P1 using the formula:
[0131] N10. Calculate the distance n2 from P1 to P2 using the formula:
[0132] N11. Calculate the distance t1 between the point of tangency of a circle with radius r and the line segments P0 to P1 and P1 to P2, from P1. Formula: t = r ÷ tan (α ÷ 2)
[0133] N12. Calculate the value of the horizontal coordinate CP0x of the fillet vertex CP0 on the line segment from P0 to P1. The formula is: CP0x = x1 + t × cosβ0
[0134] N13. Calculate the value of the vertical coordinate CP0y of the fillet vertex CP0 on the line segment from P0 to P1. The formula is: CP0y=y1+t×sinβ0
[0135] N14. Determine whether α is less than 90 degrees;
[0136] If so, the following operations are included:
[0137] M1: Calculate the fillet vertex handle length u, formula: u = 2r × sin[(90-0.5α)÷2]÷{2cos[90-(270-0.5α) / 2]+1};
[0138] M2: Calculate the value of the abscissa CP1x of the fillet vertex CP1 using the formula: CP1x = x1 + [r ÷ sin (α / 2) - r] × cos (β1 + 0.5α);
[0139] M3: Calculate the value of the abscissa CP1x of the fillet vertex CP0 using the formula: CP1x = x1 + [r ÷ sin (α / 2) - r] × sin (β1 + 0.5α);
[0140] M4: Calculate the horizontal coordinate CP1 B1x of the first control handle of the fillet vertex CP1, formula: CP1B1x = CP1x + u × cos(β1 + 0.5α + 90);
[0141] M5: Calculate the horizontal coordinate CP1B2y of the second control handle of the fillet vertex CP1 using the formula: CP1B2y = CP1x + u × sin(90 + β1 + 0.5α - 90);
[0142] M6: Calculate the horizontal coordinate CP1 B2y of the second control handle of the fillet vertex CP1, formula: CP1 B2y = CP1x + u × sin (β1 + 0.5α - 90); proceed to operation N15;
[0143] If not, include the following operations:
[0144] F1: Calculate the fillet vertex handle length u, formula: u = 2r × sin[(90-0.5α)÷2]÷[2cos(90-0.5α)+1], and proceed to operation N15;
[0145] N15. Calculate the horizontal coordinate CP0 B1x of the first control handle of the fillet vertex CP0 using the formula: CP0 B1x = x1 + (t + u) × cos β0.
[0146] N16. Calculate the horizontal coordinate CP0 B1y of the first control handle of the fillet vertex CP0 using the formula: CP0 B1y = x1 + (t + u) × sin β0.
[0147] N17. Calculate the horizontal coordinate CP0 B2x of the second control handle of the fillet vertex CP0 using the formula: CP0 B2x = x1 + (tu) × cosβ0.
[0148] N18. Calculate the horizontal coordinate CP0 B2y of the second control handle of the fillet vertex CP0 using the formula: CP0 B2y = x1 + (tu) × sinβ0.
[0149] N19. Calculate the value of the horizontal coordinate CP2x of the fillet vertex CP2 on the line segment from P1 to P2 using the formula: CP2x = x1 + t × cosβ2;
[0150] N20. Calculate the ordinate CP2y of the first fillet vertex CP2 on the line segment from P1 to P2 using the formula: CP2y = x1 + t × sinβ2.
[0151] N21. Calculate the horizontal coordinate CP2 B1x of the first control handle of the fillet vertex CP2 using the formula: CP2B1x = x1 + (tu) × cosβ2.
[0152] N22. Calculate the horizontal coordinate CP2 B1y of the first control handle of the fillet vertex CP2 using the formula: CP2 B1y = x1 + (tu) × sin β2.
[0153] N23. Calculate the horizontal coordinate CP2 B2x of the second control handle of the fillet vertex CP2 using the formula: CP2 B2x = x1 + (t + u) × cos β2.
[0154] N24. Calculate the horizontal coordinate CP2 B2y of the second control handle of the fillet vertex CP2 using the formula: CP2 B2y = x1 + (t + u) × sin β2.
[0155] N25. Add a path corner node CP0 at the coordinates CP0x and CP0y in the document, set the coordinates of the first control handle to CP0B1x and CP0B1y, and set the horizontal and vertical coordinates of the second control handle to CP0B2y and CP0B2y;
[0156] N26. Determine whether α is less than 90 degrees. If so, add a path corner node CP1 at the document coordinates CP1x and CP1y, set the coordinates of the first control handle to CP1B1x and CP1B1y, and set the horizontal and vertical coordinates of the second control handle to CP1B2y and CP1B2y. If not, add a path corner node CP2 at the document coordinates CP2x and CP2y, set the coordinates of the first control handle to CP2B1x and CP2B1y, and set the horizontal and vertical coordinates of the second control handle to CP2B2y and CP2B2y.
[0157] N27. Draw the next vertex.
[0158] Those skilled in the art will appreciate that the above formula may have other situations by adopting mathematical changes, which are not limited here.
[0159] like Figure 20 As shown, an embodiment of the present application provides a rounded corner drawing device, comprising:
[0160] The acquisition module 10 is used to obtain the fillet size parameters for drawing the fillet after receiving the instruction to draw the corners of the selected polygon as fillets;
[0161] The drawing parameter determination module 20 is used to determine the fillet drawing parameters corresponding to each vertex of the selected polygon based on the obtained fillet size parameters and the graphic parameters of the selected polygon; the fillet drawing parameters include the coordinates of the curve nodes and the control handle parameters of the curve; the control handle parameters include the coordinates of the control point and the length of the control handle; the graphic parameters include the coordinates of each vertex of the selected polygon and the angle parameters of each vertex
[0162] The rounded corner drawing module 30 is used to set a curve node for each vertex of the selected polygon according to the determined rounded corner drawing parameters and draw the curve, so as to replace the original angle of the vertex with the drawn curve.
[0163] An embodiment of the present application also provides a rounded corner drawing device, including a processor and a memory, characterized in that the memory stores a program for targeted content delivery; the processor is used to read the program for targeted content delivery and execute any of the above methods.
[0164] An embodiment of the present application further provides a computer storage medium having a computer program stored thereon, wherein the computer program implements any of the methods described above when executed by a processor.
[0165] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In hardware implementations, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all components may be implemented as software executed by a processor, such as a digital signal processor or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium). As is well known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable, and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those skilled in the art that communication media generally embodies computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
Claims
1. A method for drawing rounded corners, characterized in that: include: N1. The user selects polygon S and initiates a command to draw a rounded polygon. N2. The preset parameter setting interface is called up, and the user enters the fillet radius value f and selects whether to create a polygon with constant radius fillets or a polygon with constant cross-section; N3. Traverse all vertices of S, using P1 to represent the vertex pointed to by the current loop, P0 to represent the previous vertex, P2 to represent the next vertex, and P3 to represent the next vertex, and perform operations N4-N26; N4. Get the horizontal coordinate x1 and vertical coordinate y1 of P1, get the horizontal coordinate x0 and vertical coordinate y0 of P0, and get the horizontal coordinate x2 and vertical coordinate y2 of P2; The angle α formed by the lines connecting the three vertices N5, P0, P1 and P2, that is, the angle where the vertex P1 is located, is as follows: ; N6. Determine whether the user has selected a polygon with equal radius fillets. If so, calculate the fillet radius r using the formula: ; If not, calculate the value of the fillet radius r, formula: ; N7. Calculate the relative angle β0 from P0 to P1 using the formula: ; N8. Calculate the relative angle β2 from P1 to P2 using the formula: ; N9. Calculate the distance n0 from P0 to P1 using the formula: ; N10. Calculate the distance n2 from P1 to P2 using the formula: ; N11. Calculate the distance t1 between the point of tangency from P1 and the line segments P0 to P1 and P1 to P2 when the circle with radius r is tangent to them. The calculation formula is: ; N12. Calculate the value of the horizontal coordinate CP0x of the fillet vertex CP0 on the line segment from P0 to P1. The formula is: ; N13. Calculate the ordinate CP0y of the fillet vertex CP0 on the line segment from P0 to P1. Formula: ; N14. Determine whether α is less than 90 degrees; If so, the following operations are included: M1: Calculate the length u of the fillet vertex handle, formula: ; M2: Calculate the value of the horizontal coordinate CP1x of the fillet vertex CP1. Formula: ; M3: Calculate the value of the vertical coordinate CP1y of the fillet vertex CP1. The formula is: ; M4: Calculate the horizontal coordinate CP1B1x of the first control handle of the fillet vertex CP1. Formula: ; M5: Calculate the horizontal coordinate CP1B2y of the second control handle of the fillet vertex CP1. Formula: ; M6: Calculate the horizontal coordinate CP1B2y of the second control handle of the fillet vertex CP1. Formula: ; Enter operation N15; If not, include the following operations: F1: Calculate the length u of the fillet vertex handle, formula: , proceed to operation N15; N15. Calculate the horizontal coordinate CP0B1x of the first control handle of the fillet vertex CP0. Formula: ; N16. Calculate the horizontal coordinate CP0B1y of the first control handle of the fillet vertex CP0. Formula: ; N17. Calculate the horizontal coordinate CP0B2x of the second control handle of the fillet vertex CP0. Formula: ; N18. Calculate the horizontal coordinate CP0B2y of the second control handle of the fillet vertex CP0. Formula: ; N19. Calculate the value of the horizontal coordinate CP2x of the fillet vertex CP2 on the line segment from P1 to P2. The formula is: ; N20. Calculate the value of the ordinate CP2y of the first fillet vertex CP2 on the line segment from P1 to P2. Formula: ; N21. Calculate the horizontal coordinate CP2B1x of the first control handle of the fillet vertex CP2. Formula: ; N22. Calculate the horizontal coordinate CP2B1y of the first control handle of the fillet vertex CP2. Formula: ; N23. Calculate the horizontal coordinate CP2B2x of the second control handle of the fillet vertex CP2. Formula: ; N24. Calculate the horizontal coordinate CP2B2y of the second control handle of the fillet vertex CP2. The formula is: ; N25. Add a path corner node CP0 at the coordinates CP0x and CP0y in the document, set the coordinates of the first control handle to CP0B1x and CP0B1y, and set the horizontal and vertical coordinates of the second control handle to CP0B2y and CP0B2y; N26. Determine whether α is less than 90 degrees. If so, add a path corner node CP1 at the document coordinates CP1x and CP1y, set the coordinates of the first control handle to CP1B1x and CP1B1y, and set the horizontal and vertical coordinates of the second control handle to CP1B2y and CP1B2y. If not, add a path corner node CP2 at the document coordinates CP2x and CP2y, set the coordinates of the first control handle to CP2B1x and CP2B1y, and set the horizontal and vertical coordinates of the second control handle to CP2B2y and CP2B2y. Among them, the CP0 is the tangent point of the line connecting the current vertex and the adjacent previous vertex and the rounded corner corresponding to the current vertex; the CP2 is the tangent point of the line connecting the current vertex and the adjacent next vertex and the rounded corner corresponding to the current vertex.
2. A rounded corner drawing device, comprising a processor and a memory, characterized in that: The memory stores a program; the processor is configured to read the program and execute the method according to claim 1.
Citation Information
Patent Citations
Method for drawing arbitrary arc in mobile terminal
CN101958001A
Graphic drawing device and graphic drawing program
JP2007087283A