A graphic fitting algorithm based on douglas-puke algorithm

By fitting manually drawn graphics using the Douglas-Puk algorithm, the problem of inaccurate graphics caused by hand tremors is solved, generating accurate fitted graphics and improving drawing efficiency and analysis results.

CN116228921BActive Publication Date: 2026-05-29合肥栈顶信息科技有限公司

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
合肥栈顶信息科技有限公司
Filing Date
2023-02-15
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing technologies often result in inaccurate graphics when manually drawing them due to hand tremors, affecting the efficiency of users in analyzing problems.

Method used

The Douglas-Puk algorithm is used to simplify the collected touch points, retain key points, and generate a fitted graph through closure point processing and type determination.

Benefits of technology

The accuracy of the generated fitted graphs is improved, and it supports circles, ellipses, triangles, rectangles, pentagrams, polygons, etc., which improves problem analysis and work efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116228921B_ABST
    Figure CN116228921B_ABST
Patent Text Reader

Abstract

The application relates to the field of figure processing, and discloses a figure fitting algorithm based on a Douglas-Puke algorithm, which comprises the following steps: first step: drawing on a mobile terminal screen by a brush or a finger to collect touch points; second step: simplifying the collected points by using the Douglas-Puke algorithm or adopting a least square method to obtain figure key points, retaining the key points, and obtaining result 1; third step: performing closed point processing on the result 1 to obtain result 2; fourth step: performing type judgment on the result 2; fifth step: correcting the point set in the result 2 according to the judged type to generate point set 3; and sixth step: sequentially connecting each point in the point set 3 to generate a fitting figure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of graphics processing, specifically to a graphics fitting algorithm based on the Douglas-Puk algorithm. Background Technology

[0002] With the development of mobile technology, various learning and note-taking apps have emerged. Users are increasingly inclined to take notes, study, and think about problems on mobile devices. Often, users may need to draw mathematical figures, such as triangles, rectangles, pentagrams, polygons, circles, and ellipses, to aid thinking or to make special graphic markings. Therefore, accurately and quickly drawing these figures can significantly reduce extra time and improve efficiency.

[0003] Existing technical solutions:

[0004] S1: Sampling of points by touching the mobile screen with a pen.

[0005] S2: Connect two adjacent points to generate a graph.

[0006] S3: The generated lines are drawn onto the screen in real time to achieve the effect of drawing graphics.

[0007] The above-mentioned methods can cause line distortion due to hand tremors when manually drawing graphics. Existing technologies do not provide intelligent correction for the drawn graphics, resulting in inaccurate and imperfect graphics that affect users' analysis of problems. To address this, we propose a graphics fitting algorithm based on the Douglas-Puk algorithm. Summary of the Invention

[0008] (a) Technical problems to be solved

[0009] To address the shortcomings of existing technologies, this invention provides a graph fitting algorithm based on the Douglas-Puk algorithm. By intelligently fitting mathematical graphs, it solves the problem of poor visual quality of generated graphs due to jitter during manual drawing.

[0010] (II) Technical Solution

[0011] To achieve the above-mentioned objectives, the present invention provides the following technical solution: a graph fitting algorithm based on the Douglas-Puk algorithm, comprising the following steps:

[0012] Step 1: Draw on the mobile screen using a pen or finger to collect touch points;

[0013] Step 2: Simplify the collected points using the Douglas-Puk algorithm or the least squares method to obtain the key points of the image. Retain the key points to obtain result 1;

[0014] Step 3: Process the result 1 for the closed points to obtain result 2;

[0015] Step 4: Determine the type of result 2;

[0016] Step 5: According to the determined type, correct the point set in result 2 to generate point set 3;

[0017] Step 6: Connect each point in point set 3 in sequence to generate a fitted graph.

[0018] Preferably, the Douglas - Peucker algorithm needs to use a parameter for comparing the lengths of line segments, with a threshold of ε, and a parameter for comparing the magnitudes of angles, with a threshold of a, and the thresholds are user - defined parameters.

[0019] Preferably, the steps for obtaining the key points of the graph are as follows:

[0020] S1: Set the starting point and the ending point, where A is the starting point and F is the ending point;

[0021] S2: Calculate the distances of each touch point from the straight line AF, and take the point with the maximum distance from the straight line AF, denoted as point B. The distance from point B to the straight line AF is d(B, AF), and the angles between AB and FB are denoted as ∠ABF;

[0022] S3: If d(B, AF)>ε and ∠ABF < a, then retain point B, and divide the entire point set into two point sets. The points before point B are denoted as points1: (1...4), and the points after point B are denoted as points2: (5...17). If d(B, AF)<ε, then the algorithm will delete all the points between AF and only retain points A and F;

[0023] S4: Repeat step1 and step2 for points1 and points2, and iterate in turn.

[0024] Preferably, in step 3, if the distance between the starting point A and the ending point F is very close, it means that the user wants to close the graph at this time. Set a parameter len. If D(A, F)>len, then retain point F, otherwise delete point F.

[0025] Preferably, the determination method in step 4 is as follows:

[0026] S1: According to the number of key points, group three adjacent key points, and connect them pairwise to form straight lines to obtain different angles;

[0027] S2: If there are only three key points, it can be directly determined as a triangle;

[0028] S3: If there are only four key points and the angles are close to 90 degrees, that is, between 70 degrees and 110 degrees, then the shape is determined to be a rectangle;

[0029] S4: If there are only five key points and all angles are less than 90 degrees, it means the user intends to draw a pentagram. If all five angles are obtuse, it means the user intends to draw a pentagon.

[0030] S5: If the number of key points is greater than 6, then the shape is determined to be a circle.

[0031] Preferably, the correction method in the fifth step is as follows:

[0032] S1: Find the center point of the rectangle rect, and denote it as center;

[0033] S2: Then calculate the average distance of the key points from the center point;

[0034] S3: The circle with the average value as the radius and center as the center is the circumcircle of the figure;

[0035] S4: Each point intersects the circumcircle by drawing perpendicular lines, which forms point set 3.

[0036] (III) Beneficial Effects

[0037] Compared with existing technologies, this invention provides a graph fitting algorithm based on the Douglas-Puk algorithm, which has the following advantages:

[0038] 1. This graph fitting algorithm based on the Douglas-Puk algorithm generates corresponding fitting graphs by determining the user's drawing intention. The generated fitting graphs support circles, ellipses, triangles, rectangles, pentagrams, polygons, etc., which brings efficiency improvements to problem analysis and work. Attached Figure Description

[0039] Figure 1 This is a schematic diagram of the process of the present invention;

[0040] Figure 2 To manually draw a graphic diagram;

[0041] Figure 3 A schematic diagram showing the result of fitting a manually drawn graph;

[0042] Figure 4 A schematic diagram of the point set sampled from the screen;

[0043] Figure 5 This is a diagram illustrating the distance to line AB.

[0044] Figure 6A schematic diagram showing the results after iterating through points2 using steps 1 and 2;

[0045] Figure 7 This is a schematic diagram illustrating the closure point processing of result 1;

[0046] Figure 8 A schematic diagram for generating the minimum rectangular box (rect) that encloses the set of points;

[0047] Figure 9 A schematic diagram of the circumcircle of a pentagram;

[0048] Figure 10 This is a schematic diagram illustrating the conversion of a manually drawn rectangle into a standard rectangle.

[0049] Figure 11 An example diagram illustrating how to convert a manually drawn circle into a standard circle;

[0050] Figure 12 An example diagram illustrating the conversion of a manually drawn triangle into a standard triangle;

[0051] Figure 13 This is an example illustration of converting a manually drawn polygon into a standard polygon. Detailed Implementation

[0052] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0053] Please see Figure 1-13 A graph fitting algorithm based on the Douglas-Puk algorithm includes the following steps:

[0054] Step 1: Draw on the mobile screen using a pen or finger to collect touch points;

[0055] Step 2: Simplify the collected points using the Douglas-Puk algorithm, retaining key points, to obtain result 1;

[0056] Step 3: Perform closure point processing on result 1 to obtain result 2;

[0057] Step 4: Determine the type of result 2;

[0058] Step 5: Based on the type of judgment, correct the point set in result 2 to generate point set 3;

[0059] Step 6: Connect each point in point set 3 in sequence to generate the fitted graph.

[0060] Specific examples:

[0061] The process of graph fitting is to adapt manually drawn graphs to the shape of the graph. Figure 2 The graph is fitted to a shape similar to Figure 3 The graphic.

[0062] Figure 1 This is a graphic manually drawn on a mobile device, without any processing. It's generated by directly connecting sampled points sequentially. As you can see... Figure 2 It is not a five-pointed star in the standard sense.

[0063] Figure 3 Yes Figure 2 The sampling points in the sample are specially processed and then connected to form a standard pentagram.

[0064] S1: During the manual drawing of the pentagram, the mobile device will sample dozens of points. These points need to be simplified using the Douglas-Puk algorithm. The processing procedure of the Douglas-Puk algorithm is briefly described below.

[0065] Assuming the user draws, the set of points sampled on the screen is as follows: Figure 4 As shown (the actual number of midpoints may be greater). The drawing order is as follows: Figure 4 The points are marked 1 to 17. For clarity, some special points are also marked: A, B, C, D, E, and F. These marked points were not known before simplification; they only appear during the algorithm's processing.

[0066] The algorithm requires one parameter for comparing line segment lengths, with a threshold of ε; and one parameter for comparing the size of the included angle, with a threshold of a. The thresholds are user-defined parameters.

[0067] For the manually drawn pentagram above, assume A is the starting point and F is the ending point.

[0068] Step 1: Calculate the distance from each of the remaining points to line AF, and select the point with the largest distance to line AF. Figure 3 Among all points, the fourth point has the largest distance, denoted as point B. The distance from point B to line AF is d(B,AF). Let the angle between AB and FB be ∠ABF.

[0069] Step 2: If d(B, AF) > ε and ∠ABF < a, then retain point B and divide the entire point set into two point sets. The points before B are denoted as points1: (1...4), and the points after B are denoted as points2: (5...17). If d(B, AF) < ε, then the algorithm will delete all the points between A and F and retain only points A and F. Since d(B, AF) > ε and ∠ABF < a, point B is retained.

[0070] Step 3: Repeat Step 1 and Step 2 for points1 and points2. Iterate in sequence.

[0071] Figure 3 In this case, when points1 executes Step 1 and Step 2, first connect the first and last points 1 - 4 (i.e., the straight line AB), and then compare the distances from points 2 and 3 to the straight line AB. Since both are less than ε, delete points 2 and 3. The result is as Figure 5 shown:

[0072] The result after points2 iteratively executes Step 1 and Step 2 is as Figure 6 shown.

[0073] Figure 6 and Figure 5 The sum of the results in is the result 1 after simplifying the point set.

[0074] S2: Perform closed - point processing on result 1.

[0075] Result 1 contains six points A, B, C, D, E, and F. Among them, point F is the last point before the user's finger or stylus leaves the screen. Because in the process of manually drawing a graph, generally, it is inclined to leave the screen when the drawing end is close to the start point. If the distance between the end point and the start point is very close, it means that the user wants to close the graph at this time. Set a parameter len. If D(A, F) > len, then retain point F; otherwise, delete point F.

[0076] Then for result 1, after executing this step, point F is deleted. Result 1 becomes result 2 (A, B, C, D, E). As Figure 7 shown.

[0077] S3: Make a determination on result 2.

[0078] As Figure 7 shown, there are a total of 5 points A, B, C, D, E. Take points in sequence to form five angles ∠ABC, ∠BCD, ∠CDE, ∠DEF, ∠EFA. If all five angles are less than 90 degrees, it means that the user's intention is to draw a five - star; if all five angles are obtuse, it means that the user's intention is to draw a pentagon. According to this step, result 2 is determined to be a five - star.

[0079] S4: Correct the points in result 2.

[0080] Figure 7 The position of each point in result 2 is already known. The positions of some points need to be corrected to obtain a standard pentagram. By comparing the minimum and maximum x-coordinates and y-coordinates of each point, a minimum bounding box (rect) can be generated to enclose the set of points. For example... Figure 8 As shown.

[0081] S1: Find the center point of the rectangle rect, and denote it as center.

[0082] S2: Then calculate the average distance of points A, B, C, D, and E from the center point, [D(A,center)+D(B,center)+D(C,center)+D(D,center)+D(E,center)] / 5, denoted as averageD.

[0083] S3: The circle with radius averageD and center as the center is the circumcircle of the pentagram. For example... Figure 9 As shown.

[0084] S4: First, determine the positions of points A1 and H in the standard pentagram. This needs to be determined based on the original points A and B, because the original points A and B determine the rotation angle of the standard pentagram.

[0085] Let vector center-A be (Ax-center.x, Ay-center.y), and its length len = sqrt((Ax-center.x)^2 + (Ay-center.y)^2). Then, the unit vector unit_center_A = center-A / len. Therefore, the coordinates of point A1 are: A1.x = center.x + unit_center_A.x * averageD, A1.y = center.y + unit_center_A.y * averageD.

[0086] The unit vector unit_AB of vector AB can be found in the same way.

[0087] Next, determine the coordinates of point H. The length of A1H in the pentagram is denoted as A1H_length = averageD * sin36 / cos36.

[0088] Then vector A1H = A1H_length * unit_AB. Since the coordinates of A1 have already been calculated, the coordinates of H are (A1.x + A1H.x, A1.y + A1H.y). The coordinates of the other points can be calculated similarly.

[0089] See Figure 10 This shows an example of converting a manually drawn rectangle into a standard rectangle.

[0090] First, the Douglas-Puk algorithm is used to simplify the problem to five points: A, B, C, D, and E. Then, because points A and E are very close, point E is discarded. At this point, four points remain: A, B, C, and D.

[0091] Since there are four points, we first need to determine whether the order of the four points is clockwise or counterclockwise. Let the cross product of vectors AB and BC be N1, and the cross product of vectors BC and CD be N2. If vectors N1 and N2 have the same direction, it means that A, B, C, and D were generated in a clockwise or counterclockwise order.

[0092] Assuming the angular error tolerance is 20 degrees, and ∠ABC, ∠BCD, ∠CDA, and ∠DAB are close to 90 degrees, that is, between 70 degrees and 110 degrees, then this figure is determined to be a rectangle.

[0093] use Figure 8 Find the smallest enclosing rectangle and its center point using the method described above. Calculate the average distance from points A, B, C, and D to the center point and use this average as the radius of the circumcircle of rectangle A1B1C1D1.

[0094] The next step is to determine points A1, B1, C1, and D1. Based on the original points A and B, a straight line is drawn. At this point, the line AB intersects the circumcircle at two points, A1 and B1. Therefore, we only need to determine two points in the rectangle, and the remaining points are determined by drawing perpendicular lines to the circumcircle.

[0095] See Figure 11 This shows an example of converting a manually drawn circle into a standard circle.

[0096] First, the Douglas-Puk algorithm is used to simplify the problem into seven points: A, B, C, D, E, F, and G.

[0097] Determine whether the order of the seven points is clockwise or counterclockwise. The method is the same as above.

[0098] If the number of points is greater than 6, then the shape is considered a circle.

[0099] use Figure 8The method described above finds the minimum bounding rectangle and its center point. At this point, it's necessary to distinguish between a circle and an ellipse. Assume there's a comparison value `diff`. If the difference between the length and width of the minimum bounding rectangle is less than `diff`, it means the user intended to draw a circle; otherwise, it's an ellipse.

[0100] If it is a circle, calculate the average distance from each point A, B, C, D, E, F, G to the center point as the radius. Knowing the center point and the radius, the circle is determined.

[0101] If the ellipse is an ellipse, calculate the vectors from points A, B, C, D, E, F, and G to the center point. Take the vector with the longest length as the major axis of the ellipse, and the direction perpendicular to the major axis as the minor axis. The length of the minor axis is the length of the vector with the shortest length. Knowing the major axis, minor axis, and center point, the ellipse is determined.

[0102] Figure 12 This shows an example of converting a manually drawn triangle into a standard triangle.

[0103] First, the Douglas-Puk algorithm is used to simplify the problem into three points: A, B, and C.

[0104] Since there are only three points, it can be directly identified as a triangle. Simply connect the three points in sequence.

[0105] See Figure 13 This shows an example of converting a manually drawn polygon into a standard polygon.

[0106] First, the Douglas-Puk algorithm is used to simplify the problem into five points: A, B, C, D, and E.

[0107] Determine whether the order of the five points is clockwise or counterclockwise. The method is the same as above.

[0108] Assuming the angle error is 20 degrees, since the interior angle of a regular pentagon is 108 degrees, determine whether the angle formed between the five points is between 88 degrees and 128 degrees. Figure 13 It is determined to be a polygon, specifically a pentagon.

[0109] The pentagon can be formed by connecting the five points A, B, C, D, and E in sequence.

[0110] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A graph fitting algorithm based on the Douglas-Puk algorithm, characterized in that, It includes the following steps: The first step: Draw on the mobile screen with a brush or finger to collect touch points. The second step: Simplify the collected points using the Douglas-Peucker algorithm or adopt the least squares method to obtain the key points of the graph, retain the key points, and obtain Result 1. The third step: Process the closing points of Result 1 to obtain Result 2. The fourth step: Determine the type of Result 2. The fifth step: According to the determined type, correct the point set in Result 2 to generate Point Set 3. The sixth step: Connect each point in Point Set 3 in sequence to generate a fitted graph. The Douglas-Peucker algorithm needs to use a parameter for comparing the lengths of line segments, with a threshold of ε, and a parameter for comparing the magnitudes of angles, with a threshold of a. The threshold is a user-defined parameter. The steps for obtaining the key points of the graph are as follows: S1: Set the starting point and the ending point. A is the starting point and F is the ending point. S2: Calculate the distances of each touch point from the straight line AF, and take the point with the maximum distance from the straight line AF, denoted as point B. The distance from point B to the straight line AF is d(B,AF). Denote the angles between AB and FB as ∠ABF. S3: If d(B,AF)>ε and ∠ABF<a, then retain point B, and divide the entire point set into two point sets. Points1, in the order of touch point collection, contains all points from the first collected point to the collection serial number corresponding to point B. Points2, in the order of touch point collection, contains all points from the collection serial number corresponding to point B + 1 to the last collected point. If d(B,AF)<ε, then the algorithm will delete all points between AF and only retain points A and F. S4: Repeat the above iterative process of S1 - S3 for Points1 and Points2, and iterate successively. In the third step, if the distance between the starting point A and the ending point F is very close, it means that the user wants to close the graph at this time. Set a parameter len. If D(A,F)>len, then retain point F, otherwise delete point F. The determination method in the fourth step is as follows: S1: According to the number of key points, group three adjacent key points and connect them pairwise to form straight lines to obtain different angles. S2: If there are only three key points, directly determine it as a triangle. S3: If there are only four key points and the angles are between 70 degrees and 110 degrees, then determine this graph as a rectangle. S4: If there are only five key points and all angles are less than 90 degrees, it means that the user's intention is to draw a five-star. If all five angles are obtuse, it means that the user's intention is to draw a pentagon. S5: If the number of key points is greater than 6, then determine this graph as a circle. The correction method in the fifth step is as follows: S1: Obtain the minimum bounding rectangle rect that can completely enclose all key points in Result 2, denoted as center. S2: Then calculate the average value of the distances from the key points to the center point center. S3: The circle with the average value as the radius and center as the center is the circumcircle of the graph. S4: Each point intersects with the circumcircle by drawing a perpendicular line, which is Point Set 3.