Curve smoothing method, system, device and storage medium based on Bezier curve
By selecting marking points as control points in the Bezier curve smoothing method and generating Bezier curves with the start point and the end point as the end point, the problem that the curve does not pass through marking points in the prior art is solved, and the problem of the curve not being completely passed through marking points is realized. More accurate curve smoothing and reduced error, suitable for a variety of touch displays.
Patent Information
- Application Number
- CN202110442936.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-23
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2041-04-23
AI Technical Summary
The curve generated by the existing Bezier curve smoothing method does not completely pass through all the marking points set by the user, resulting in errors with the actual curve to be drawn.
By selecting marking points outside the starting point and the end point as control points, a Bezier curve with the starting point and the end point as the end point is generated, so that the curve passes through all the marking points, and the marking points are accurately obtained by capacitance value or ray division method. , and set control points to reduce errors.
The generated curve is not only smooth, but also passes through all marking points set by the user, reducing the error with the curve that the user actually wants to draw, and is suitable for different types of touch displays.
Smart Images

Figure CN113362418B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of electronic drawing, and in particular to a curve smoothing method, system, device and storage medium based on Bezier curve. Background Art
[0002] With the popularization of computer equipment, human-computer interaction using computer equipment has become a part of daily life. Among them, in various interactive intelligent terminals, drawing original curves is one of the basic interactive functions, which has been widely used in people's work, study and life, greatly improving people's work and learning convenience. Taking teaching equipment as an example, the teacher draws and writes on the smart blackboard or smart tablet through touch or writing tools, and students can see what the teacher writes through the intelligent terminal.
[0003] In order to improve the smoothness of line drawing, in the prior art, Bezier curves are usually used to smooth the lines. Some more mature bitmap software also has Bezier curve tools, such as the "Pen Tool" in Photoshop, the "Bezier Tool" in CorelDraw, and the "Brush" in Fireworks.
[0004] like Figure 1 As shown in the figure, although the Bezier curve can effectively solve the problem of curve smoothness, the curve generated by the Bezier curve principle usually sets the first and last marking points as the starting point and the end point and locks them, and the other marking points between the starting point and the end point are used as control points to simulate and generate a smooth curve that only passes through the starting point and the end point. The curve generated by this method does not completely pass through all the marking points set by the user, resulting in an error between the generated curve and the curve that the user actually wants to draw. Summary of the invention
[0005] The present invention provides a curve smoothing method, system, device and storage medium based on Bezier curve to solve the problems existing in the prior art.
[0006] To achieve the above object, the present invention adopts the following technical solutions:
[0007] In a first aspect, a curve smoothing method based on a Bezier curve is provided, comprising:
[0008] Select the marking points to be drawn in the order of drawing, and mark the starting point and the ending point;
[0009] The control points corresponding to the marking points excluding the starting point and the ending point are set by a preset method;
[0010] Generate a Bezier curve with the start point and the end point as the two end points and passing through all the marked points according to the control points.
[0011] In a further embodiment, the process of setting the control point is:
[0012] Select three adjacent marking points in sequence according to the drawing order, which are the first point, the second point and the third point;
[0013] Connect the first point and the third point to form a line segment, and mark the midpoint of the line segment;
[0014] Connect the midpoint and the second point and extend to a fourth point so that the distance between the midpoint and the second point is equal to the distance between the second point and the fourth point;
[0015] The fourth point is set as a control point corresponding to the second point.
[0016] By adopting the above technical solution: by determining the control point, the Bezier curve generated according to the control point and passing through the first point and the third point can pass through the second point.
[0017] In a further embodiment, the marking points are obtained by the following process:
[0018] Get all pixels within the selected range on the screen;
[0019] Obtaining a capacitance value corresponding to the pixel point;
[0020] The pixel point corresponding to the maximum capacitance value is selected as the marking point.
[0021] In a further embodiment, the marking point may also be obtained through the following process:
[0022] Get all pixels within the selected range on the screen;
[0023] A pixel point is randomly selected on the contour of the selected range, recorded as a first pixel point, and a first ray is extended from the first pixel point as a starting point to penetrate the selected range, wherein the first ray divides the selected range into two parts with equal pixel points on both sides;
[0024] A pixel point is randomly selected on the contour of the selected range, recorded as the second pixel point, and a second ray is extended from the second pixel point to penetrate the selected range, and the second ray also divides the selected range into two parts with equal pixel points on both sides;
[0025] The intersection of the first ray and the second ray is obtained, the distance between all pixels in the selected range and the intersection is calculated, the pixel closest to the intersection is selected, and the selected pixel is set as a marking point.
[0026] In a second aspect, a system for a curve smoothing method based on a Bezier curve is provided, comprising:
[0027] A first module for selecting marking points to be drawn according to the drawing order and marking the starting point and the ending point;
[0028] A second module for setting control points corresponding to marking points excluding the starting point and the ending point by a preset method;
[0029] The third module is used for generating a Bezier curve having a start point and an end point as two end points and passing through all the marked points according to the control points.
[0030] In a third aspect, a device for a curve smoothing method based on a Bezier curve is provided, comprising:
[0031] a memory in which a computer program is stored;
[0032] The processor implements the curve smoothing method based on Bezier curve provided in the first aspect when executing the computer program.
[0033] In a fourth aspect, a storage medium is provided, wherein a computer program is stored in the storage medium, and when the computer program is executed by a processor, the curve smoothing method based on Bezier curve provided in the first aspect is implemented.
[0034] Beneficial effect: The curve smoothing method based on Bezier curve proposed by the present invention sets control points, and then generates a Bezier curve with a starting point and an end point as two end points and passing through all marked points according to the set control points. Instead of generating a Bezier curve with marked points as control points like in the prior art. Therefore, the curve generated by the present invention is not only smooth; at the same time, the generated curve passes through all marked points set by the user, reducing the error with the curve actually to be drawn by the user. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a schematic diagram of Bezier curve generation in the prior art.
[0036] Figure 2 It is a flow chart of the curve smoothing method based on Bezier curve of the present invention.
[0037] Figure 3 This is a schematic diagram of obtaining marking points.
[0038] Figure 4 It is a schematic diagram of determining the geometric center of gravity of an object using the suspension method.
[0039] Figure 5 This is a schematic diagram of setting control points by the preset method.
[0040] Figure 6 It is a structural schematic diagram of a system of a curve smoothing method based on Bezier curves.
[0041] Figure 7 It is a structural schematic diagram of a device for a curve smoothing method based on a Bezier curve.
[0042] Figures 1 to 7 The labels in the figure are: a first module 10, a second module 20 and a third module 30, a processor 100, a memory 200, an input device 300 and an output device 400. DETAILED DESCRIPTION
[0043] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings and embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] According to research, in order to improve the smoothness of line drawing on existing smart terminals, tools based on Bezier curves are usually used to smooth the lines. Although Bezier curves can effectively solve the problem of curve smoothness, the current process of generating curves based on the Bezier curve principle is usually: first set the starting point and the end point, and then use other marked points between the starting point and the end point as control points to simulate and generate a smooth curve that only passes through the starting point and the end point. Figure 1 As shown, the curve generated by this method does not completely pass through all the marking points set by the user, resulting in an error between the generated curve and the curve actually drawn by the user. In order to solve this technical problem, the present application provides a curve smoothing method, system, device and storage medium based on Bezier curve.
[0045] Embodiment 1
[0046] Figure 2 : is a flow chart of a curve smoothing method based on a Bezier curve provided in the first embodiment of the present invention. Figure 2 As shown, the curve smoothing method based on the Bezier curve provided in this embodiment includes:
[0047] S1, select the marking points to be drawn in the drawing order, and mark the starting point and the ending point. In this embodiment, the number of the selected marking points is set to n+1, which are respectively set to P 0 , P 1 ...P n , calibrate P 0 As the starting point, mark P n is the end point. Where n is an integer greater than or equal to 2.
[0048] Specifically, the user determines multiple marking points on the screen or other display device in sequence according to the approximate shape of the curve to be drawn. In practical applications, it is common to use a mouse or other clicking device to click to obtain the marking points. In this case, the coordinates of the marking points can be obtained more accurately. However, with the widespread use of smart terminals, there are fewer and fewer ways to obtain marking points through a mouse or other clicking devices. Taking teaching equipment as an example, teachers usually draw and write on smart blackboards or smart tablets by touching. When the display device is clicked by touching, a certain range of pixels is obtained, which brings several possibilities for smooth adjustment of the drawn curve. Therefore, it is necessary to explain how to accurately obtain marking points when touching and clicking the display device.
[0049] One possible solution is to use a capacitive touch screen as the display screen. This type of display screen is also one of the most widely used ones. In this case, the following steps can be used to determine a certain mark point:
[0050] S11, first obtain all pixel points within a selected range on the screen. The selected range is the range corresponding to the area contacted by the user's finger or other pointing device when clicking the screen. Because when the finger or pointing device clicks the screen, the screen is in contact with a certain range of surfaces, so at this time, the screen can obtain pixel points within a certain range.
[0051] S12, obtaining corresponding capacitance values according to the obtained pixel points within the selected range. Each pixel point corresponds to an independent capacitance value.
[0052] S13, selecting a pixel point corresponding to a maximum capacitance value, and determining the marked point as a marked point within the selected range.
[0053] Reducing the marking points to pixel points can make the final simulated curve pass through a certain marking point instead of a range point, effectively reducing the possibility of smooth adjustment, so that the generated curve is determined and not confused. It should be noted that the above-mentioned process of selecting marking points is usually only applicable to capacitive touch screens. In practical applications, touch screens mainly include resistive touch screens, infrared touch screens and surface acoustic wave touch screens. These types of touch screens cannot adopt the above-mentioned scheme of selecting marking points, so it is necessary to design a universal scheme of selecting marking points.
[0054] like Figure 3 As shown, in another possible solution, the following steps are used to select the marking points:
[0055] S11`, first, all pixels within a selected range on the screen are obtained. Similarly, because when a finger or a clicking device clicks the screen, the screen is in contact with a certain range of surfaces, so at this time, the screen can obtain pixels within a certain range, and the selected range is the range corresponding to when the user's finger or other clicking device clicks the screen.
[0056] S12', randomly selecting a pixel point on the contour of the selected range, recorded as the first pixel point, extending a first ray running through the selected range from the first pixel point as the starting point, the first ray dividing the selected range into two parts, the number of pixels in the two parts being equal;
[0057] S13', randomly select another pixel point on the selected range contour, record it as the second pixel point, and extend a second ray that runs through the selected range with the second pixel point as the starting point. The second ray also divides the selected range into two parts, and the number of pixel points in the two parts is also equal;
[0058] S14`, obtaining the intersection point of the first ray and the second ray, calculating the distance between all pixel points in the selected range and the intersection point and selecting the pixel point corresponding to the shortest distance, and then setting the selected pixel point as the marking point.
[0059] like Figure 4 As shown, in daily applications, the geometric center of gravity of irregular geometric objects is usually determined by the hanging method. The principle is: hang the object from the edge of the object. Since the geometric object has only one geometric center of gravity, each time it is hung, the geometric center of gravity is on the vertical downward ray from the hanging position, and the weight of the two parts divided by the ray is equal. Therefore, the geometric center of gravity of the geometric object can be obtained by hanging at least twice. Similar to this application, each time the touch screen is clicked, the range of contact between the finger or the clicking device and the screen is usually an irregular plane, so it is difficult to select pixels from the irregular plane as marking points. This scheme uses the first point to draw the first ray, and divides the range into two parts with equal pixel points; then draws the second ray through the second point to divide the range into two parts with equal pixel points. Similar to the hanging method for measuring the geometric center of gravity, the intersection of the first ray and the second ray should also be uniquely determined. However, this scheme is different from the hanging method for measuring the geometric center of gravity, that is, the selected range has no physical gravity, so it is divided by the number of pixels; at the same time, the hanging method is not really used to determine the intersection of the first ray and the second ray. Since the intersection point is uniquely determined, the pixel point closest to the intersection point within the selected range should also be uniquely determined.
[0060] Therefore, the advantages of adopting the above scheme are: on the one hand, it can obtain the marking points of the selected range more accurately and uniquely, so that the final simulated curve passes through a certain marking point rather than a range point, effectively reducing the possibility of smooth adjustment, so that the generated curve is certain and not confused; on the other hand, it can meet the usage requirements of different types of touch screens.
[0061] S2, setting control points corresponding to the marking points excluding the starting point and the ending point by a preset method.
[0062] Specifically, the process of setting the control points by the preset method is:
[0063] S21, selecting three adjacent marking points in sequence according to the drawing order as a first point, a second point and a third point.
[0064] S22, connecting the first point and the third point to form a line segment, and marking the midpoint of the line segment;
[0065] S23, connecting the midpoint and the second point and extending to a fourth point, so that the distance between the midpoint and the second point is equal to the distance between the second point and the fourth point;
[0066] S24: setting the fourth point as a control point corresponding to the second point.
[0067] With respect to the above steps, when there are only two marking points, that is, only the starting point and the ending point, the control point cannot be set at this time. According to the Bezier curve principle, when there are only two marking points, the generated curve is a straight line segment connecting the starting point and the ending point. Therefore, when there are only two marking points, the problem described in the background technology of the specification will not occur. Therefore, this application only describes the case where the number of marking points is greater than or equal to 3, and does not discuss the case where the number of marking points is only 2.
[0068] Combination Figure 5 , for the above method, in this embodiment, the marking point P 0 , P 1 , P 2 and P 3 Take this as an example to illustrate. 0 , P 1 , P 2 and P 3 represents the marking points in the drawing order 0, 1, 2, 3, then P 0 The first stage goal is to first determine P 1 The control point P 1 `. Set the marker point P 0 is the first point, mark point P 1 For the second point, mark point P2 First, connect the first point and the third point to form a line segment, and mark the midpoint of the line segment as P. 中 ; Then take the midpoint P 中 Connect the second point P to the starting point 1 And extend to the fourth point, so that the midpoint P 中 To the second point P 1 The distance between them is equal to the second point P 1 The distance between the fourth point and the second point is set as the control point P1' corresponding to the second point. 1 is the first point, mark point P 2 For the second point, mark point P 3 For the third point, we can get P 2 The corresponding control point P 2 The more the number of marking points, the method of setting the control points remains unchanged, that is, P is obtained by this method. 1 , P 2 ...P n-1 The corresponding control point P 1 `、P 2 `……P n-1 `. This embodiment only provides a specific method for obtaining control points. In practical applications, different control points can be obtained by other methods. According to the Bezier curve principle, the generated curve will be different depending on the control point selection, but this difference is irrelevant to the technical problem to be solved by this application. This application aims to use a curve smoothing method based on Bezier curve to make the generated curve pass through all the marking points set by the user, thereby reducing the error between the generated curve and the curve actually to be drawn by the user.
[0069] S3, based on the control points, a Bezier curve is generated with the start point and the end point as the two end points and passes through all the marked points. The Bezier curve can be expressed by the following formula:
[0070]
[0071] In the formula, (n―i) represents the number of control points, t∈[0,1], P 0 Indicates the starting point, P n Indicates the end point, P i ` indicates the marking point P i The corresponding control points.
[0072] According to the Bezier curve principle, under the control of the control points obtained based on step S2, the generated Bezier curve is a smooth curve passing through all the selected marking points, thereby reducing the error between the generated curve and the curve actually to be drawn by the user.
[0073] Embodiment 2
[0074] Figure 6 Schematic diagram of the structure of the system of the curve smoothing method based on Bezier curve provided in the second embodiment of the present invention. Figure 6 As shown, the system provided by the embodiment of the present invention includes a first module 10 , a second module 20 and a third module 30 .
[0075] Specifically, the first module selects the marking points according to the order in which the user draws, and calibrates the starting point and the ending point. The user can draw by clicking the screen with a finger or a clicking device. For example, click P on the screen in sequence. 0 , P 1 ...P n Position, then it corresponds to n+1 marking points, where n is an integer greater than or equal to 2. The order of selecting the markings is P 0 , P 1 ...P n Among them, P 0 is the starting point, P n is the end point.
[0076] The second module sets the control points of all other selected marking points except the starting point and the ending point according to the preset method. Select three adjacent marking points in sequence according to the drawing order, and record them as the first point, the second point and the third point respectively; connect the first point and the third point to form a line segment, and mark the midpoint of the line segment; then, connect the second point with the midpoint as the starting point and extend to the fourth point, and make the distance between the midpoint and the second point equal to the distance between the second point and the fourth point; finally, set the fourth point as the control point corresponding to the second point. Repeat the cycle in sequence to complete the setting of the control points corresponding to all marking points except the starting point and the ending point. That is, the marking point P 1 , P 2 ...P n-1 The corresponding control points are P 1 `、P 2 `……P n-1 `.
[0077] The third module generates a Bezier curve with the start point and the end point as the two end points and passing through all the marked points according to the control points. The curve can be expressed by the following formula:
[0078]
[0079] In the formula, (n―i) represents the number of control points, t∈[0,1], P 0 Indicates the starting point, P n Indicates the end point, P i ` indicates the marking point P iAccording to the Bezier curve principle, the curve starts from the starting point, connects all the marked points in sequence and finally extends to the end point, thereby reducing the error between the generated curve and the curve that the user actually wants to draw.
[0080] Embodiment 3
[0081] Figure 7 Schematic diagram of the structure of a device for a curve smoothing method based on a Bezier curve provided in Embodiment 3 of the present invention. Figure 7 As shown, the device for the curve smoothing method based on Bezier curve provided in the embodiment of the present invention includes a processor 100, a memory 200, an input device 300 and an output device 400.
[0082] Specifically, the processor 100, the memory 200, the input device 300, and the output device 400 may be communicatively connected. The memory 200, as a computer-readable storage medium, may be used to store software programs and computer executable programs. The processor 100 executes various functional applications and data processing of the computer device by running the software programs and instructions stored in the memory 200, thereby realizing the curve smoothing method based on the Bezier curve provided in any embodiment of the present invention.
[0083] Embodiment 4
[0084] Embodiment 4 of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the curve smoothing method based on the Bezier curve provided in any embodiment of the present invention is implemented.
[0085] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A curve smoothing method based on Bezier curve, characterized in that: include: Select the marking points to be drawn in the order of drawing, and mark the starting point and the ending point; The control points corresponding to the marking points excluding the starting point and the ending point are set by a preset method; Generate a Bezier curve with a start point and an end point as two end points and passing through all the marked points according to the control points; Select three adjacent marking points in sequence according to the drawing order, which are the first point, the second point and the third point; Connect the first point and the third point to form a line segment, and mark the midpoint of the line segment; Connect the midpoint and the second point and extend to a fourth point so that the distance between the midpoint and the second point is equal to the distance between the second point and the fourth point; Setting the fourth point as the control point corresponding to the second point; The marking points are obtained through the following process: Get all pixels within the selected range on the screen; Obtaining a capacitance value corresponding to the pixel point; The pixel point corresponding to the maximum capacitance value is selected as the marking point.
2. The curve smoothing method based on Bezier curve according to claim 1, characterized in that: The screen is a capacitive touch screen.
3. A system for a curve smoothing method based on a Bezier curve according to any one of claims 1 to 2, characterized in that: include: A first module for selecting marking points to be drawn according to the drawing order and marking the starting point and the ending point; A second module for setting control points corresponding to marking points excluding the starting point and the ending point by a preset method; The third module is used for generating a Bezier curve having a start point and an end point as two end points and passing through all the marked points according to the control points.
4. A device for a curve smoothing method based on a Bezier curve, characterized in that: include: a memory in which a computer program is stored; A processor, which implements the curve smoothing method based on Bezier curve as described in any one of claims 1 to 2 when executing the computer program.
5. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the curve smoothing method based on the Bezier curve as described in any one of claims 1 to 2 is implemented.
