Curve generation method and device, electronic device and readable storage medium
By generating curve control points and model sampling technology, the problem of difficulty in drawing smooth handwriting by user input points is solved, and a more stable and beautiful drawing effect is achieved, which is suitable for applications such as pen-shaped simulation.
Patent Information
- Application Number
- CN202011289862.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-17
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2040-11-17
AI Technical Summary
In the prior art, when generating handwriting, it is difficult for user input point sampling to draw smooth and continuous handwriting, which is affected by user usage habits and stroke speeds.
By obtaining user input points, generating curve control points, determining the curve generation model, and sampling the model, obtaining sampling points evenly distributed along the curve to draw a smooth and continuous target curve.
It improves the stability and aesthetics of the drawing algorithm, increases the user experience, and is suitable for applications such as pen-shaped simulation.
Smart Images

Figure CN112270730B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and more specifically, to a curve generation method, a curve generation apparatus, an electronic device, and a readable storage medium. Background Art
[0002] In related technologies, electronic devices can perform handwriting operations via touchscreens or styluses. When generating handwriting, it is necessary to sample the trajectory of the user's finger or stylus movement to obtain multiple input points, and then draw the corresponding strokes based on the input points. However, due to different user habits, the speed of pen movement varies when writing different strokes, so the sampled input points cannot accurately produce smooth and continuous handwriting. Summary of the Invention
[0003] Embodiments of the present application provide a curve generating method, a curve generating device, an electronic device, and a readable storage medium.
[0004] The curve generation method of this application includes: sequentially acquiring user input points and generating curve control points based on the user input points; determining a curve generation model based on the user input points and the curve control points; sampling the curve generation model to obtain sampling points uniformly distributed along the curve corresponding to the curve generation model, and drawing a target curve using the sampling points.
[0005] The curve generation device according to the embodiments of this application includes an acquisition module, a determination module, and a processing module. The acquisition module is used to acquire user input points in sequence and generate curve control points based on the user input points. The determination module is used to determine a curve generation model based on the user input points and the curve control points. The processing module is used to sample the curve generation model to obtain sampling points that are uniformly distributed along the curve corresponding to the curve generation model, and to draw a target curve using the sampling points.
[0006] The electronic device according to the embodiments of this application includes one or more processors and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, it implements the curve generation method of the above embodiments.
[0007] The readable storage medium of the embodiment of the present application stores a computer program, and when the computer program is executed by one or more processors, the curve generating method of the above embodiment is implemented.
[0008] In the curve generation method, curve generation device, electronic device, and storage medium of this embodiment, curve control points are generated based on the acquired user input points. A curve generation model is obtained based on the user input points and curve control points. Based on the curve generation model, corresponding sampling points are obtained from sampling, so that the sampling points in the generated target curve are evenly distributed in both the straight and curved parts, that is, a smooth and continuous target curve is generated. It can be widely used in applications such as pen shape simulation to improve the stability and correctness of the drawing algorithm, as well as the aesthetics of the drawing results, and enhance the user experience.
[0009] Additional aspects and advantages of the embodiments of the present application will be given in part in the description below, and in part will become obvious from the description below, or will be learned through practice of the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, wherein:
[0011] Figure 1 It is a flow chart of the curve generation method according to the embodiment of the present application.
[0012] Figure 2 This is a schematic diagram of the curve generation apparatus according to an embodiment of this application.
[0013] Figure 3 It is another flowchart of the curve generation method according to the embodiment of the present application.
[0014] Figure 4 It is a graphical drawing diagram of the curve generation method according to the embodiment of the present application.
[0015] Figure 5 This is another flowchart of the curve generation method according to the embodiment of the present application.
[0016] Figure 6 This is another schematic diagram of the curve generation method according to the embodiments of this application.
[0017] Figure 7 This is another schematic diagram of the curve generation method according to the embodiments of this application.
[0018] Figure 8 This is another flowchart of the curve generation method according to the embodiment of the present application.
[0019] Figure 9 This is another graphical drawing diagram of the curve generation method according to the embodiments of this application.
[0020] Figure 10 This is another schematic diagram of the curve generation method according to the embodiments of this application.
[0021] Figure 11 This is another schematic diagram of the curve generation method according to the embodiments of this application.
[0022] Figure 12 This is another schematic diagram of the curve generation method according to the embodiments of this application.
[0023] Figure 13 This is another graphical drawing diagram of the curve generation method according to the embodiments of this application.
[0024] Figure 14 This is another schematic diagram of the curve generation method according to the embodiments of this application.
[0025] Figure 15 It is a module schematic diagram of an electronic device according to an embodiment of the present application.
[0026] Figure 16 This is a schematic diagram of a readable storage medium according to an embodiment of this application.
[0027] Description of main component symbols:
[0028] Curve generation device 10, acquisition module 11, auxiliary unit 111, determination unit 112, determination module 12, processing module 13, electronic device 100, processor 20, memory 30, computer program 32, and readable storage medium 40. DETAILED DESCRIPTION
[0029] The embodiments of this application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.
[0030] See also Figure 1 and Figure 2 This application provides a curve generation method for processing user input points to obtain a corresponding curve generation model. By resampling the curve generation model of control points, the sampling points are uniformly distributed on the target curve. In this way, by using curves instead of straight lines to interpolate the user input points, the target curve can be smooth and continuous, and it is not easy to produce obvious creases.
[0031] The curve generation method of this application embodiment can be applied to the curve generation device 10 of this application embodiment. That is to say, the curve generation device 10 of this application embodiment can use the curve generation method of this application embodiment to process the user input points to obtain the corresponding curve generation model. By resampling the curve generation model of the control points, the sampling points are uniformly distributed on the target curve. In this way, by using curves instead of straight lines to interpolate the user input points, the target curve can be smooth and continuous, and it is not easy to produce obvious creases.
[0032] In some implementations, the curve generation method includes:
[0033] Step S10: Obtain user input points in sequence and generate curve control points based on user input points;
[0034] Step S20: Determine the curve generation model based on the user input points and curve control points; and
[0035] Step S30: Sample the curve generation model to obtain sampling points that are uniformly distributed along the curve corresponding to the curve generation model, and draw the target curve using the sampling points.
[0036] Accordingly, the curve generation device 10 may include an acquisition module 11, a determination module 12, and a processing module 13. Step S10 can be implemented by the acquisition module 11, step S20 by the determination module 12, and step S30 by the processing module 13. That is, the acquisition module 11 can be used to acquire user input points sequentially and generate curve control points based on the user input points. The determination module 12 can be used to determine the curve generation model based on the user input points and the curve control points. The processing module 13 can be used to resample according to the curve generation model to obtain sampling points uniformly distributed along the curve corresponding to the curve generation model, and draw the generated target curve using the sampling points.
[0037] The curve generation method and curve generation apparatus 10 of this application generate curve control points based on the acquired user input points, thereby obtaining a curve generation model based on the user input points and curve control points. The curve generation model is sampled so that the sampled points are evenly distributed along the curve corresponding to the curve generation model, and the path lengths of any two adjacent sampled points along the curve corresponding to the curve generation model are equal, thereby generating a smooth and continuous target curve. It can be widely used in applications such as pen shape simulation to improve the stability and correctness of the drawing algorithm, as well as the aesthetics of the drawing results, and enhance the user experience.
[0038] In step S1, the user input point is the line segment drawn by the user by sliding their finger or stylus on the touchscreen (i.e., the input event). The curve generation device 10 collects the input events at a certain frequency to obtain multiple user input points. The multiple user input points record the coordinate position of the user's finger or stylus on the touchscreen and the corresponding collection time. By sorting the multiple user input points according to the collection time, user input points with a collection order can be obtained.
[0039] The frequency of collecting user input points can be a system-preset frequency. For example, the curve generation device 10 can be preset to a collection frequency of 3, 5, 10, 15, 30 points / second, or one of other frequencies. Alternatively, the frequency can be selected or entered by the user. For instance, the user can select the speed at which line segments are recognized. When the user selects a slow speed, the collection frequency can be 3 points / second; when the user selects a medium speed, the collection frequency can be 5 points / second; and when the user selects a fast speed, the collection frequency can be 10 points / second. In one example, a collection frequency of 5 points / second means that the curve generation device 10 can continuously collect the coordinate positions of the user's finger or stylus on the touchscreen at 0.2-second intervals.
[0040] Furthermore, curves can be drawn by combining user input points and curve control points. Specifically, obtaining curve control points based on user input points can be used to represent the trend of curve extension and provide directional information.
[0041] In step S2, the curve generation model refers to a mathematical model determined by certain rules based on user input points and curve control points. According to the curve generation model, a line segment passing through the corresponding user input point can be determined. In addition to the user input point, the curve generation model can also determine the coordinate position of any point on the curve corresponding to the model on the screen.
[0042] In step S3, the curve length can be calculated by obtaining the coordinate position of any point on the curve corresponding to the curve of the curve generation model on the screen. Then, sampling based on the curve length on the curve corresponding to the model can obtain sampling points that are evenly distributed along the curve of the curve generation model. This ensures that the sampling points in the generated target curve are evenly distributed in both the straight and curved parts, improving the stability and correctness of the drawing algorithm.
[0043] See also Figure 3 and Figure 4 In some implementations, step S10 includes:
[0044] Step S11: Draw an auxiliary line segment through the midpoint of the line connecting the current user input point and the previous user input point, and through the midpoint of the line connecting the current user input point and the next user input point.
[0045] Step S12, drawing a control line segment parallel to the auxiliary line segment through the current user input point and with the current user input point as the midpoint; and
[0046] Step S13: Determine the curve control points based on the control line segments.
[0047] Accordingly, acquisition module 11 includes an auxiliary unit 111 and a determination unit 112. Steps S11 and S12 can be implemented by auxiliary unit 111, and step S13 can be implemented by determination unit 112. In other words, auxiliary unit 111 can be used to create an auxiliary line segment passing through the midpoint of the line connecting the current user input point and the previous user input point, and the midpoint of the line connecting the current user input point and the next user input point, and to create a control line segment parallel to the auxiliary line segment passing through the current user input point and with the current user input point as its midpoint. Determination unit 112 can be used to determine the curve control points based on the control line segments.
[0048] In this embodiment, an auxiliary line segment is drawn through the midpoint of the line connecting the current user input point and the adjacent user input point. Then, a control line segment is drawn through the current user input point in a manner parallel to the auxiliary line segment to determine the curve control point.
[0049] exist Figure 4 In the illustrated embodiment, the user input points obtained in sequence are P1, P2, P3, and P4. Thus, for the user input point P2, an auxiliary line segment K1-K2 can be made through the midpoint K1 of the line segment P1-P2 and the midpoint K2 of the line segment P2-P3. Then, a control line segment Q21-Q23 parallel to the auxiliary line segment K1-K2 is made through P2 with P2 as the midpoint, thereby determining the curve control point based on the control line segment Q21-Q23, wherein Q21 is the endpoint of the control line segment Q21-Q23 close to P1, and Q23 is the endpoint of the control line segment Q21-Q23 close to P3. For user input point P3, we can draw an auxiliary line segment K2-K3 based on the midpoint K2 of P2-P3 and passing through the midpoint K3 of P3-P4. Then, we can draw a control line segment Q32-Q34 parallel to the auxiliary line segment K2-K3 with P3 as the midpoint. Thus, we can determine the curve control point based on the control line segment Q32-Q34.
[0050] It should be noted that the illustrated embodiment uses 4 user input points as an example. In other embodiments, the number of user input points is not limited to 4, but can be any number of 3 or more.
[0051] Please see Figure 5 In some implementations, step S12 includes:
[0052] Step S121: Determine the length of the control line segment based on the ratio between the distance between the current user input point and the previous user input point and the distance between the current user input point and the next user input point;
[0053] Step S13 includes:
[0054] Step S131: Determine the endpoints of the control line segment as curve control points.
[0055] Specifically, step S121 can be implemented by auxiliary unit 111, and step S131 can be implemented by determining unit 112. That is, auxiliary unit 111 can be used to determine the length of the control line segment based on the ratio between the distance between the current user input point and the previous user input point and the distance between the current user input point and the next user input point. Determining unit 112 can be used to determine the endpoints of the control line segment as curve control points.
[0056] Thus, the length of the control line segment is determined by the ratio of the distance between the current user input point and the adjacent user input points. This makes the curve extension trend controlled by the curve control point determined by the endpoint of the control line segment related to the two adjacent user input points, which is more conducive to the control curve generation model obtaining a smooth and continuous curve.
[0057] exist Figure 4 In this embodiment, when the current user input point is P2, the previous user input point of P2 is P1, and the next user input point of P2 is P3. At this time, the distance between the current user input point and the previous user input point is |P1-P2|, and the distance between the current user input point and the next user input point is |P2-P3|. Therefore, the length of the control line segment Q21-Q23 can be: |Q21-Q23|=|P1-P2| / |P2-P3|*k, where k is a proportional coefficient, which can be flexibly configured as needed. Furthermore, the endpoints Q21 and Q23 of the control line segment Q21-Q23 can be determined as curve control points.
[0058] Please see Figure 6 In some implementations, step S20 includes:
[0059] Step S21: Determine two adjacent user input points and the curve control point located between the two adjacent user input points; and
[0060] Step S22: Based on the Bézier curve, determine the curve generation model using two adjacent input points and the curve control point located between two adjacent user input points.
[0061] Accordingly, step S21 and step S22 can be implemented by the determination module 12. That is, the determination module 12 can be used to determine two adjacent user input points and the curve control points located between the two adjacent user input points, and to determine a curve generation model based on the Bezier curve using the two adjacent input points and the curve control points located between the two adjacent user input points.
[0062] For drawing a line segment, a Bezier curve can be drawn using a start point, an end point, and a control node located between the start and end points. This application determines a corresponding curve generation model based on the Bezier curve by determining two adjacent user input points and a curve control point located between the two adjacent user input points. Specifically, a Bezier curve can be drawn based on the curve generation model, passing through two adjacent user input points.
[0063] Since the curve corresponding to the curve generation model passes through the user input point, and the curve control point represents the trend of the curve extension and provides direction information, the curve corresponding to the curve generation model may not pass through the curve control point. Therefore, when determining the corresponding curve generation model based on the Bezier curve, it is necessary to use two adjacent user input points as the starting point and the end point, and combine the curve control points located between the two user input points to generate the curve generation model. According to understanding, when the above method determines the curve control point, the current user input point can correspond to two curve control points, where one curve control point is located between the current user input point and the next user input point, and the other curve control point is located between the current user input point and the next user input point. In this way, for any two adjacent user input points, such as Figure 4 As shown, P2 can correspond to two curve control points Q21 and Q23, P3 can correspond to two curve control points Q32 and Q34, the curve control point between the user input points P1 and P2 is Q21; the curve control points between the user input points P2 and P3 are Q23 and Q32, and the curve control point between the user input points P3 and P4 is Q34.
[0064] In step S22, the curve generation model determined based on the Bézier curve takes two adjacent user input points as the start and end points respectively. That is to say, the curve corresponding to the curve generation model determined by two adjacent user input points and the curve control point located between the two adjacent user input points is the curve between the two adjacent user input points. Therefore, any two adjacent user input points can determine a curve generation model.
[0065] See also Figure 7 In some embodiments, the user input point includes a starting input point, and step S10 includes:
[0066] Step S14: In the control line segment corresponding to the next user input point of the starting input point, the endpoint closest to the starting input point is determined as the curve control point between the starting input point and the next user input point of the starting input point;
[0067] Step S20 includes:
[0068] Step S23: Based on the second-order Bézier curve, determine the curve generation model using the starting input point, the next user input point of the starting input point, and the curve control points located between the starting input point and the next user input point of the starting input point.
[0069] Accordingly, step S14 can be implemented by determination unit 112, and step S23 can be implemented by determination module 12. That is, determination unit 112 can be configured to determine, within the control line segment corresponding to the next user input point after the starting input point, the endpoint closest to the starting input point as the curve control point between the starting input point and the next user input point after the starting input point. Determination module 12 can be configured to determine a curve generation model based on a second-order Bezier curve, using the starting input point, the next user input point after the starting input point, and the curve control points between the starting input point and the next user input point after the starting input point.
[0070] It can be understood that for the starting input point, the starting input point has only one adjacent user input point, and its corresponding control point cannot be determined by making auxiliary line segments and control line segments. For the next user input point after the starting input point (i.e., the second user input point), since the control line segment takes the second user input point as the midpoint, the endpoints of the control line segment are located on both sides of the second input point, so there is only one curve control point between the starting input point and the second input point. In this way, the starting input point and the second user input point can determine the curve generation model based on the second-order Bezier curve.
[0071] like Figure 4 As shown, the initial user input point is P1. For the second user input point P2, the curve control point between P1 and P2 is the endpoint Q21 of the control line segment Q21-Q23 passing through P2, which is closer to P1. When there is only one curve control point Q21 between P1 and P2, the curve generation model can be determined based on the second-order Bézier curve using P1, P2, and Q21.
[0072] Please see Figure 8 and Figure 9 In some embodiments, the user input point includes a starting input point, and step S10 includes:
[0073] Step S15, generating a simulated input point located before the starting input point according to the starting input point and the next user input point of the starting input point;
[0074] Step S16: Based on the analog input point, the starting input point, and the next user input point of the starting input point, determine the control line segment corresponding to the starting input point; and
[0075] Step S17: In the control line segment corresponding to the starting input point, the endpoint of the next user input point that is closer to the starting input point, and the end of the control line segment corresponding to the next user input point that is closer to the starting input point, are determined as the curve control point between the starting input point and the next user input point.
[0076] Step S20 includes:
[0077] Step S24: Based on the third-order Bézier curve, determine the curve generation model using the starting input point, the next user input point of the starting input point, and the curve control points located between the starting input point and the next user input point of the starting input point.
[0078] Accordingly, steps S15 and S16 can be implemented by auxiliary unit 111, step S17 can be implemented by determining unit 112, and step S24 can be implemented by determining module 12. That is, auxiliary unit 111 can be used to generate a simulated input point located before the starting input point based on the starting input point and the next user input point of the starting input point, and to determine the control line segment corresponding to the starting input point based on the simulated input point, the starting input point, and the next user input point of the starting input point. Determining unit 112 can be used to determine the endpoints of the control line segments corresponding to the starting input point that are closest to the next user input point of the starting input point, and the endpoints of the control line segments corresponding to the next user input point of the starting input point that are closest to the starting input point, as curve control points between the starting input point and the next user input point of the starting input point. Determining module 12 can be used to determine the curve generation model based on a third-order Bézier curve, using the starting input point, the next user input point of the starting input point, and the curve control points located between the starting input point and the next user input point of the starting input point.
[0079] Thus, by adding simulated input points, the starting input point can have two adjacent input points, allowing the curve control point corresponding to the starting input point to be determined by drawing auxiliary and control line segments. Furthermore, there can be two curve control points between the starting and second input points, enabling the curve generation model to be determined based on a third-order Bézier curve for both the starting and second user input points.
[0080] like Figure 9As shown, to ensure that the initial user input point P1 can also determine the curve control point corresponding to P1 using the methods described in steps S11-S13, a simulated input point P0 is added before P1. An auxiliary line segment K0-K1 can be constructed using the midpoints K0 of line segments P0-P1 and P1-P2. Then, a control line segment Q10-Q12 is constructed parallel to the auxiliary line segment K0-K1 through P1. This allows the endpoint Q12 of the control line segment Q10-Q12 corresponding to P1, close to P2, and the endpoint Q21 of the control line segment Q21-Q23 corresponding to P2, close to P1, to be determined as the curve control point between P1 and P2. With two curve control points Q12 and Q21 between P1 and P2, the curve generation model can be determined based on a third-order Bézier curve using P1, P2, Q12, and Q21.
[0081] exist Figure 9 In the illustrated embodiment, the simulated input point is obtained by extending a predetermined distance from the starting input point along the direction from the second input point to the starting input point. In other embodiments, the simulated input point can be determined in other ways according to actual needs, and no specific limitation is made here.
[0082] Please see Figure 10 In some implementations, the user input point includes a last input point, and step S1 includes:
[0083] Step S14': In the control line segment corresponding to the user input point above the last input point, the endpoint closest to the last input point is determined as the curve control point between the user input point above the last input point and the last input point.
[0084] Step S20 includes:
[0085] Step S25: Based on the second-order Bézier curve, determine the curve generation model using the previous user input point of the last input point, the last input point, and the curve control point located between the previous user input point and the last input point.
[0086] Accordingly, step S14' can be implemented by the determining unit 112, and step S25 can be implemented by the determining module 12. That is, the determining unit 112 can be used to determine the endpoint closest to the last input point in the control line segment corresponding to the user input point preceding the last input point as the curve control point between the user input point preceding the last input point and the last input point. The determining module 12 can be used to determine the curve generation model based on the second-order Bézier curve, using the user input point preceding the last input point, the last input point, and the curve control point located between the user input point preceding the last input point and the last input point.
[0087] Similarly, for the last input point, there is only one adjacent user input point. It is impossible to determine its corresponding control point by drawing auxiliary line segments and control line segments. Therefore, there is only one curve control point between the last input point and the user input point above the last input point. Thus, the curve generation model between the last input point and the user input point above the last input point can be determined based on the second-order Bézier curve.
[0088] Likewise, if Figure 4 As shown, the last input point is P4. For the previous user input point P3, the curve control point between P3 and P4 is the endpoint Q34 of the control line segment Q32-Q34 passing through P3, which is closer to P4. When there is only one curve control point Q34 between P3 and P4, the curve generation model can be determined based on the second-order Bézier curve using P3, P4, and Q34.
[0089] Please see Figure 9 and Figure 11 In some implementations, the user input point includes a last input point, and step S10 includes:
[0090] Step S15': Based on the previous user input point and the last input point, generate a predicted input point that follows the last input point;
[0091] Step S16': Based on the predicted input point, the last input point, and the user input point preceding the last input point, determine the control segment corresponding to the last input point; and
[0092] Step S17': In the control line segment corresponding to the last input point, the endpoint of the user input point above the last input point that is closer to the last input point, and the endpoint of the control line segment corresponding to the user input point above the last input point that is closer to the last input point, are determined as the curve control point located between the user input point above the last input point and the last input point.
[0093] Step S20 includes:
[0094] Step S26: Based on the third-order Bézier curve, determine the curve generation model using the user input point before the last input point, the last input point, and the curve control point located between the user input point before the last input point and the last input point.
[0095] Accordingly, steps S15' and S16' can be implemented by auxiliary unit 111, step S19 can be implemented by determining unit 112, and step S26 can be implemented by determining module 12. That is, auxiliary unit 111 can be used to generate a predicted input point located after the last input point based on the previous user input point and the last input point, and to determine the control line segment corresponding to the last input point based on the predicted input point, the last input point, and the previous user input point. Determining unit 112 can be used to determine the endpoint closest to the previous user input point in the control line segment corresponding to the last input point, and the endpoint closest to the last input point in the control line segment corresponding to the previous user input point, as the curve control point between the previous user input point and the last input point. The determination module 12 can be used to determine the curve generation model based on the third-order Bézier curve, using the previous user input point of the last input point, the last input point, and the curve control point located between the previous user input point and the last input point.
[0096] Thus, by adding predicted input points, the last input point can have two adjacent input points, allowing the curve control point corresponding to the last input point to be determined by drawing auxiliary and control line segments. Furthermore, there can be two curve control points between the last input point and the user input point preceding it, enabling the curve generation model to be determined based on a third-order Bézier curve.
[0097] like Figure 9 As shown, to ensure that the curve control point corresponding to the last user input point P4 can also be determined according to the methods described in steps S11-S13, a predicted input point Px can be added after P4. An auxiliary line segment K3-K4 can be constructed using the midpoint K4 of line segment P4-Px and the midpoint K3 of line segment P3-P4. Then, a control line segment Q43-Q4x is constructed parallel to the auxiliary line segment K3-K4 through P4. This allows the endpoint Q43 of the control line segment Q43-Q4x corresponding to P4, near P3, and the endpoint Q34 of the control line segment Q32-Q34 corresponding to P3, near P4, to be determined as the curve control point between P3 and P4. With two curve control points Q34 and Q43 between P3 and P4, a curve generation model can be determined based on a third-order Bézier curve using P3, P4, Q34, and Q43.
[0098] exist Figure 9In the illustrated embodiment, the predicted input point is the input point obtained by extending a predetermined distance from the last input point along the direction from the previous user input point to the last input point. In other embodiments, the last input point can be determined in other ways according to actual needs, and no specific limitation is made here. For example, the velocity and direction corresponding to each input point can be determined by the sampling rate of the user input points and the positional relationship of each user input point, and then the predicted input point can be obtained by using the Kalman algorithm.
[0099] Please see Figure 12 and Figure 13 In some implementations, step S30 includes:
[0100] Step S31: Use Simpson's integral method to analyze the curve generation model to obtain the curve length at any point on the curve corresponding to the curve generation model;
[0101] Step S32: determining the model parameters corresponding to the preset curve length, and obtaining sampling points evenly distributed along the curve to generate a model corresponding to the curve according to the model parameters.
[0102] Accordingly, steps S31 and S32 can be implemented by processing module 13. That is, processing module 13 can be used to analyze the curve generation model using Simpson's integral method to obtain the curve length of any point on the curve corresponding to the curve generation model, and to determine the model parameters corresponding to the preset curve length, and to obtain sampling points uniformly distributed along the curve corresponding to the curve generation model based on the model parameters.
[0103] Thus, the curve length of each point on the curve corresponding to the curve generation model can be calculated using the Simpson integral method. Then, the model parameters corresponding to the preset curve length can be determined on the curve generation model. The curve corresponding to the curve generation model can be resampled according to the preset curve length to obtain sampling points that are uniformly distributed along the curve corresponding to the curve generation model.
[0104] Since any two adjacent user input points can determine a curve generation model (meaning the curve generation models between two adjacent user input points can be different), each curve generation model can correspond to a curve segment, and these segments are connected to form the target curve. Thus, in step S32, the curve length of the sub-segment formed by every two sampling points after resampling is the preset curve length. Figure 13 In the illustrated embodiment, sampling points (R1 to R12) evenly distributed along the curve corresponding to the curve generating model can be obtained according to the model parameters.
[0105] Specifically, if Figure 13As shown, based on the curve generation model corresponding to P1 to P2, starting from the initial user input point P1, a sampling point R1 can be determined after passing through a preset curve length. Then, starting from sampling point R1, the next sampling point R2 can be determined after passing through a preset curve length. Then, starting from sampling point R2, the next sampling point R3 can be determined again after passing through a preset curve length. This process is repeated until the sampling of the curve generation model corresponding to P1 to P2 ends.
[0106] It should be noted that for the curve generation model corresponding to P1 to P2, if the calculated curve length from R3 to P2 does not meet the preset curve length, starting from a certain sampling point, such as R3, then the curve length from R3 to P2 is recorded. Then, in the curve generation model corresponding to the next curve segment P2 to P3, the preset curve length is subtracted from the curve length from R3 to P2 to obtain the supplementary curve length. Then, starting from P2, a sampling point R4 is determined after the supplementary curve length. Thus, the curve length between R3 and R4 is the sum of the curve lengths from R3 to P2 and from P2 to R4, which is the preset curve length. By supplementing the curve lengths of P2 and R4 to the curve lengths of R3 and P2, the curve length between these two adjacent sampling points (R3 and R4) across the user input point is guaranteed to be the preset curve length. Then, starting from R4, after the preset curve length, the next sampling point R5 can be determined again, and this process is repeated until all curve generation models have been sampled.
[0107] See also Figure 14 In some implementations, the curve generation method includes:
[0108] Step S40: When the next new input point is obtained after the last input point, the curve generation model is redefined using the new input point instead of the predicted input point; and
[0109] Step S50: Update the sampling points between the previous user input point and the last input point based on the redefined curve generation model.
[0110] Accordingly, step S40 can be implemented by the determining module 12, and step S50 can be implemented by the processing module 13. That is, the determining module 12 can be used to redefine the curve generation model by replacing the predicted input point with the new input point when the next new input point is obtained after the last input point. The processing module 13 can be used to update the sampling points between the previous user input point and the last input point according to the redefined curve generation model.
[0111] It is understood that this application can acquire user input points in real time when generating curves and draw corresponding curves for user input points in real time. Therefore, in the process of determining curve control points by predicting input points and resampling, the sampling point of the last line segment resampling is based on the predicted input points. For newly acquired input points during continuous input, the actual newly acquired input points should replace the predicted input points to recalculate the sampling point of the last line segment resampling.
[0112] See also Figure 15 This application provides an electronic device 100, which includes one or more processors 20 and a memory 30. The memory 30 stores a computer program 32. When the computer program 32 is executed by one or more processors 20, it implements the curve generation method of any of the above embodiments.
[0113] In one example, when computer program 32 is executed by processor 20, it performs the following steps:
[0114] Step S10: Obtain user input points in sequence and generate curve control points based on user input points;
[0115] Step S20: Determine the curve generation model based on the user input points and curve control points; and
[0116] Step S30: Sample the curve generation model to obtain sampling points that are uniformly distributed along the curve corresponding to the curve generation model, and draw the target curve using the sampling points.
[0117] In the electronic device 100 of this application embodiment, the processor 20 executes the computer program 32 to implement the curve generation method of this application embodiment. Based on the acquired user input points, curve control points are generated, thereby obtaining a curve generation model according to the user input points and curve control points. The curve generation model is sampled so that the sampled points are evenly distributed along the curve corresponding to the curve generation model. The path lengths of any two adjacent sampled points along the curve corresponding to the curve generation model are equal, thereby generating a smooth and continuous target curve. This method can be widely used in applications such as pen shape simulation to improve the stability and correctness of the drawing algorithm, as well as the aesthetics of the drawing results, and enhance the user experience.
[0118] In some embodiments, the curve generating device 10 may be part of the electronic device 100. In other words, the electronic device 100 includes the curve generating device 10.
[0119] In some embodiments, the curve generation device 10 may be a discrete component assembled in a certain way to have the aforementioned functions, or a chip having the aforementioned functions in the form of an integrated circuit, or a computer software code segment that enables the computer to have the aforementioned functions when run on a computer.
[0120] In some implementations, the curve generation device 10 may be installed as hardware, either independently or as an additional peripheral component into a computer or computer system. The curve generation device 10 may also be integrated into the computer or computer system; for example, when the curve generation device 10 is part of the electronic device 100, it may be integrated into the processor 20.
[0121] In some embodiments, the curve generation device 10 is part of the electronic device 100. As software, the code segment corresponding to the electronic device 100 can be stored in the memory 30 and executed on the processor 20 to implement the aforementioned functions. Alternatively, the curve generation device 10 includes one or more of the aforementioned computer programs 32, or the aforementioned one or more computer programs 32 include the curve generation device 10.
[0122] See also Figure 16 This application provides a readable storage medium 40 storing a computer program 32, which, when executed by one or more processors 20, implements the curve generation method of any of the above embodiments.
[0123] In the description of this specification, references to terms such as "one embodiment," "some embodiments," or "an example," etc., indicate that a specific feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0124] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.
[0125] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0126] Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of this application.
Claims
1. A curve generation method for processing user input points, characterized in that: include: The user input points are acquired in sequence and curve control points are generated according to the user input points, wherein the user input points record the coordinate positions of the user's finger or stylus on the touch screen and the corresponding acquisition time, and the curve control points are used to indicate the extension trend of the curve; Determine a curve generation model according to the user input point and the curve control point, and determine the coordinate position of any point on the curve corresponding to the curve generation model on the screen according to the curve generation model; and Analyzing the curve generation model using the Simpson integral method to obtain the curve length of any point on the curve corresponding to the curve generation model; The model parameters corresponding to the preset curve length are determined, and sampling points evenly distributed along the curve corresponding to the curve generation model are obtained according to the model parameters, and the target curve is drawn with the sampling points as the user's handwriting.
2. The curve generation method according to claim 1, characterized in that: The obtaining of user input points in sequence and generating curve control points according to the user input points comprises: Make an auxiliary line segment through the midpoint of the line connecting the current user input point and the previous user input point, and through the midpoint of the line connecting the current user input point and the next user input point; A control line segment is made parallel to the auxiliary line segment through the current user input point and with the current user input point as the midpoint; and The curve control point is determined according to the control line segment.
3. The curve generation method according to claim 2, characterized in that: The control line segment passing through the current user input point and being parallel to the auxiliary line segment with the current user input point as the midpoint comprises: determining the length of the control line segment according to a ratio between a distance between the current user input point and a previous user input point and a distance between the current user input point and a next user input point; Determining the curve control point according to the control line segment comprises: The endpoints of the control line segments are determined as the curve control points.
4. The curve generating method according to claim 2, characterized in that: Determining the curve generation model according to the user input point and the curve control point comprises: determining two adjacent user input points and the curve control point located between the two adjacent user input points; and Based on the Bezier curve, the curve generation model is determined by using two adjacent input points and the curve control point located between the two adjacent user input points.
5. The curve generation method according to claim 2, characterized in that: The user input point includes a starting input point, and the step of sequentially acquiring the user input points and generating curve control points according to the user input points includes: In the control line segment corresponding to the next user input point of the starting input point, an endpoint close to the starting input point is determined as a curve control point between the starting input point and the next user input point of the starting input point; Determining the curve generation model according to the user input point and the curve control point comprises: Based on a second-order Bezier curve, the curve generation model is determined by the starting input point, the next user input point of the starting input point, and a curve control point between the starting input point and the next user input point of the starting input point.
6. The curve generation method according to claim 2, characterized in that: The user input point includes a starting input point, and the step of sequentially acquiring the user input points and generating curve control points according to the user input points includes: generating a simulated input point located before the starting input point according to the starting input point and the next user input point of the starting input point; Determine a control line segment corresponding to the starting input point according to the simulated input point, the starting input point and the next user input point of the starting input point; and In the control line segment corresponding to the starting input point, an endpoint close to the next user input point of the starting input point and an endpoint close to the starting input point in the control line segment corresponding to the next user input point of the starting input point are determined as curve control points between the starting input point and the next user input point of the starting input point; Determining the curve generation model according to the user input point and the curve control point comprises: Based on a third-order Bezier curve, the curve generation model is determined by the starting input point, the next user input point of the starting input point, and a curve control point between the starting input point and the next user input point of the starting input point.
7. The curve generation method according to claim 2, characterized in that: The user input point includes the last input point, and the acquiring the user input points in sequence and generating the curve control points according to the user input points includes: In the control line segment corresponding to the user input point immediately preceding the last input point, an endpoint close to the last input point is determined as a curve control point between the user input point immediately preceding the last input point and the last input point; Determining the curve generation model according to the user input point and the curve control point comprises: Based on a second-order Bezier curve, the curve generation model is determined by using the user input point previous to the last input point, the last input point, and a curve control point between the user input point previous to the last input point and the last input point.
8. The curve generation method according to claim 2, characterized in that: The user input point includes the last input point, and the acquiring the user input points in sequence and generating the curve control points according to the user input points includes: generating a predicted input point after the last input point according to the user input point before the last input point and the last input point; Determine a control line segment corresponding to the last input point according to the predicted input point, the last input point and the user input point immediately before the last input point; and In the control line segment corresponding to the last input point, an endpoint close to the last user input point, and in the control line segment corresponding to the last user input point, an endpoint close to the last input point, are determined as curve control points between the last user input point and the last input point; Determining the curve generation model according to the user input point and the curve control point comprises: Based on a third-order Bezier curve, the curve generation model is determined by using the user input point previous to the last input point, the last input point, and a curve control point between the user input point previous to the last input point and the last input point.
9. The curve generating method according to claim 8, characterized in that: The curve generating method comprises: When a next newly added input point after the last input point is obtained, the curve generation model is re-determined by replacing the predicted input point with the newly added input point; and The sampling points between the user input point previous to the last input point and the last input point are updated according to the re-determined curve generation model.
10. A curve generating device, characterized in that: include: An acquisition module, the acquisition module is used to sequentially acquire user input points and generate curve control points according to the user input points, the user input points record the coordinate position of the user's finger or stylus on the touch screen and the corresponding acquisition time, and the curve control points are used to indicate the extension trend of the curve; A determination module, the determination module is used to determine a curve generation model according to the user input point and the curve control point, and can determine the coordinate position of any point on the curve corresponding to the curve generation model on the screen according to the curve generation model; and A processing module, the processing module is used to analyze the curve generation model using the Simpson integral method to obtain the curve length of any point on the curve corresponding to the curve generation model, and to determine the model parameters corresponding to the preset curve length, and obtain sampling points evenly distributed along the curve corresponding to the curve generation model according to the model parameters, and draw a target curve with the sampling points as the user's handwriting.
11. An electronic device, characterized in that: The method comprises one or more processors and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the curve generating method according to any one of claims 1 to 9 is implemented.
12. A readable storage medium storing a computer program, characterized in that: When the computer program is executed by one or more processors, the curve generating method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Track smoothing method and device
CN103500037A
Writing trace demonstration method and apparatus applied to writing brush
CN105046730A
Handwriting rendering method, device, interactive intelligent tablet computer, and storage medium
CN109284059A