A CAD curve fitting optimization method based on scribe line scene

By calculating the instantaneous velocity and local curvature values ​​of sampling points in CAD curve fitting, identifying the intended sharp corner points and constructing a geometric association index, the problem of fitting results deviating from the design idea in the existing technology due to user hand-drawn input is solved, and higher precision curve fitting and shape expression are achieved.

CN120850562BActive Publication Date: 2026-04-28FOSHAN DAOSHAN INTELLIGENT ROBOT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
FOSHAN DAOSHAN INTELLIGENT ROBOT CO LTD
Filing Date
2025-07-10
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing CAD curve fitting technology lacks an understanding of the semantic structure and behavioral intent of strokes when processing user hand-drawn input, causing the fitting results to deviate from the original design ideas. In particular, there is a lack of coordination and consistency among multiple structural curves, which can easily lead to problems such as breakage and skewing.

Method used

By using a line-drawing scenario-based approach, the instantaneous velocity and local curvature values ​​of sampling points are calculated to determine the confidence level, intentional sharp corners are filtered out, a geometric association index is generated, geometric constraints of the curve family are established, a piecewise fitting cost function is constructed, and constraint optimization is performed to generate an optimized fitting curve.

Benefits of technology

It improves the accuracy of curve fitting and the ability to reproduce user design intent, reduces curve deformation error, and enhances the quality of shape expression, especially performing excellently in free curve modeling and hand-drawn input curve analysis scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120850562B_ABST
    Figure CN120850562B_ABST
Patent Text Reader

Abstract

The present application relates to CAD curve fitting optimization technical field, specifically to a kind of CAD curve fitting optimization method based on scribing scene, comprising the following steps: based on the input sampling point sequence with time stamp, the instantaneous speed value and local curvature value of each sampling point in sequence are calculated, the confidence of each sampling point is determined, screening is carried out according to confidence, and the intended sharp corner point set is obtained.The present application extracts sampling point with time stamp, constructs confidence system in combination with instantaneous speed and local curvature, realizes the identification of intended feature point in user stroke, and enhances the semantic compatibility of curve segmentation.The corresponding point difference between stroke sampling points and potential symmetry transformation axis are combined and analyzed, can automatically construct the geometric correlation reflected based on user hand-drawing behavior, so that subsequent constraint modeling no longer depends on fixed rules but is dynamically generated based on actual input configuration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of CAD curve fitting optimization technology, and in particular to a CAD curve fitting optimization method based on line drawing scenarios. Background Technology

[0002] The field of CAD curve fitting and optimization technology mainly involves mathematical modeling and curve reconstruction of discrete point data in two-dimensional or three-dimensional space within a computer-aided design environment. Its core objective is to ensure both geometric accuracy and aesthetic appeal. Figure One Under the premise of consistency, smooth curves or surfaces that meet the engineering design requirements are generated by means of fitting, approximation, and constraint optimization.

[0003] Current technologies primarily rely on mathematical fitting and modeling of discrete points in space, often employing a purely curve approximation strategy. When handling user-generated input such as hand-drawn sketches, they lack an understanding of the semantic structure and behavioral intent of strokes, leading to fitting results that easily deviate from the original design intent. The fitting process commonly uses least-squares error as the sole optimization objective, neglecting geometric relationships between points such as parallelism or symmetry. This results in a lack of consistency among multiple structural curves, particularly when processing contours or symmetrical sketches composed of multiple line segments, making them more prone to breakage and skewness. Therefore, improvements are needed. Summary of the Invention

[0004] The purpose of this invention is to address the shortcomings of existing technologies by proposing a CAD curve fitting optimization method based on line drawing scenarios.

[0005] To achieve the above objectives, the present invention adopts the following technical solution: a CAD curve fitting optimization method based on a line drawing scenario, comprising the following steps:

[0006] Based on the input sequence of timestamped sampling points, the instantaneous velocity value and local curvature value of each sampling point in the sequence are calculated, the confidence level of each sampling point is determined, and the set of intentional sharp corner points is obtained by filtering according to the confidence level.

[0007] Based on the sampling point sequence of multiple strokes and the set of intentional sharp corners, the distance standard deviation between corresponding points of different curves is calculated, and the symmetry transformation axis is searched to generate a potential geometric association index. Based on the potential geometric association index, point pairs below the distance standard deviation threshold are determined to be parallel, and point pairs with a symmetry transformation axis are determined to be symmetric, thus establishing a set of geometric constraints for the family of curves.

[0008] Based on the set of intended sharp corner points and the set of geometric constraints of the curve family, the intended sharp corner points are set as piecewise nodes of the B-spline curve and C0 continuity constraints are applied to construct a piecewise fitting cost function; then the constraints in the set of geometric constraints of the curve family are merged into the piecewise fitting cost function to construct a constraint optimization objective function.

[0009] Solve the objective function of the constraint optimization to obtain the set of coordinates of the B-spline curve control points that satisfy all constraints; use the set of coordinates of the B-spline curve control points as the definition data for CAD curve fitting optimization to generate the optimized fitting curve.

[0010] Preferably, the step of obtaining the set of intentional sharp corner points is as follows:

[0011] Based on the input sequence of timestamped sampling points, the two-dimensional coordinates of each sampling point are extracted and the vector angle between adjacent points is calculated. The local curvature value of the current point is calculated using the vector angle. At the same time, the instantaneous velocity value of the current point is calculated by dividing the coordinate distance between two adjacent points by the time interval, thus obtaining the sampling point feature group.

[0012] Calculate the confidence value for each sampling point based on the feature group of the sampling points;

[0013] Based on the confidence value of each sampling point, all sampling points with confidence values ​​greater than the preset confidence threshold are filtered to generate an intent corner point set.

[0014] Preferably, the step of obtaining the potential geometric association index is as follows:

[0015] Based on the sampling point sequence of multiple strokes and the set of intentional corner points, each stroke is divided into multiple independent line segments defined by the intentional corner points, and the coordinates of the sampling points on each independent line segment are extracted in sequence to form an independent line segment coordinate sequence.

[0016] Based on the independent line segment coordinate sequence, the same percentage position points between line segments corresponding to different line strokes are determined according to the line segment length percentage segmentation method. The spatial coordinates of the same percentage position points are paired and the Euclidean distance between each pair of corresponding points is calculated. The standard deviation of the distance values ​​of all corresponding points is calculated to form a set of distance standard deviations.

[0017] Based on the aforementioned set of distance standard deviations, and taking the independent line segment coordinate sequence as a basis, all symmetry axis positions of the coordinate sequence are enumerated. By comparing the distance standard deviations of the coordinate sequences on both sides of different symmetry axes, the axis position that minimizes the distance standard deviation of the corresponding point is selected as the symmetry transformation axis, and the index of the independent line segment coordinate sequence associated with the symmetry transformation axis is marked as a potential geometric association index.

[0018] Preferably, the steps for obtaining the set of geometric constraints for the family of curves are as follows:

[0019] Based on the potential geometric association index, extract all coordinate point pairs of the corresponding independent line segment coordinate sequence, calculate the standard deviation of the distance between coordinate point pairs, compare the standard deviation of the distance with the standard deviation threshold one by one, and if the standard deviation of the distance is less than the standard deviation threshold, mark the coordinate point pair as parallel relationship and generate a set of parallel relationship point pairs.

[0020] Based on the set of parallel relationship point pairs, and taking the symmetry transformation axis determined by the potential geometric association index as a reference, it is detected whether the coordinate point pairs in the independent line segment coordinate sequence are mirrored about the symmetry transformation axis. If the mirrored distribution of the coordinate point pairs is true, the coordinate point pairs are marked as symmetric, and a set of symmetric relationship point pairs is generated.

[0021] Based on the set of parallel relationship point pairs and the set of symmetric relationship point pairs, parallel relationship constraints and symmetric relationship constraints for the position of curve control points are established respectively. The two types of constraints are then integrated to form a set of geometric constraints for the family of curves.

[0022] Preferably, the step of obtaining the piecewise fitting cost function is as follows:

[0023] Based on the set of intentional corner points, each intentional corner point in the set of intentional corner points is used as a segmentation node in the B-spline curve fitting process. The original sampling point sequence is segmented in sequence, and C0 continuity constraints of the B-spline curve control point position are applied at each intentional corner point to generate a set of segmentation node constraints.

[0024] Based on the set of segmented node constraints and the set of geometric constraints of the curve family, the original sampling points on each B-spline curve segment are paired with the control points to be optimized on the curve point by point. The sum of squares of the coordinate differences between the paired points is calculated, and the square of the coordinate difference of each point is multiplied by the confidence value of the corresponding sampling point and accumulated to obtain the weighted distance sum of squares.

[0025] Based on the weighted sum of squared distances, with the magnitude of the sum as the optimization objective, and integrating the C0 continuity constraints in the segmented node constraint set, a segmented fitting cost function is constructed.

[0026] Preferably, the step of obtaining the constrained optimization objective function is as follows:

[0027] Based on the aforementioned set of geometric constraints for the family of curves and the piecewise fitting cost function, the value of the constraint optimization objective function is calculated;

[0028] Based on the constraint optimization objective function value, with minimizing the constraint optimization objective function value as the optimization objective, a unified set of position constraint or symmetry constraint functions is integrated to obtain the constraint optimization objective function.

[0029] Preferably, the steps for obtaining the set of control point coordinates for the B-spline curve are as follows:

[0030] Based on the constraint optimization objective function, the set of control point coordinates is updated numerically step by step. In each iteration, the gradient value of the objective function is calculated and it is determined whether the descent trend of the objective function meets the convergence condition. The calculation is terminated when the gradient update magnitude is lower than the set accuracy threshold or the number of iterations exceeds the maximum limit, and the optimal set of control point coordinates that satisfies all constraints is obtained.

[0031] Based on the optimal control point coordinate solution set that satisfies all constraints, the control point coordinate information corresponding to each segment of the B-spline curve is extracted to generate the control point coordinate set of the B-spline curve.

[0032] Preferably, the step of obtaining the optimized fitting curve is as follows:

[0033] Based on the B-spline curve control point coordinate set, the two-dimensional spatial coordinates of each control point are read, the curve segment structure information is extracted according to the control point order, and the control point number index of each segment is bound to generate the B-spline curve control point structure dataset.

[0034] Based on the B-spline curve control point structure dataset, the order parameters and node vector parameters of CAD curve fitting are set, and the mathematical expression model of each curve segment is established sequentially by calling the CAD graphics engine curve construction interface, generating CAD curve fitting optimization definition data containing the definition of all segmented curves.

[0035] Based on the CAD curve fitting optimization definition data, all B-spline curve segments are sequentially spliced ​​according to the curve construction order, and the continuity of each connection node is checked to generate the optimized fitting curve.

[0036] Compared with the prior art, the advantages and positive effects of the present invention are as follows:

[0037] This invention achieves the identification of intentional feature points in user strokes by extracting timestamped sampling points and constructing a confidence system based on instantaneous velocity and local curvature, thus enhancing the semantic fit of curve segmentation. By combining the differences between corresponding points of stroke sampling points with the potential symmetry transformation axis for analysis, it can automatically construct geometric relationships reflected by user hand-drawn behavior, enabling subsequent constraint modeling to dynamically generate based on the actual input configuration rather than relying on fixed rules. The identification results of parallel and symmetric relationships are transformed into constraint functions between control points, guiding the B-spline curve to follow geometric consistency during the fitting process. This constraint design not only covers the handling of traditional positional errors but also introduces logical constraints on direction and symmetry. Using sharp corner points directly as segmentation nodes of the B-spline curve ensures that the curve expression captures key structural changes. In constructing the objective function, geometric constraints are organically embedded in the fitting cost function, unifying the minimization direction of the objective and making the control point solutions more holistic and reasonable. This improves the fitting accuracy while enhancing the ability to reproduce the user's true design intent. In particular, in scenarios such as free curve modeling and hand-drawn input curve analysis, it reduces curve deformation errors and improves the quality of shape representation. Attached Figure Description

[0038] Figure 1 This is a schematic diagram of the steps of the present invention. Detailed Implementation

[0039] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0040] Please see Figure 1 This invention provides a technical solution, a CAD curve fitting optimization method based on a line drawing scenario, comprising the following steps:

[0041] Based on the input sequence of timestamped sampling points, the instantaneous velocity value and local curvature value of each sampling point in the sequence are calculated, the confidence level of each sampling point is determined, and the set of intentional sharp corner points is obtained by filtering according to the confidence level.

[0042] Based on the sampling point sequence of multiple strokes and the set of intended sharp corner points, the distance standard deviation between corresponding points of different curves is calculated, and the symmetry transformation axis is searched to generate a potential geometric association index. Based on the potential geometric association index, point pairs below the distance standard deviation threshold are identified as parallel relationships, and point pairs with symmetry transformation axes are identified as symmetric relationships, thus establishing a set of geometric constraints for the family of curves.

[0043] According to the set of intended sharp corner points and the set of geometric constraints of the curve family, set the intended sharp corner points as the segmentation nodes of the B-spline curve and impose C0 continuity constraints to construct a piecewise fitting cost function; then merge the constraint conditions in the set of geometric constraints of the curve family into the piecewise fitting cost function to construct a constrained optimization objective function;

[0044] Solve the constrained optimization objective function to obtain the set of B-spline curve control point coordinates that satisfy all constraint conditions; use the set of B-spline curve control point coordinates as the defined data for CAD curve fitting optimization to generate an optimized fitting curve.

[0045] The steps for obtaining the set of intended sharp corner points are as follows:

[0046] Based on the input sequence of sampled points with timestamps, extract the two-dimensional coordinates of each sampled point and calculate the vector angle between adjacent points before and after. Use the vector angle to calculate the local curvature value of the current point, and at the same time calculate the instantaneous velocity value of the current point by dividing the distance between adjacent two-point coordinates by the time interval to obtain a set of sampled point features;

[0047] According to the set of sampled point features, calculate the confidence value of each sampled point. The calculation formula is:

[0048]

[0049] where, C i is the confidence value of the i-th sampled point, K i is the local curvature value of the i-th sampled point, U i is the instantaneous velocity value of the i-th sampled point, U i;1 is the instantaneous velocity value of the (i - 1)-th sampled point, Q is the average value of the instantaneous velocity values of all sampled points in the current sampling sequence, α is the velocity adjustment coefficient, and β is the deceleration sensitivity coefficient;

[0050] According to the confidence value of each sampled point, filter out all sampled points whose confidence values are greater than the preset confidence threshold to generate a set of intended sharp corner points.

[0051] Specifically, based on the input sequence of sampled points with timestamps, first process each sampled point to extract its two-dimensional coordinate information. For example, for stroke input on a tablet computer, obtain the coordinates (x i , y i , y i ) of the i-th sampled point with timestamp t i i (where i ranges from 1 to N, and N is the total number of sampled points. Usually, the sampling frequency is set to 100Hz to capture sufficiently fine stroke details). Then, for each non-endpoint sampled point P i (i.e., 1 < i < N) in the sequence, calculate its vector with the adjacent points P i;1 and P i:1The two vectors formed and Then calculate the angle θ between these two vectors. i The calculation formula is: in It is the vector dot product. and The vector magnitude is the angle θ obtained from the angle θ. i (Usually takes values ​​between 0 and π) is directly used to represent the current point P. i The degree of local curvature is determined and used as the local curvature value K. i K i =θ i At the same time, calculate point P i instantaneous velocity value U i Its calculation method is point P i With the previous point P i;1 The Euclidean distance between them divided by the corresponding time interval, i.e. For the first point P1 in the sequence, its instantaneous velocity U1 can be approximated as U2, or calculated by dividing the distance between P1 and P2 by the time difference. K1 is set to 0, and the local curvature values ​​K of all sampled points are... i and instantaneous velocity value U i and the original coordinates (x) i ,y i ) and timestamp t i These features are then integrated to form the feature data for each sampling point, and all of these feature data together constitute the feature group of the sampling point.

[0052] formula: The advantage of this formula is that it comprehensively considers the local geometric features of the sampling points (curvature K). i Kinematic characteristics (instantaneous velocity U) i ) and the trend of speed change (U) i;1 -U i This (i.e., deceleration) allows for more accurate identification of sharp corners in the user's intent. Specifically, high curvature is a necessary condition for sharp corners; users typically reduce pen speed when drawing sharp corners, therefore... The item will penalize high-speed points, when U i When the value is much greater than Q / α, this term tends to 0; conversely, it tends to 1. The user will experience a noticeable deceleration process before reaching the sharp corner. The term is used to amplify this deceleration effect, when deceleration (U) occurs. i;1 >U iWhen the speed is constant, the value is greater than 1; when the speed is accelerated, it is less than 1; and when the speed is constant, it is equal to 1. By multiplying these three parts, the sharp inflection points that the user truly wants to form can be filtered out from the stroke data, rather than pseudo-feature points caused by drawing jitter or rapid curve movement. This provides a more reliable foundation for subsequent curve segmentation and geometric constraint recognition.

[0053] K i Let P be the local curvature value of the i-th sampling point, which is obtained by calculating the sampling point P in the previous step. i The vector angle θ at the location i Let K represent this. i =θ i The angle is expressed in radians. For example, through the calculations described above, a point P is obtained. i Local curvature value K i = 1.8 radians.

[0054] U i Let U be the instantaneous velocity value of the i-th sampling point, in pixels per second (pixels / s). This value is calculated in the previous step, i.e., the distance between the coordinates of two adjacent points divided by the time interval. For example, through the calculation in the aforementioned steps, the instantaneous velocity value U of the i-th sampling point is obtained. i = 30.0 pixels / s.

[0055] U i;1 This represents the instantaneous velocity value at the (i-1)th sampling point, in units of U. i The same. For example, by calculation, the instantaneous velocity value U at the (i-1)th sampling point is obtained. i;1 = 50.0 pixels / s.

[0056] Q is the average instantaneous velocity value of all sampling points in the current sampling sequence, with units equal to U. i The same. For example, a sequence containing 100 sampling points, whose instantaneous velocity values ​​at each point are summed and divided by 100, yields Q = 40.0 pixels / s.

[0057] α is a velocity adjustment coefficient, a dimensionless parameter. This coefficient is used to adjust the sensitivity of the confidence level to the absolute velocity of the sampling points. The setting of α is based on statistical analysis of user drawing habits; for example, collecting a large amount of stroke data from users drawing sharp corners and analyzing the velocity distribution at these corner points. If users generally draw sharp corners at a low speed, α can be set to a larger value to enhance the suppression of high speeds. Specifically, a reference velocity U can be selected. ref (For example, the 85th percentile non-sharp point velocity), such that when U i =U ref At that time, the speed inhibition term There is a desired decay value (e.g., 0.5). Then... For example, if Q = 40.0 pixels / s, the expected value in U ref When the value is 80.0 pixels / s, the decay of this term is 0.5. In this example, we take α = 0.5.

[0058] β is the deceleration sensitivity coefficient, a dimensionless parameter. This coefficient is used to adjust the confidence level's sensitivity to changes in the sampling point's velocity (especially deceleration). The setting of β depends on the significance of the user's deceleration behavior before the corner is drawn. If the user exhibits very significant deceleration behavior before the corner forms, β can be set larger to amplify the contribution of deceleration. A possible method is to statistically analyze common decelerations at corner points (e.g., U...). i;1 -U i (The ratio distribution of Q), select a typical relative deceleration value R. decel (For example, (U) i;1 -U i ) / Q=0.5), such that under this deceleration, tanh(β·R) decel To achieve a desired response value (e.g., 0.76, corresponding to β·R) decel ≈1). Then β=1 / R decel For example, if the typical relative deceleration is 0.25 (i.e., a reduction of 25% of the average speed), and we expect the tanh term to contribute significantly, we can assume β·0.25≈1, then β=4.0. In this example, we take β=4.0.

[0059] Calculation process:

[0060] The following parameter values ​​are available:

[0061] K i = 1.8 radians;

[0062] U i = 30.0 pixels / s;

[0063] U i;1 = 50.0 pixels / s;

[0064] Q = 40.0 pixels / s;

[0065] α = 0.5;

[0066] β = 4.0;

[0067] Calculation process:

[0068] Calculate the speed suppression term:

[0069] Calculate the parameters in the deceleration response term:

[0070] Calculate the deceleration response term: tanh(2.0)≈0.964. 1+0.964=1.964;

[0071] Calculate the final confidence level C i :

[0072] The result indicates that the confidence value C at the i-th sampling point is... i Approximately 2.570. It has a high C value throughout the entire sampling point sequence. i Points with a confidence value of 1.0 are considered potential intent corners. Subsequent steps will use this confidence value and set a threshold to filter out the final set of intent corners. For example, if the confidence threshold is set to 1.0, then this C... i A point with a value of 2.570 will be initially identified as an intentional sharp corner point.

[0073] Based on the confidence value sequence {C1,C2,...,C...} calculated in the previous step for each sampling point... N Next, we need to filter out all confidence values ​​greater than a preset confidence threshold C. thresh The sampling points, this preset confidence threshold C thresh Determining the target is a crucial step, directly impacting the accuracy of intent corner point recognition. thresh The setup can be based on the following method: First, collect a batch of representative user line-drawing data, and have the designer manually mark the true intent corners in these data. Then, run the aforementioned confidence calculation process on these data to obtain the confidence values ​​of all sampling points. Statistically analyze the confidence distribution at the true corner locations and the confidence distribution at non-corner locations. Ideally, the confidence of true corner locations will be significantly higher than that of non-corner locations. A common method is to plot the Receiver Operating Characteristic (ROC) curve, and by trying different C... thresh The value is used to calculate the corresponding true positive rate (the proportion of correctly identified sharp points) and false positive rate (the proportion of non-sharp points incorrectly identified as sharp points). A point on the ROC curve that balances these two values ​​is selected, for example, maximizing the Youden index (true positive rate + true negative rate - 1) or the C value corresponding to the highest true positive rate within a specific acceptable range for false positive rates. thresh Values, for example, by analyzing 100 sets of test stroke data containing approximately 500 manually marked sharp points, it was found that in C... thresh When C = 1.5, a true positive rate of 90% can be achieved, while the false positive rate is controlled below 5%. Therefore, C can be considered... thresh Set to 1.5, after determining C thresh Then, iterate through the confidence values ​​C of all sampling points. i If Ci >C thresh (For example, C) i If the value is greater than 1.5, then the sampling point P will be... i The index or coordinates are added to an initial list of candidate sharp corner points. Considering that multiple consecutive points may exceed the threshold due to local noise or computational inaccuracies, further non-maximum suppression processing can be performed. That is, within a small neighborhood window (e.g., 3-5 consecutive sampling points), if multiple candidate sharp corner points exist, only the built-in confidence value C of that window is retained. i The largest point, or curvature K i The largest point is selected as the final intention corner point, and these selected and optimized points together constitute the intention corner point set.

[0074] The steps to obtain the potential geometric association index are as follows:

[0075] Based on the sampling point sequence of multiple strokes and the set of intentional corner points, each stroke is divided into multiple independent line segments defined by the intentional corner points, and the coordinates of the sampling points on each independent line segment are extracted in turn to form an independent line segment coordinate sequence.

[0076] Based on the independent line segment coordinate sequence, according to the line segment length percentage segmentation method, the same percentage position points between the corresponding line segments of different strokes are determined. The spatial coordinates of the same percentage position points are paired and the Euclidean distance between each pair of corresponding points is calculated. The standard deviation of the distance values ​​of all corresponding points is calculated to form a set of distance standard deviations.

[0077] Based on the set of distance standard deviations, and taking the coordinate sequence of independent line segments as the basis, we enumerate all the positions of the axis of symmetry of the coordinate sequence. By comparing the distance standard deviations of the coordinate sequences on both sides of different axes of symmetry, we select the axis position that minimizes the distance standard deviation of the corresponding point as the axis of symmetry transformation, and mark the index of the independent line segment coordinate sequence associated with the axis of symmetry transformation as the potential geometric association index.

[0078] Specifically, based on the sampling point sequence of multiple strokes and the intentional corner point set obtained in the previous step, a decomposition operation is performed on each stroke. Specifically, for a single stroke, its complete sampling point coordinate sequence {(x1,y1),(x2,y2),…,(x...} is first obtained. m ,y m The stroke's intentional sharp point and its index in the sequence, for example, if a stroke contains sampling points P1, ..., P... 100 And the intention is to indicate P in the set of sharp corner points. 20 and P 65 For the sharp point of this stroke, the starting point P1 and the sharp point P of the original stroke are then... 20 Sharp corner point P65 And the endpoint P of the stroke 100 As the dividing point, the line is divided into three independent segments: the first segment is from P1 to P... 20 The second segment consists of all the sampling points between them, and P is the second segment. 20 To P 65 The third segment consists of all the sampling points between them, and P is the third segment. 65 To P 100 The sequence consists of all the sampling points between them. For each such independent line segment, the two-dimensional coordinates (x, y) of all the original sampling points it contains are extracted sequentially. For example, for the first segment above, the extracted coordinate sequence is {(x1, y1), ..., (x...y1)}. 20 ,y 20 If a stroke has no intentional sharp corner, then the entire stroke itself constitutes an independent line segment, and its coordinate sequence is the complete sampling point coordinate sequence of the original stroke. This decomposition and extraction process is performed on all input multiple strokes to form their own independent line segment coordinate sequence sets. These sets together constitute all the independent line segment coordinate sequences required for subsequent processing.

[0079] Based on the independent line segment coordinate sequences obtained in the previous stage, the line segment length percentage segmentation method is used to quantify the correspondence between different line segments. The specific process is as follows: Select two independent line segment coordinate sequences from different strokes (or different parts of the same stroke, if applicable), denoted as line segment A and line segment B. First, calculate the total arc length of line segment A, which is the total length obtained by accumulating the Euclidean distance between all adjacent sampling points along line segment A from its starting point to its ending point. Similarly, calculate the total arc length of line segment B. Next, set a number of sampling points, such as 100 points, to represent dividing each line segment conceptually into 100 parts with equal arc length proportions. For line segment A, determine the precise spatial coordinate points at 0%, 1%, 2%, ..., 100% of its total arc length (a total of 101 positions, or take 100 internal division points). If these percentage positions happen to fall on... At the original sampling point, the coordinates of that sampling point are used directly. If the point falls between two original sampling points, the coordinates of that percentage position are calculated using linear interpolation. The same operation is performed on line segment B to obtain the coordinates of a series of points with the same percentage position. Then, points with the same percentage position on line segment A and line segment B are paired one by one. For example, a point at 10% length on line segment A is paired with a point at 10% length on line segment B. The Euclidean distance between each pair of such paired points is calculated, thus obtaining a set of distance values ​​(101 or 100 in this example). Finally, the standard deviation of this set of distance values ​​is calculated. This standard deviation reflects the dispersion of the distance between corresponding points after the two line segments are aligned according to their length ratio. This process is repeated for all independent line segment pairs that need to be compared, and each calculated standard deviation value is collected to form a set of distance standard deviations.

[0080] Based on the distance standard deviation set and all independent line segment coordinate sequences generated in the previous steps, a further search for potential symmetrical geometric relationships is performed. Specifically, a pair of independent line segment coordinate sequences is selected, such as line segment I and line segment J (these line segment pairs can be filtered from the distance standard deviation set; for example, only those line segment pairs with small original distance standard deviations are considered, setting a pre-screening threshold of 15.0 pixels. This threshold is selected by observing the distance standard deviation distribution of a large number of line segment pairs to initially exclude obviously irrelevant line segment pairs. For example, statistics show that 70% of random line segment pairs have a distance standard deviation greater than 15.0 pixels, while potentially related line segment pairs are usually below this value). For the selected line segment I and line segment J, a series of possible symmetry axis positions are enumerated. One enumeration method is to calculate the centroid C of line segment I. I The centroid C of line segment J J , will connect C I and C JThe midpoint M of the line segment is taken as a point that the axis of symmetry must pass through. Then, with point M as the center, different directions of the axis of symmetry are tried, for example, from 0 degrees to 180 degrees, taking an angle every 5 degrees (i.e., π / 36 radians) as a candidate direction of the axis of symmetry. For each candidate axis of symmetry, all sampling points on line segment I are mirrored about that axis to obtain a new sequence of reflected line segment coordinates, denoted as line segment I'. Next, using a line segment length percentage segmentation method similar to the previous step (e.g., using 100 percentage points), the corresponding points between line segment I' and line segment J are determined, and the Euclidean distance between these corresponding points is calculated. Then, the standard deviation of these Euclidean distances is calculated. This standard deviation measures the accuracy of the current candidate axis of symmetry. Under the selected axis of symmetry, the degree of coincidence between line segment I and line segment J after reflection is determined. By comparing the standard deviations of distances obtained from all candidate axes of symmetry, the axis of symmetry that minimizes this standard deviation is selected as the optimal symmetry transformation axis between line segments I and J. The indices of this pair of line segments (e.g., the indices of line segment I and line segment J), the parameters of the calculated optimal symmetry transformation axis (such as its equation or a point and direction vector on it), and the corresponding minimum distance standard deviation are recorded. This information is added as an entry to the latent geometric association index. This process is repeated for all considered line segment pairs. The final latent geometric association index contains all line segment pairs identified as having potential symmetry relationships and their symmetry information.

[0081] The steps to obtain the set of geometric constraints for a family of curves are as follows:

[0082] Based on the latent geometric association index, extract all coordinate point pairs of the corresponding independent line segment coordinate sequence, calculate the numerical standard deviation of the distance between coordinate point pairs, compare the numerical standard deviation of the distance with the distance standard deviation threshold one by one, and mark the coordinate point pair as parallel relationship if the numerical standard deviation of the distance is less than the distance standard deviation threshold, and generate a set of parallel relationship point pairs.

[0083] Based on the set of parallel relationship point pairs, and taking the symmetry transformation axis determined by the potential geometric association index as the reference, it is detected whether the coordinate point pairs in the independent line segment coordinate sequence are mirrored about the symmetry transformation axis. If the mirror distribution of the coordinate point pairs is true, the coordinate point pairs are marked as symmetric and a set of symmetric relationship point pairs is generated.

[0084] Based on the sets of parallel and symmetric point pairs, parallel and symmetric constraints on the positions of curve control points are established respectively. The two types of constraints are then integrated to form a set of geometric constraints for the family of curves.

[0085] Specifically, based on the potential geometric association index obtained in the previous steps, which records independent line segment pairs with potential geometric relationships and their related information, such as symmetry axis parameters or corresponding point information, each entry in the index is processed. First, the coordinate sequences of the two independent line segments corresponding to the entry are extracted, denoted as line segment S1 and line segment S2. Then, based on the original sampling points of these two line segments, corresponding point pairs are generated using the line segment length percentage segmentation method (for example, as before, taking 100 equally spaced points along the arc length of each line segment). That is, the k-th percentage position point on S1 and the k-th percentage position point on S2 form a pair. For each such coordinate point pair (P 1k ,P 2k ), calculate the Euclidean distance d between them. k =||P 1k -P 2k ||, thus obtaining a set of distance values ​​{d1,d2,…,d 100 Then calculate the standard deviation of this set of distance values, denoted as σ. dist This standard deviation reflects whether the distance between two line segments remains approximately constant after they are proportionally matched in length. The next step is to calculate the standard deviation σ of the distance values. dist With a preset distance standard deviation threshold σ thresh The distance standard deviation threshold σ is compared. thresh The basis for this setting is: by analyzing a large number of known parallel pairs of real CAD line segments, calculating the distribution of the standard deviation of the distances between their corresponding points, and selecting a critical value that can effectively distinguish between parallel and non-parallel lines. For example, analyzing a test dataset containing 100 pairs of known parallel line segments, it was found that 95% of the parallel line segment pairs have a standard deviation of σ. dist Less than 5.0 pixels, and σ of random non-parallel line segment pairs dist Most values ​​are much higher than this, therefore σ can be set. thresh = 5.0 pixels, if σ dist <σ thresh (for example, σ) dist If the distance is less than 5.0 pixels, then line segment S1 and line segment S2 are considered to be parallel, and this pair of line segments (or their corresponding original sampling point pairs, or more precisely, the control point pairs of the B-spline curves that constitute this pair of line segments) are marked as having a parallel relationship. All line segment pairs or point pairs marked as parallel are collected to form a set of parallel relationship point pairs.

[0086] Based on the set of parallel relationship point pairs generated in the previous step, and the potential geometric association index established in an earlier step (which contains line segment pairs and their corresponding candidate symmetry transformation axes), the symmetry relationship is further precisely determined. Specifically, a pair of independent line segments marked as parallel is selected from the set of parallel relationship point pairs, denoted as line segment U and line segment V. At the same time, the optimal symmetry transformation axis L determined by this pair of line segments U and V (or the original line segment pairs as part of them) when searching for the symmetry axis is searched from the potential geometric association index. sym Its parameters (e.g., a point P on the axis) axis and direction vector It is known that line segments U and V are indeed about axis L. sym The mirror-symmetric distribution is verified as follows: For each sampling point P on line segment U... U Calculate its value about the symmetry transformation axis L. sym mirror point P′ U The method for calculating the mirror point is: find P U To axis L sym If the foot of the perpendicular is F, then Or P′ U =2F-P U Then, search for the line segment V that corresponds to P′. U The nearest sampling point is denoted as Calculate P′ U and The Euclidean distance between them is calculated by repeating this operation for all sampling points (or representative points selected as a percentage of length) on line segment U, resulting in a set of such nearest distance values. The average or maximum value of these distance values ​​is then calculated and compared with a preset symmetric tolerance threshold D. sym_thresh Compared to this, the symmetric tolerance threshold D sym_thresh The settings should take into account sampling noise and calculation accuracy; for example, they can be set to pixel level, such as D. sym_thresh = 2.0 pixels. This value can be determined by observing the deviation distribution between the original point and the ideal symmetrical point of a known symmetrical figure after digitization and symmetry axis calculation. A value that tolerates normal deviations but excludes obvious asymmetry should be selected. If the average or maximum value of this set of distances is less than D... sym_thresh (For example, if the average distance is <2.0 pixels), then the coordinate point pair (i.e., line segment U and line segment V) is considered to be about the symmetry transformation axis L. sym If the mirror distribution holds, mark the pair of line segments (or their corresponding control point pairs) as symmetrical, and collect all line segment pairs or point pairs marked as symmetrical to form a set of symmetrical point pairs.

[0087] Based on the sets of parallel and symmetric point pairs obtained in the first two steps, we begin to construct geometric constraints for subsequent curve fitting optimization. For each pair of line segments marked as parallel in the set of parallel point pairs, constraints need to be established to maintain their parallelism. If a pair of line segments is controlled by the sequence of control points CP1 = {cp 1,1 ,…,cp 1,m} and CP2 = {cp 2,1 ,…,cp 2,n The parallelism between control points can be defined by constraining the dot product of their tangent directions or main directional vectors to be approximately 1 or -1, or more directly, if they are approximately equidistant parallels, by constraining the direction of the lines connecting their corresponding control points to be approximately the same. For example, for a B-spline curve, the corresponding edges of the control polygons of the corresponding segments can be constrained to be parallel, or the difference vectors between corresponding control points can be constrained to be in the same direction. Similarly, for each pair of line segments marked as symmetric in the set of symmetric point pairs (by the control point sequence CP), the parallelism can be defined. A and CP B (Definition) and their associated symmetry transformation axes L sym Constraints need to be established to make CP A Each control point cp A,i After about L sym After the symmetric transformation, its position should be close to CP. B The corresponding control point cp B,i (Or conversely), this constraint can be directly applied to the coordinates of the control points, i.e., cp. B,i ≈Reflect(cp A,i ,L sym All parallel relationship constraints derived from the set of parallel relationship point pairs and symmetry relationship constraints derived from the set of symmetry relationship point pairs are collected and integrated. For example, they can be expressed as a series of equations or inequalities about the coordinates of the control points to be optimized, or added as penalty terms to the optimization objective function. The resulting constraint set is the geometric constraint set of the curve family.

[0088] The steps for obtaining the piecewise fitting cost function are as follows:

[0089] Based on the intentional corner point set, each intentional corner point in the intentional corner point set is used as a segmentation node in the B-spline curve fitting process. The original sampling point sequence is segmented in sequence, and the C0 continuity constraint of the B-spline curve control point position is applied at each intentional corner point to generate a segmentation node constraint set.

[0090] Based on the set of segmented node constraints and the set of geometric constraints of the family of curves, the original sampling points on each B-spline curve are paired with the control points to be optimized on the curve point by point. The sum of squares of the coordinate differences between the paired points is calculated, and the square of the coordinate difference of each point is multiplied by the confidence value of the corresponding sampling point and accumulated to obtain the weighted distance sum of squares.

[0091] Based on the weighted sum of squared distances, with the numerical value as the objective to be optimized, and integrating the C0 continuity constraints in the set of segmented node constraints, a segmented fitting cost function is constructed.

[0092] Specifically, based on the set of intent corner points obtained in the previous steps, each intent corner point P in the set is... corner,j (where j is the index of the cusp point) serves as the segmentation node in the subsequent B-spline curve fitting process. Specifically, for an original sampling point sequence containing multiple cusp points, such as sequence S = {P1, P2, ..., P...}, ... N If the intention is to indicate P in the set of sharp corner points k1 ,P k2 ,…,P km For the sharp points in this sequence (arranged in order of their appearance in the sequence), the original sampling point sequence S is cut at these sharp point positions to form m+1 segments. The first segment runs from the sequence start point P1 to the first sharp point P. k1 The second paragraph starts from P k1 To P k2 And so on, the last paragraph starts from the last sharp point P. km to the end point P of the sequence N If the sequence has no intended sharp points, the entire sequence is considered as a segment. For each such segment, an independent B-spline curve will be used for fitting, at each intended sharp point P. kj To ensure the visual continuity of the fitted curve, a C0 continuity constraint is applied. This means that the control point (or the curve endpoint position determined by the control point) that is the endpoint of the previous B-spline curve segment must coincide spatially with the control point (or the curve start position determined by the control point) that is the start point of the next B-spline curve segment. In other words, they must be the same point. This constraint ensures that at the apex point, two adjacent B-spline curve segments can be accurately connected without breakage. All these C0 continuity constraints generated by the intended apex point are collected to form a set of piecewise node constraints.

[0093] Based on the segmented node constraint set generated in the previous step (mainly containing C0 continuity constraints) and the previously established curve family geometric constraint set (including geometric relationship constraints such as parallelism and symmetry), we begin to construct a measure of fitting error. For each B-spline curve segment divided by the intended sharp corner point, its shape is determined by the position of a set of control points to be optimized. For each sampling point P in the original sampling point subsequence corresponding to this curve segment... raw,i We need to find a corresponding point P on the currently parameterized B-spline curve. fit,i This correspondence can be calculated by substituting the parameter values ​​of the original sampling points (e.g., obtained based on arc length parameterization or uniform parameterization) into the parametric equation of the B-spline curve. Once the original sampling points P are determined... raw,i =(x raw,i ,y raw,i ) and its corresponding point P on the fitted curve fit,i =(x fit,i (CP),y fit,i For pairing (CP) (where CP represents the set of control points for the current curve segment), the sum of squares of the coordinate differences between them is calculated, i.e., (x... raw,i -x fit,i (CP)) 2 +(y raw,i -y fit,i (CP)) 2 To reflect the importance of different sampling points in the fitting process (e.g., points near sharp corners may be more important), each such squared difference term needs to be multiplied by a weight, which is the value of the original sampling point P. raw,i confidence level C i (This confidence value, calculated in an earlier step, reflects the likelihood that the point is an intended corner point; even if it is not the final selected corner point, its confidence value still reflects the importance of its local features.) All weighted coordinate differences are squared and summed, i.e., ∑ is performed on all sampling points i within a curve segment. i C i ·[(x raw,i -x fit,i (CP)) 2 +(y raw,i -y fit,i (CP)) 2 The calculation is performed on all B-spline curve segments and summed to obtain a total weighted sum of squared distances. This value measures the overall closeness of all fitted curve segments to the original sampling point sequence under the current control point configuration, while also taking into account the confidence level of the sampling points.

[0094] Based on the weighted sum of squared distances calculated in the previous step, this value directly reflects the degree of deviation between the fitted curve and the original sampling points under the current B-spline curve control point configuration. Therefore, the magnitude of this weighted sum of squared distances is used as the main objective of the fitting optimization, i.e., to minimize this value by adjusting the control points of the B-spline curve. At the same time, it is also necessary to integrate the C0 continuity constraints defined in the segment node constraint set previously. These C0 continuity constraints ensure that adjacent B-spline curve segments can be smoothly connected at each intentional sharp point. Specifically, these C0 constraints (e.g., the last control point of the previous curve segment equals the first control point of the next curve segment, or more precisely, the point of the previous curve segment when the parameter equals 1 equals the point of the next curve segment when the parameter equals 0) are added to the optimization problem as equality constraints, or the degree of violation of these constraints is added to the objective function in the form of a penalty term. For example, if two control points CP should coincide... end,j and CP start,j:1 If they do not overlap, a penalty term λ can be added. C0 ||CP end,j -CP start,j:1 || 2 In the objective function, where λ C0 It is a C0 continuity constraint weighting coefficient, and this weighting coefficient λ C0 The value needs to be large enough to force the C0 continuity. For example, it can be set to a value much larger than the coefficients in the weighted distance sum of squares, such as 1000.0. The specific value can be adjusted experimentally, observing the results under different λ values. C0 The degree of fracture in the optimization results is evaluated, and a minimum value that can basically eliminate the fracture is selected. In this way, the objective of minimizing the weighted sum of squared distances is combined with the requirement of satisfying the C0 continuity constraint to construct a piecewise fitting cost function.

[0095] The steps to obtain the objective function for constrained optimization are as follows:

[0096] Based on the set of geometric constraints of the family of curves and the piecewise fitting cost function, the value of the constraint optimization objective function is calculated using the following formula:

[0097]

[0098] Where O is the objective function value of the constrained optimization, D is the weighted sum of squared distances, CP is the vector of the control point coordinates to be optimized, and f p (CP) k v is the coordinate deviation vector of the control point at the k-th position or under symmetric constraints. s1,j With v s2,j Let L be the unit direction vector between the two control point pairs involved in the parallel relationship in the j-th parallel constraint. jλ is the average of the original lengths of the direction vectors between two control point pairs in the j-th parallel constraint. p,k With λ s,j These are the corresponding penalty coefficients, N. p With N s These represent the total number of positional or symmetric constraints and parallel constraints, respectively.

[0099] Based on the constraint optimization objective function value, with minimizing the constraint optimization objective function value as the optimization objective, a unified set of position constraint or symmetry constraint functions is integrated to obtain the constraint optimization objective function.

[0100] Specifically, the formula: The advantage of this formula lies in its comprehensive optimization objective. It not only strives to make the fitted curve closely approximate the original sampling points (through term D), but also simultaneously forces or encourages the fitted curve to satisfy the implicit geometric intentions of the user during the drawing process, such as point position constraints, symmetry between line segments (through term D), and parallelism between line segments (through term D). This is achieved by adjusting the penalty coefficient λ. p,k and λ s,j This allows for a flexible balance between data fidelity and geometric regularity. p (CP) k The term quantifies specific geometric constraints (fixed position, symmetry) as deviations in the coordinates of control points, and minimizing the sum of their squares ensures that the constraints are satisfied. In the parallel constraint term, 1-|v s1,j ·v s2,j |The property of the dot product of unit vectors is used to measure the degree of parallelism between two directional vectors (when the vectors are parallel, the absolute value of the dot product is 1, and this term is 0), while The term then makes the parallelism of longer line segments contribute more to the total cost.

[0101] Parameter description:

[0102] D is the weighted sum of squared distances, calculated through the steps described above: "Based on the set of segmented node constraints and the set of geometric constraints for the family of curves, pair the original sampling points on each segment of the B-spline curve with the control points to be optimized on the curve point by point, calculate the sum of squared coordinate differences between the paired points, and multiply the squared coordinate difference of each point by the confidence value of the corresponding sampling point and sum them to obtain the weighted sum of squared distances." It represents the weighted least squares error between the fitted curve and the original sampling points. For example, D = 125.5 is calculated.

[0103] CP is the set vector of control point coordinates to be optimized. It contains the two-dimensional coordinates (x, y) of all control points for all B-spline curve segments. For example, if there are a total of 10 control points, then CP = (cp... 1x ,cp 1y ,cp2x ,cp 2y ,…,cp 10x ,cp 10y These coordinates are the variables that the optimization algorithm needs to adjust.

[0104] f p (CP) k This is the coordinate deviation vector of the control point at the k-th position or under symmetric constraints.

[0105] For position constraints: if the m-th control point CP m =(cp mx ,cp my Constrained at target point T m =(t mx ,t my If f is the corresponding f, then f is the corresponding f. p (CP) k =CP m -T m =(cp mx -t mx ,cp my -t my ).

[0106] For symmetric constraints: if control point CP a With CP b Regarding a certain axis of symmetry L sym If symmetric, then f p (CP) k =CP b -Reflect(CP a ,L sym ), where Reflect(CP a ,L sym ) is CP a Regarding L sym The mirror point. For example, consider the k=1st constraint as a symmetric constraint, requiring control points CP1 = (15.0, 25.0) and CP2 = (-18.0, 26.0) to be symmetric about the Y-axis (x = 0). The ideal symmetric point of CP1 about the Y-axis should be (-15.0, 25.0). Then the deviation vector f p (CP)1=CP2-(-15.0,25.0)=(-18.0-(-15.0),26.0-25.0)=(-3.0,1.0). Therefore, ||f p (CP)1‖ 2 =(-3.0) 2 +(1.0) 2 =9.0+

[0107] 1.0 = 10.0.

[0108] v s1,j With v s2,j These are the unit direction vectors between the two control point pairs involved in the parallel relationship in the j-th parallel constraint. For example, the j=1-th parallel constraint involves two curve segments. One control polygon edge of the first curve segment is defined by control points A1=(10,10) and A2=(30,12), and its direction vector... but The control polygon edges corresponding to the second curve segment are defined by B1 = (10, 40) and B2 = (35, 43), and their direction vectors... but

[0109]

[0110] L j This is the average of the original lengths of the direction vectors between the two control point pairs in the j-th parallel constraint. Continuing...

[0111] but

[0112] λ p,k With λ s,j These are the corresponding penalty coefficients, which are dimensionless positive numbers. These coefficients are set based on the relative importance of various constraints and the typical numerical range of each error. One method is to first run an unconstrained fit (or with only C0 constraint), observe the typical value of D, and, without constraints, the value of f. p Typical values ​​for the angle deviation term. Then adjust λ so that the penalties for each term have similar magnitudes initially, or assign different weights according to design preferences. For example, if position / symmetry constraints are more important than parallel constraints, then λ... p,k The value of can be relative to λ s,j Larger. Specific setup process: Collect a batch of user-drawn line data containing typical geometric features, perform preliminary fitting, and statistically analyze the average degree of violation of each constraint. For example, if the order of D is 10... 2 ,‖f p || 2 The order of magnitude is 10 1 ,and The order of magnitude is 10 0 To make the constraints take effect, λ can be set. p,k Between 1.0 and 10.0, λ s,j The value is between 10.0 and 100.0, making the penalty term comparable to D. In this example, λ is set... p,1 =8.0, λ s,1 =15.0.

[0113] N pWith N s These represent the total number of positional or symmetry constraints and parallel constraints, respectively. These numbers are determined by the aforementioned generation steps of the "curve family geometric constraint set". For example, if a symmetry relationship and a set of parallel relationships are detected, then N... p =1, N s =1.

[0114] Use the values ​​calculated or set in the parameter examples above:

[0115] D = 125.5;

[0116] N p =1,‖f p (CP)1‖ 2 =10.0, λ p,1 =8.0;

[0117] N s =1, v s1,1 ≈(0.995,0.0995), v s2,1 ≈(0.992,0.119), L1=22.639, λ s,1 =15.0;

[0118] Calculate the first term (position / symmetry constraint penalty):

[0119]

[0120] Calculate the second term (parallel constraint penalty):

[0121] First, calculate the dot product:

[0122] v s1,1 ·v s2,1 ≈0.995·0.992+0.0995·0.119;

[0123] ≈0.98704+0.0118405≈0.99888;

[0124] The absolute value is |0.99888| = 0.99888.

[0125]

[0126] Calculate the total value O of the constrained optimization objective function:

[0127] O = D + 80.0 + 8.610;

[0128] O=125.5+80.0+8.610=214.110;

[0129] The result shows that the objective function value for constraint optimization under the current B-spline curve control point CP configuration is 214.110. This value is the sum of the fitting error (125.5), the position / symmetry constraint violation penalty (80.0), and the parallel constraint violation penalty (8.610). The goal of the optimization algorithm is to minimize this O value by adjusting the coordinates of CP. A smaller O value means that the fitted curve is closer to the original data points and better satisfies the applied geometric constraints.

[0130] Based on the constrained optimization objective function value defined in the previous step (i.e., the specific mathematical expression of the constrained optimization objective function O), the core task is to set and execute an optimization process. The goal of this process is to find a set of control point coordinates CP of a B-spline curve that minimizes the value of the constrained optimization objective function O. This minimization process constitutes the core computational step of curve fitting optimization. The constrained optimization objective function O itself has unified and integrated the requirements for data fidelity and geometric regularity through its composition (i.e., the weighted sum of squared distances D, and the penalty terms for violations of geometric constraints such as position, symmetry, and parallelism). Specifically, the first term D of function O ensures that the fitted curve matches the user's... The approximation of the input sampling point sequence is considered, while the subsequent summation term quantifies the various constraints defined in the "curve family geometric constraint set" (such as specific control points should be located at a certain position, two curve segments should be symmetrical to each other, or two curve segments should be parallel to each other) into numerical penalties. When a constraint is not satisfied, the corresponding penalty term will increase the value of O. Therefore, the process of minimizing O is essentially finding an optimal balance point so that the fitted curve can be faithful to the original input and can reflect the geometric characteristics expected by the user to the greatest extent. Finally, after this integration step with minimization as the goal, the complete constraint optimization objective function is obtained to guide the subsequent numerical solution.

[0131] The steps to obtain the set of control point coordinates for a B-spline curve are as follows:

[0132] Based on the constrained optimization objective function, the set of control point coordinates is updated numerically step by step. In each iteration, the gradient value of the objective function is calculated and it is determined whether the descent trend of the objective function meets the convergence condition. The calculation is terminated when the gradient update magnitude is lower than the set accuracy threshold or the number of iterations exceeds the maximum limit, and the optimal set of control point coordinates that satisfies all constraints is obtained.

[0133] Based on the optimal control point coordinate solution set that satisfies all constraints, the control point coordinate information corresponding to each segment of the B-spline curve is extracted to generate the control point coordinate set of the B-spline curve.

[0134] Specifically, based on the constrained optimization objective function O constructed in the previous steps, an iterative numerical optimization algorithm, such as gradient descent or conjugate gradient, is used to progressively update and optimize the control point coordinate set CP of the B-spline curve. At the beginning of each iteration, the current control point coordinates CP need to be calculated first. current The gradient vector of the lower-constraint optimization objective function O with respect to CP The gradient vector indicates the objective function value O at the current point CP. current Since the direction of the fastest growth is in the direction of the gradient, in order to minimize O, the update direction of the control point coordinates should be the negative gradient direction. The update step size η can be determined by using a fixed value, adaptive adjustment (such as the strategies used in AdaGrad, RMSProp, and Adam), or through a line search method (such as the Armijo condition or Wolfe condition) to ensure that each update step results in a sufficient decrease in the objective function value. The update formula for the control point coordinates is as follows: After each update, it is determined whether the iteration process meets the preset convergence conditions. The convergence conditions usually include the following two aspects: first, the descent trend of the objective function becomes very slow, or the magnitude of the gradient vector (i.e., the gradient update magnitude) is reduced. Less than a set precision threshold ∈ grad For example, ∈ grad It can be set to 10 ;6 The selection of this value is based on considerations of the accuracy requirements of the final fitted curve. When the gradient magnitude is less than this value, it is considered that further iterations will have a negligible effect on improving the objective function. Secondly, the number of iterations has reached the preset maximum limit MaxIter. For example, MaxIter can be set to 1000 times. This value is set to prevent the algorithm from failing to converge or converging too slowly in some cases and running indefinitely, providing a mechanism for forced termination. When any convergence condition is met, the iterative calculation terminates, and the control point coordinate set CP is obtained at this time. new This is considered to be the optimal set of control point coordinates that satisfies all constraints (in the sense of the objective function definition, i.e., the penalty term of the constraint is small enough).

[0135] Based on the optimal control point coordinate solution set obtained from the previous iterative optimization process, this solution set is a collection containing the two-dimensional coordinates (x, y) of all control points for all B-spline curve segments. For example, if the entire stroke is decomposed into 3 B-spline curve segments, the first segment requires 5 control points, the second segment requires 4 control points, and the third segment requires 6 control points. Then, this optimal control point coordinate solution set contains the precise x and y coordinate values ​​of these 5 + 4 + 6 = 15 control points. The next task is to extract the coordinates of each B-spline curve segment from this flattened optimal control point coordinate solution set, according to the original curve segmentation structure. The specific control point coordinate information corresponding to the spline curve is obtained by dividing and reorganizing the optimal control point coordinate solution set based on the number of control points required for each curve segment recorded during the piecewise fitting cost function construction stage (or an earlier intentional corner point identification stage). For example, if it is known that the first curve segment uses the first 5 control points in the solution set, the second segment uses the next 4, and the third segment uses the last 6, then these coordinates are extracted to form an independent control point list for each curve segment. For the first curve segment, its control point coordinate list is as follows:

[0136] {CP opt,1 ,CP opt,2 ,CP opt,3 ,CP opt,4 ,CP opt,5}, where CP opt,i The coordinates of the i-th optimal control point are given. Similarly, the coordinate lists of control points for the second and third curve segments are extracted. By summing up all these control point coordinate lists organized by segment, the set of B-spline curve control point coordinates is generated.

[0137] The steps to obtain the optimized fitted curve are as follows:

[0138] Based on the B-spline curve control point coordinate set, the two-dimensional spatial coordinates of each control point are read, the curve segment structure information is extracted according to the control point order, and the control point number index of each segment is bound to generate the B-spline curve control point structure dataset.

[0139] Based on the B-spline curve control point structure dataset, the order parameters and node vector parameters of CAD curve fitting are set, and the mathematical expression model of each curve segment is built sequentially by calling the curve construction interface of the CAD graphics engine, generating CAD curve fitting optimization definition data containing the definition of all segmented curves.

[0140] Based on the CAD curve fitting optimization definition data, all B-spline curve segments are sequentially spliced ​​according to the curve construction order, and the continuity of each connection node is checked to generate the optimized fitting curve.

[0141] Specifically, based on the control point coordinate set of the B-spline curve generated in the previous steps, which contains the two-dimensional spatial coordinates (x, y) of all control points of each optimized B-spline curve segment, the coordinate data of these control points are read one by one. Simultaneously, the curve segmentation structure information determined during curve segmentation (e.g., segmentation based on the intended sharp corner point) is also required. This structure information indicates how many B-spline curve segments the original user stroke was divided into, and which control points (in order of their position in the complete control point list) define each segment. For example, if a stroke is divided into two segments, the first segment is defined by control point indices 1 to 5, and the second segment is defined by control point indices 5 to 9. (Note that control point 5 may be shared by two segments as a connection point, or, depending on the implementation of C0 continuity, it may be the endpoint control point of two curve segments.) Therefore, the read control point coordinates need to be organized according to this order and segmentation information. Specifically, a record is created for each curve segment, which contains the index of the control points constituting that curve segment in its original complete list. For example, for the first curve segment, the index of the bound control points is {1,2,3,4,5}, and for the second segment it is {5,6,7,8,9}. After integrating this information (i.e., the control point index list of each curve segment and the corresponding actual coordinates of the control points), a B-spline curve control point structure dataset is formed.

[0142] Based on the B-spline curve control point structure dataset generated in the previous step, which details the coordinates of the control points of each B-spline curve segment and their position in the overall structure, the next step is to set the key parameters required for each curve segment to be represented in the CAD system, namely the order parameter p and the node vector parameter U. The order parameter p (usually p-1 for B-spline curves) can be set according to application requirements or experience. For example, for fitting freehand curves, the commonly used B-spline curve order is 2nd or 3rd (corresponding to order p=3 or p=4) to provide sufficient shape control flexibility while ensuring curve smoothness. For example, setting the order of all curve segments to p=3 (i.e., a quadratic B-spline curve), and the node vector U={u0,u1,…,u…} mThe generation of the curve needs to be determined based on the number of control points n+1 and the order p. Its length m+1 = n+p+1. The value of the node vector will affect the shape and parameterization of the curve. A common generation method is the node vector of a quasi-uniform B-spline, where the nodes at both ends have a repetition degree p and the internal nodes are evenly distributed. For example, for a 3rd-order (p=3) B-spline curve with 5 control points (n=4), its node vector can be {0,0,0,1,2,3,3,3}. After setting the order and node vector of each curve segment, the curve construction application programming interface provided by the target CAD system's graphics engine is called. The list of control point coordinates of the curve segment, the set order, and the calculated node vector are passed in as parameters. The graphics engine will generate a mathematical expression model of the curve segment based on these parameters. This operation is repeated for each curve segment in the B-spline curve control point structure dataset. All generated single-segment curve mathematical expression models are collected to form CAD curve fitting optimization definition data containing the definitions of all segment curves.

[0143] Based on the CAD curve fitting optimization definition data generated in the previous step, which contains the complete mathematical definition (control points, order, node vectors) of each B-spline curve segment, we now need to splice these independent piecewise curves according to their construction order in the original user strokes to form one or more continuous, optimized fitting curves. Specifically, from the CAD curve fitting optimization definition data, following the order in which the original strokes were segmented (this order information should be preserved in previous steps, for example, in the B-spline curve control point structure dataset), we sequentially extract the mathematical expression model of each B-spline curve segment. Then, in the CAD environment, we connect the endpoints of these curve segments, connecting each... At the nodes, i.e., the points where the end of the previous curve segment intersects with the start of the next curve segment (these connection points usually correspond to the intended sharp corners in the original strokes), continuity checks are required. At least C0 continuity (positional continuity) must be guaranteed, meaning the coordinates of the end point of the previous curve segment must be exactly the same as the coordinates of the start point of the next curve segment. This C0 continuity has already been enforced as a constraint condition in the previous "segmented node constraint set" generation step and subsequent optimization process. Therefore, the main purpose here is to verify whether the optimization results have indeed achieved this goal. This can be done by querying the endpoint coordinates of the curve objects in the CAD system and comparing whether they are within the preset geometric tolerance range (e.g., tolerance set to 10). ;5This can be achieved using coordinate units. If higher-order continuity is required, such as C1 (tangent continuity) or C2 (curvature continuity), then corresponding constraint terms need to be added to the optimization objective function, and corresponding checks are performed here. For example, the tangent vector direction (for C1) or curvature value (for C2) of the two curve segments at the connection point is compared. After completing the splicing of all segmented curves and the necessary continuity checks, the final result is the optimized fitted curve.

[0144] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments that can be applied to other fields. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.

Claims

1. A CAD curve fitting optimization method based on line drawing scenarios, characterized in that, Includes the following steps: Based on the input sequence of timestamped sampling points, the instantaneous velocity value and local curvature value of each sampling point in the sequence are calculated, the confidence level of each sampling point is determined, and the set of intentional sharp corner points is obtained by filtering according to the confidence level. Based on the sampling point sequence of multiple strokes and the set of intentional sharp corners, the distance standard deviation between corresponding points of different curves is calculated, and the symmetry transformation axis is searched to generate a potential geometric association index. Based on the potential geometric association index, point pairs below the distance standard deviation threshold are determined to be parallel, and point pairs with a symmetry transformation axis are determined to be symmetric, thus establishing a set of geometric constraints for the family of curves. Based on the set of intended sharp corner points and the set of geometric constraints of the curve family, the intended sharp corner points are set as piecewise nodes of the B-spline curve and C0 continuity constraints are applied to construct a piecewise fitting cost function; then the constraints in the set of geometric constraints of the curve family are merged into the piecewise fitting cost function to construct a constraint optimization objective function. Solving the constraint optimization objective function yields the set of B-spline curve control point coordinates that satisfy all constraints. The set of control point coordinates of the B-spline curve is used as the definition data for CAD curve fitting optimization to generate the optimized fitting curve.

2. The CAD curve fitting optimization method based on line drawing scenarios according to claim 1, characterized in that, The steps for obtaining the set of intent corner points are as follows: Based on the input sequence of timestamped sampling points, the two-dimensional coordinates of each sampling point are extracted and the vector angle between adjacent points is calculated. The local curvature value of the current point is calculated using the vector angle. At the same time, the instantaneous velocity value of the current point is calculated by dividing the coordinate distance between two adjacent points by the time interval, thus obtaining the sampling point feature group. Calculate the confidence value for each sampling point based on the feature group of the sampling points; Based on the confidence value of each sampling point, all sampling points with confidence values ​​greater than the preset confidence threshold are filtered to generate an intent corner point set.

3. The CAD curve fitting optimization method based on line drawing scenarios according to claim 1, characterized in that, The steps for obtaining the potential geometric association index are as follows: Based on the sampling point sequence of multiple strokes and the set of intentional corner points, each stroke is divided into multiple independent line segments defined by the intentional corner points, and the coordinates of the sampling points on each independent line segment are extracted in sequence to form an independent line segment coordinate sequence. Based on the independent line segment coordinate sequence, the same percentage position points between line segments corresponding to different line strokes are determined according to the line segment length percentage segmentation method. The spatial coordinates of the same percentage position points are paired and the Euclidean distance between each pair of corresponding points is calculated. The standard deviation of the distance values ​​of all corresponding points is calculated to form a set of distance standard deviations. Based on the aforementioned set of distance standard deviations, and taking the independent line segment coordinate sequence as a basis, all symmetry axis positions of the coordinate sequence are enumerated. By comparing the distance standard deviations of the coordinate sequences on both sides of different symmetry axes, the axis position that minimizes the distance standard deviation of the corresponding point is selected as the symmetry transformation axis, and the index of the independent line segment coordinate sequence associated with the symmetry transformation axis is marked as a potential geometric association index.

4. The CAD curve fitting optimization method based on line drawing scenarios according to claim 1, characterized in that, The steps for obtaining the set of geometric constraints for the family of curves are as follows: Based on the potential geometric association index, extract all coordinate point pairs of the corresponding independent line segment coordinate sequence, calculate the standard deviation of the distance between coordinate point pairs, compare the standard deviation of the distance with the standard deviation threshold one by one, and if the standard deviation of the distance is less than the standard deviation threshold, mark the coordinate point pair as parallel relationship and generate a set of parallel relationship point pairs. Based on the set of parallel relationship point pairs, and taking the symmetry transformation axis determined by the potential geometric association index as a reference, it is detected whether the coordinate point pairs in the independent line segment coordinate sequence are mirrored about the symmetry transformation axis. If the mirrored distribution of the coordinate point pairs is true, the coordinate point pairs are marked as symmetric, and a set of symmetric relationship point pairs is generated. Based on the set of parallel relationship point pairs and the set of symmetric relationship point pairs, parallel relationship constraints and symmetric relationship constraints for the position of curve control points are established respectively. The two types of constraints are then integrated to form a set of geometric constraints for the family of curves.

5. The CAD curve fitting optimization method based on line drawing scenarios according to claim 1, characterized in that, The steps for obtaining the piecewise fitting cost function are as follows: Based on the set of intentional corner points, each intentional corner point in the set of intentional corner points is used as a segmentation node in the B-spline curve fitting process. The original sampling point sequence is segmented in sequence, and C0 continuity constraints of the B-spline curve control point position are applied at each intentional corner point to generate a set of segmentation node constraints. Based on the set of segmented node constraints and the set of geometric constraints of the curve family, the original sampling points on each B-spline curve segment are paired with the control points to be optimized on the curve point by point. The sum of squares of the coordinate differences between the paired points is calculated, and the square of the coordinate difference of each point is multiplied by the confidence value of the corresponding sampling point and accumulated to obtain the weighted distance sum of squares. Based on the weighted sum of squared distances, with the magnitude of the sum as the optimization objective, and integrating the C0 continuity constraints in the segmented node constraint set, a segmented fitting cost function is constructed.

6. The CAD curve fitting optimization method based on line drawing scenarios according to claim 1, characterized in that, The steps for obtaining the constrained optimization objective function are as follows: Based on the aforementioned set of geometric constraints for the family of curves and the piecewise fitting cost function, the value of the constraint optimization objective function is calculated; Based on the constraint optimization objective function value, with minimizing the constraint optimization objective function value as the optimization objective, a unified set of position constraint or symmetry constraint functions is integrated to obtain the constraint optimization objective function.

7. The CAD curve fitting optimization method based on line drawing scenarios according to claim 1, characterized in that, The steps for obtaining the set of control point coordinates for the B-spline curve are as follows: Based on the objective function of the constraint optimization, the set of control point coordinates is updated numerically step by step. In each iteration, the gradient value of the objective function is calculated and it is determined whether the descent trend of the objective function meets the convergence condition. The calculation is terminated when the gradient update magnitude is lower than the set accuracy threshold or the number of iterations exceeds the maximum limit, and the optimal set of control point coordinates that satisfies all constraints is obtained. Based on the optimal control point coordinate solution set that satisfies all constraints, the control point coordinate information corresponding to each segment of the B-spline curve is extracted to generate the control point coordinate set of the B-spline curve.

8. The CAD curve fitting optimization method based on line drawing scenarios according to claim 1, characterized in that, The steps for obtaining the optimized fitting curve are as follows: Based on the B-spline curve control point coordinate set, the two-dimensional spatial coordinates of each control point are read, the curve segment structure information is extracted according to the control point order, and the control point number index of each segment is bound to generate the B-spline curve control point structure dataset. Based on the B-spline curve control point structure dataset, the order parameters and node vector parameters of CAD curve fitting are set, and the mathematical expression model of each curve segment is established sequentially by calling the CAD graphics engine curve construction interface, generating CAD curve fitting optimization definition data containing the definition of all segmented curves. Based on the CAD curve fitting optimization definition data, all B-spline curve segments are sequentially spliced ​​according to the curve construction order, and the continuity of each connection node is checked to generate the optimized fitting curve.

Citation Information

Patent Citations

  • Flexible circuit board three-dimensional shape laser scanning measurement and reconstruction method and system

    CN119887779A

  • Real-time drawing and verifying method for machined part pattern of bending machine numerical control system

    CN120276371A