WO2018072336A1 - 一种线段擦除方法和装置 - Google Patents
一种线段擦除方法和装置 Download PDFInfo
- Publication number
- WO2018072336A1 WO2018072336A1 PCT/CN2016/113688 CN2016113688W WO2018072336A1 WO 2018072336 A1 WO2018072336 A1 WO 2018072336A1 CN 2016113688 W CN2016113688 W CN 2016113688W WO 2018072336 A1 WO2018072336 A1 WO 2018072336A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- line segment
- point
- points
- eraser
- adjacent
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F3/00—Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
- G06F3/14—Digital output to display device ; Cooperation and interconnection of the display device with other functional units
- G06F3/147—Digital output to display device ; Cooperation and interconnection of the display device with other functional units using display panels
Definitions
- the present invention relates to the field of computer software technologies, and in particular, to a line segment erasing method and apparatus.
- An object of the embodiments of the present invention is to provide a line segment erasing method and apparatus, which reduces the calculation amount of line segment erasure, and improves the operation efficiency of the line segment erasing result within a range in which the accuracy error is acceptable.
- an embodiment of the present invention provides a line segment erasing method, including:
- a point closest to the eraser edge is searched from the adjacent two points and the N points, and the point is used as an approximate intersection of the original line segment and the eraser area and the point is recorded.
- the traversing each point constituting the original line segment, determining whether each point is in the eraser area, or not Recording at points in the eraser area includes:
- the method further includes:
- the approximate intersection point near the first point is taken as the other end point of the first line segment.
- the traversing each point constituting the original line segment, determining whether each point is in the eraser area, and recording a point not in the eraser area includes:
- the method further includes:
- the approximate intersection point near the last point is taken as the other end point of the second line segment.
- the method further includes:
- round (d/w) points are equally spaced between adjacent points of the original line segment; wherein Round() For the rounding up function, d is the distance between two adjacent points on the line segment, and w is the width of the narrowest portion of the eraser.
- the original line segment is a Bezier curve.
- an embodiment of the present invention further provides a line segment erasing apparatus, including:
- a traversing determination module configured to traverse each point constituting the original line segment, determine whether each point is in the eraser area, and record a point that is not in the eraser area;
- An approximate intersection obtaining module configured to acquire two adjacent points located outside the eraser area and located in the eraser area, by inserting points between the adjacent two points, from the adjacent Obtaining an approximate intersection of the original line segment and the eraser region between two points;
- a result display module configured to display a recorded point that is not in the eraser area and the approximate intersection point, As a result of line segment erasure.
- the approximate intersection obtaining module comprises:
- An intersection coarse positioning unit configured to acquire two adjacent points on the original line segment; wherein one of the adjacent two points is located outside the eraser area, and another point is located in the eraser area;
- a point insertion unit for inserting N points at equal intervals between the adjacent two points; wherein N ⁇ 1;
- An approximate intersection finding unit configured to find a point closest to the eraser edge from the adjacent two points and the N points, and use the point as an approximate intersection point of the original line segment and the eraser region This point is recorded.
- the device further includes:
- a spacing calculation module configured to calculate a distance between adjacent points on the original line segment
- a point insertion module configured to insert Round(d/w) points equally spaced between adjacent points of the original line segment if a distance between the adjacent points is greater than a width of a narrowest portion of the eraser
- Round is a rounding function
- d is the distance between two adjacent points on the line segment
- w is the width of the narrowest portion of the eraser
- the original line segment is a Bezier curve.
- the line segment erasing method and apparatus traverses the points constituting the original line segment, determines whether each point is in the eraser area, records the points not in the eraser area, and passes through the respective locations Obtaining an approximate intersection point between the outer line segment and the adjacent two points in the eraser region to obtain an approximate intersection point between the original line segment and the eraser region, and the recorded portion is not in the eraser region
- the point and the approximate intersection point are the result of the line segment erasure.
- the line segment erasure result is calculated by the point traversal method, and the calculation amount is small.
- the approximate intersection point between the original line segment and the eraser is obtained by interpolation.
- the accuracy of the calculation result can be controlled by the number of insertion points, which can be accurate. Within the acceptable range of the degree of error, the computational efficiency of the line segment erasure result is significantly improved.
- FIG. 1 is a flow chart of a method of an embodiment of a line segment erasing method provided by the present invention
- FIG. 2 is a block diagram showing the structure of an embodiment of a line segment erasing apparatus provided by the present invention.
- FIG. 1 there is shown a block diagram of an embodiment of a line segment erasing method provided by the present invention.
- the line segment erasing method includes the following steps:
- the invention is primarily used to calculate the result of a line segment erased intersection with the eraser portion, and there should be a line segment (i.e., the original line segment) and an eraser intersecting the system. Therefore, before the start of the algorithm, the rectangle formed by the line segment and the rectangle formed by the eraser can be operated to eliminate the line segment that completely does not intersect the eraser area, and the line segment completely in the eraser area.
- a line segment in a computer is composed of a plurality of points.
- the relationship between the line segment and the eraser area can be characterized by the relationship between the point constituting the line segment and the eraser area. By traversing the points on the original line segment, it is judged to be with the eraser area. The relationship can quickly find out which points were not erased by the eraser.
- the line segment of the present invention refers to a limited portion between two points on the line, preferably a Bezier curve.
- the step S2 includes:
- S21 Obtain two adjacent points on the original line segment; wherein one of the two adjacent points is located outside the eraser area, and another point is located in the eraser area;
- the two points located inside and outside the eraser and adjacent to each other are the rough positions where the intersection of the original line segment and the eraser is located, so the adjacent two points in step S2 generally have one or two groups.
- the order of traversal is generally performed according to the track direction of the original line segment.
- the closest point to the edge of the eraser can be searched from the above points by a simple traversal or binary search algorithm, such as traversing in the direction pointed out by the eraser outside the eraser, the first one will be acquired.
- the point in the eraser area acts as the approximate intersection of the original line segment and the eraser.
- the invention obtains the approximate intersection point between the original line segment and the eraser by means of interpolation, and the accuracy of the calculation result can be inserted
- the number of in points is controlled, and the amount of calculation is small, and the operation efficiency of the line segment erasing result can be significantly improved within a range in which the accuracy error is acceptable.
- the step S1 includes:
- the method further includes:
- the approximate intersection point near the first point is taken as the other end point of the first line segment.
- the approximate intersection point near the first point means that the approximate intersection point is closer to the first point along the track direction of the original line segment. And when there is only one approximate intersection, it can be directly used as the approximate intersection near the first point.
- the step S1 further includes:
- the method further includes:
- the approximate intersection point near the last point is taken as the other end point of the second line segment.
- the approximate intersection point near the last point means that the approximate intersection point is closer to the last point along the track direction of the original line segment. And when there is only one approximate intersection, it can be directly used as the approximate intersection near the last point.
- the original line segment intersects the eraser portion, and if the first point and the last point on the original line segment are not in the eraser region, the erasure result includes the first line segment and the The second line segment. If the first point is not within the eraser area and the last point is within the eraser area, the erase result includes only the first line segment. If the first point is within the eraser area and the last point is not within the eraser area, the erase result includes only the second line segment.
- the points on the original line segment are sequentially traversed along the line segment trajectory direction from the first point and the last point of the original line segment by two threads, respectively, to obtain the first A line segment and the second line segment are used as line segment erasure results to increase the traversal speed.
- the method further includes:
- round (d/w) points are equally spaced between adjacent points of the original line segment; wherein Round() For the rounding up function, d is the distance between two adjacent points on the line segment, and w is the width of the narrowest portion of the eraser.
- the eraser is preferably rectangular, and the width of the eraser at the narrowest point is equal to the side length of the narrowest side of the rectangle, so in a specific implementation, the distance between two adjacent points should not exceed the eraser.
- the narrowest side that is, when the eraser intersects with the original line segment, there is always a point on the original line segment that falls inside the eraser.
- the approximate intersection of the eraser and the original line segment can be obtained in one traversal, as follows:
- Step 1 starting from the first point of the original line segment (which may be any one of the end points of the original line segment), sequentially traversing the direction of the click line segment on the original line segment, and the current point of the traversal is recorded as point p;
- Step 2 If the point p is the first point of the original line segment and is not in the rectangle R (ie, the eraser, the eraser can be abstracted into a rectangle R), then record this point as the first in the line segment erasure result.
- Step 3 Following step 2, continue to traverse the points on the original line segment. If the point p is not in the rectangle R, add the point p to the first line segment A;
- Step 5 Continue to step 4, continue to traverse the point on the original line segment. If the point p is the last point of the original line segment, and the point p still falls within the rectangle R, the algorithm ends, and the line segment erase result is the first line segment.
- Step 6 Following step 4 or step 8, continue to traverse the points on the original line segment.
- the first point of the point p is recorded as the point k, and the point p and the point k are inserted.
- N points which are divided into N+1 equal parts, traverse the point between point k and point p, take the last point in the rectangle R (or take the first point outside the rectangle R) as a second approximate intersection of the original line segment and the rectangle R, and also the starting point of the second line segment B in the line segment erasure result;
- Step 7 Following step 6, continue to traverse the point on the original line segment. If the point p is not in the rectangle R, add the point p to the second line segment B until the last point of the original line segment, and use the last point as The end point of the second line segment B, thereby obtaining the second line segment B.
- Step 8 Following step 1, if the point p is the first point of the original line segment and falls within the rectangle R, the algorithm starts from step 6 and starts running down.
- the line segment erasing method provided by the present invention only needs to perform a traversal on the points constituting the original line segment to obtain The approximate intersection of the eraser and the original line segment, the result of the original line segment being erased (the first line segment and/or the second line segment), the calculation amount is small, the calculation speed is fast, and at the same time, by inserting a point on the original line segment,
- the approximated calculation results are very similar to the exact results. In the acceptable range of accuracy error, the computational efficiency is significantly improved, which is beneficial to improve the user experience.
- FIG. 2 there is shown a block diagram of an embodiment of a line segment erasing apparatus provided by the present invention.
- the basic principle of the embodiment is consistent with the foregoing method implementation. For details that are not detailed in this embodiment, refer to the related description in the foregoing method embodiments.
- the line segment erasing device includes:
- the traversing determination module 21 is configured to traverse each point constituting the original line segment, determine whether each point is in the eraser area, and record a point that is not in the eraser area;
- An approximate intersection obtaining module 22 is configured to acquire two adjacent points located outside the eraser region and located in the eraser region, and insert the dots between the adjacent two points from the phase Obtaining an approximate intersection of the original line segment and the eraser region between two adjacent points;
- the result display module 23 is configured to display the recorded points not in the eraser area and the approximate intersection point as a result of line segment erasure.
- the approximate intersection obtaining module 22 includes:
- An intersection coarse positioning unit 221 is configured to acquire two adjacent points on the original line segment; wherein one of the adjacent two points is located outside the eraser area, and another point is located in the eraser area ;
- a point insertion unit 222 for inserting N points at equal intervals between the adjacent two points; wherein, N ⁇ 1;
- An approximate intersection finding unit 223 is configured to search for a point closest to the eraser edge from the adjacent two points and the N points, and use the point as an approximate intersection of the original line segment and the eraser region. Record this point.
- the apparatus may further include:
- a spacing calculation module configured to calculate a distance between adjacent points on the original line segment
- a point insertion module configured to insert Round(d/w) points equally spaced between adjacent points of the original line segment if a distance between the adjacent points is greater than a width of a narrowest portion of the eraser
- Round is a rounding function
- d is the distance between two adjacent points on the line segment
- w is the width of the narrowest portion of the eraser
- the original line segment is a Bezier curve.
- the line segment erasing method and apparatus provided by the present invention, by traversing the points constituting the original line segment, determine whether each point is in the eraser area, and record the points not in the eraser area, and Obtaining an approximate intersection of the original line segment and the eraser region by interpolating between two adjacent points located outside the eraser region and located in the eraser region, respectively
- the points in the eraser area and the approximate intersection are the result of line segment erasure.
- the line segment erasure result is performed by point traversal, and the calculation amount is small.
- the approximate intersection point between the original line segment and the eraser is obtained by interpolation.
- the accuracy of the calculation result can be controlled by the number of insertion points, and the accuracy can be obtained. Error Within the acceptable range, the computational efficiency of the line segment erase result is significantly improved.
- the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical. Units can be located in one place or distributed to multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
- the connection relationship between the modules indicates that there is a communication connection between them, and specifically, one or more communication buses or signal lines can be realized.
- the present invention can be implemented by means of software plus necessary general hardware, and of course, dedicated hardware, dedicated CPU, dedicated memory, dedicated memory, Special components and so on.
- functions performed by computer programs can be easily implemented with the corresponding hardware, and the specific hardware structure used to implement the same function can be various, such as analog circuits, digital circuits, or dedicated circuits. Circuits, etc.
- software program implementation is a better implementation in more cases.
- the technical solution of the present invention which is essential or contributes to the prior art, can be embodied in the form of a software product stored in a readable storage medium, such as a floppy disk of a computer.
- U disk mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., including a number of instructions to make a computer device (can be an individual A computer, server, or network device, etc.) performs the methods described in various embodiments of the present invention.
- a computer device can be an individual A computer, server, or network device, etc.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Human Computer Interaction (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Processing Or Creating Images (AREA)
- Image Generation (AREA)
Abstract
一种线段擦除方法和装置,所述方法包括:对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录(S1);获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点(S2);对记录的不在所述橡皮擦区域内的点以及所述近似交点进行显示,作为线段擦除的结果(S3)。所述方法可减少线段擦除的计算量,在精确度误差可接受的范围内,提高线段擦除结果的运算效率。
Description
本发明涉及计算机软件技术领域,尤其涉及一种线段擦除方法和装置。
在电子白板软件中,当使用橡皮擦擦除一条线段的一部分时,需要计算这段线段被擦除一部分之后留下的内容。传统的方法是计算这条线段与橡皮擦图形所构成的相交点,从而算出擦除后留下的内容,这种的方法的优点是计算精确,但是计算量大,特别是同时擦除多条线段时,容易出现软件假死、无响应的现象,影响用户体验。
发明内容
本发明实施例的目的在于提供一种线段擦除方法和装置,减少线段擦除的计算量,在精确度误差可接受的范围内,提高线段擦除结果的运算效率。
为实现上述目的,本发明实施例提供了一种线段擦除方法,包括:
对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录;
获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点;
对记录的不在所述橡皮擦区域内的点以及所述近似交点进行显示,作为线段擦除的结果。
其中,获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点,包括:
获取所述原线段上的相邻两点;其中,所述相邻两点中的一个点位于所述橡皮擦区域外,另一个点位于所述橡皮擦区域内;
在所述相邻两点之间等间距地插入N个点;其中,N≥1;
从所述相邻两点以及所述N个点中查找与橡皮擦边沿最接近的点,将该点作为所述原线段与所述橡皮擦区域的近似交点并对该点进行记录。
优选地,所述对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不
在所述橡皮擦区域内的点进行记录,包括:
判断所述原线段的第一个点是否在橡皮擦区域内,若不在,则将所述第一个点作为线段擦除结果中的第一线段的一个端点,并将所述第一个点之后连续的不在所述橡皮擦区域内的点添加到所述第一线段中;
在所述获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点之后,还包括:
将靠近所述第一个点的所述近似交点作为所述第一线段的另一个端点。
优选地,所述对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录,包括:
判断所述原线段的最后一个点是否在橡皮擦区域内,若不在,则将所述最后一个点作为线段擦除结果中的第二线段的一个端点,并将所述最后一个点之前连续的不在所述橡皮擦区域内的点添加到所述第一线段中;
在所述获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点之后,还包括:
将靠近所述最后一个点的所述近似交点作为所述第二线段的另一个端点。
进一步地,在所述对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录之前,还包括:
计算所述原线段上的相邻点之间的距离;
若所述相邻点之间的距离大于橡皮擦最窄处的宽度,则在所述原线段的各相邻点之间等间距地插入Round(d/w)个点;其中,Round()为向上取整函数,d为所述线段上相邻两点之间的距离,w为所述橡皮擦最窄处的宽度。
优选地,所述原线段为贝塞尔曲线。
相应地,本发明实施例还提供了一种线段擦除装置,包括:
遍历判断模块,用于对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录;
近似交点获取模块,用于获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点;
结果显示模块,用于对记录的不在所述橡皮擦区域内的点以及所述近似交点进行显示,
作为线段擦除的结果。
优选地,所述近似交点获取模块包括:
交点粗定位单元,用于获取所述原线段上的相邻两点;其中,所述相邻两点中的一个点位于所述橡皮擦区域外,另一个点位于所述橡皮擦区域内;
点插入单元,用于在所述相邻两点之间等间距地插入N个点;其中,N≥1;
近似交点查找单元,用于从所述相邻两点以及所述N个点中查找与橡皮擦边沿最接近的点,将该点作为所述原线段与所述橡皮擦区域的近似交点并对该点进行记录。
进一步地,所述装置还包括:
间距计算模块,用于计算所述原线段上的相邻点之间的距离;
点插入模块,用于若所述相邻点之间的距离大于橡皮擦最窄处的宽度,则在所述原线段的各相邻点之间等间距地插入Round(d/w)个点;其中,Round()为向上取整函数,d为所述线段上相邻两点之间的距离,w为所述橡皮擦最窄处的宽度。
优选地,所述原线段为贝塞尔曲线。
本发明提供的线段擦除方法和装置,通过对构成原线段的点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录,并通过在分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点之间插点的方式,获取所述原线段和所述橡皮擦区域的近似交点,将记录的不在所述橡皮擦区域内的点以及所述近似交点作为线段擦除的结果。线段擦除结果通过点遍历的方式进行计算,计算量较小,原线段与橡皮擦的近似交点通过插点的方式获取,计算结果的精确度可通过插入点的个数进行控制,可在精确度误差可接受的范围内,显著提高线段擦除结果的运算效率。
图1是本发明提供的线段擦除方法的一个实施例的方法流程图;
图2是本发明提供的线段擦除装置的一个实施例的装置结构图。
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
参见图1,是本发明提供的线段擦除方法的一个实施例的结构图。
如图1所示,所述线段擦除方法包括以下步骤:
S1,对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录;
本发明主要用于计算与橡皮擦部分相交的线段擦除后结果,系统中应当存在一条线段(即所述原线段)和与之相交的橡皮擦。因此在算法开始前,可通过将线段构成的矩形与橡皮擦构成的矩形进行运算,排除掉与橡皮擦区域完全不相交的线段,和完全在橡皮擦区域内的线段。
计算机中的一条线段是由很多个点构成的,线段与橡皮擦区域的关系可通过构成线段的点与橡皮擦区域的关系来表征,通过遍历原线段上的各个点,判断其与橡皮擦区域的关系,可快速找到哪些点未被橡皮擦擦除。其中,本发明所述线段是指线上两点间的有限部分,优选为贝塞尔曲线。
S2,获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点;
具体地,所述步骤S2包括:
S21,获取所述原线段上的相邻两点;其中,所述相邻两点中的一个点位于所述橡皮擦区域外,另一个点位于所述橡皮擦区域内;
位于橡皮擦内外并且相邻的两个点为原线段与橡皮擦的交点所在的粗略位置,因此步骤S2中所述相邻两点一般有一组或者两组。在具体实施当中,遍历的顺序一般按照原线段的轨迹方向进行,通过判断各点与橡皮擦区域的关系,可轻易地获取分别位于橡皮擦内外且相邻的两个点。
S22,在所述相邻两点之间等间距地插入N个点;其中,N≥1;
S23,从所述相邻两点以及所述N个点中查找与橡皮擦边沿最接近的点,将该点作为所述原线段与所述橡皮擦区域的近似交点并对该点进行记录。
插入点的个数越多,近似交点的计算结果越接近精确结果,所述N优选为19。在具体实施当中,可通过简单遍历或者二分查找等算法从上述点中查找与橡皮擦边沿最接近的点,如可沿由橡皮擦外指向橡皮擦内的方向进行遍历,将获取的第一个在橡皮擦区域内的点(或者最后一个在橡皮擦区域外的点)作为原线段与橡皮擦的近似交点。
S3,对记录的不在所述橡皮擦区域内的点以及所述近似交点进行显示,作为线段擦除的结果。
本发明通过插点的方式,获取原线段与橡皮擦的近似交点,计算结果的精确度可通过插
入点的个数进行控制,计算量较小,可在精确度误差可接受的范围内,显著提高线段擦除结果的运算效率。
其中,所述步骤S1包括:
判断所述原线段的第一个点是否在橡皮擦区域内,若不在,则将所述第一个点作为线段擦除结果中的第一线段的一个端点,并将所述第一个点之后连续的不在所述橡皮擦区域内的点添加到所述第一线段中;
若所述原线段的第一个点不在所述橡皮擦区域内,则所述步骤S2之后,还包括:
将靠近所述第一个点的所述近似交点作为所述第一线段的另一个端点。
靠近所述第一个点的所述近似交点,是指所述近似交点沿所述原线段的轨迹方向距离所述第一个点较近。而当仅有一个近似交点时,可直接将其作为靠近所述第一个点的所述近似交点。
继续按原线段的轨迹方向对原线段上的点进行遍历,若所述原线段的最后一点仍在所述橡皮擦范围内,则算法结束,将所述第一线段作为线段擦除结果。
所述步骤S1还包括:
判断所述原线段的最后一个点是否在橡皮擦区域内,若不在,则将所述最后一个点作为线段擦除结果中的第二线段的一个端点,并将所述最后一个点之前连续的不在所述橡皮擦区域内的点添加到所述第一线段中;
若所述原线段的最后一个点不在所述橡皮擦区域内,则所述步骤S2之后,还包括:
将靠近所述最后一个点的所述近似交点作为所述第二线段的另一个端点。
与前述类似的,靠近所述最后一个点的所述近似交点,是指所述近似交点沿所述原线段的轨迹方向距离所述最后一个点较近。而当仅有一个近似交点时,可直接将其作为靠近所述最后一个点的所述近似交点。
在具体实施当中,原线段与橡皮擦部分相交,若所述原线段上的第一个点和最后一个点均不在所述橡皮擦区域内,则擦除结果包括所述第一线段和所述第二线段。若所述第一个点不在所述橡皮擦区域内,而所述最后一个点在所述橡皮擦区域内,则擦除结果仅包括所述第一线段。若所述第一个点在所述橡皮擦区域内,而所述最后一个点不在所述橡皮擦区域内,则擦除结果仅包括所述第二线段。在一种优选的实施方式当中,可通过两个线程分别从所述原线段的第一个点和最后一个点开始沿线段轨迹方向对原线段上的点进行顺序遍历,以分别获取所述第一线段和所述第二线段作为线段擦除结果,提高遍历的速度。
进一步地,为保证线段上总有一点落在橡皮擦的内部,在所述步骤S1之前,还包括:
计算所述原线段上的相邻点之间的距离;
若所述相邻点之间的距离大于橡皮擦最窄处的宽度,则在所述原线段的各相邻点之间等间距地插入Round(d/w)个点;其中,Round()为向上取整函数,d为所述线段上相邻两点之间的距离,w为所述橡皮擦最窄处的宽度。
所述橡皮擦优选为矩形,所述橡皮擦最窄处的宽度等于所述矩形的最窄边的边长,因此在具体实施当中,应使得相邻两点之间的距离不超过橡皮擦的最窄边,即使得橡皮擦与原线段相交时,原线段上总有一点落在橡皮擦的内部。
在具体实施当中,可在一次遍历中,得到橡皮擦与原线段的近似交点,过程如下:
步骤1:从原线段的第一个点(可以为原线段的任意一个端点)开始,对原线段上的点按线段轨迹方向进行顺序遍历,遍历的当前点记为点p;
步骤2:如果点p是原线段的第一个点,且不在矩形R(即橡皮擦,可将橡皮擦抽象为一个矩形R)内,则记录下这一点,作为线段擦除结果中第一线段A的起点;
步骤3:接步骤2,继续对原线段上的点进行遍历,如果点p不在矩形R内,则将点p加入到第一线段A中;
步骤4:接步骤3,当检测到点p落在了矩形R内,将点p的前一点记为点f,在点p和点f之间插入N个点,使其均分为N+1等份(N≥1,插入点越多,结果越接近精确结果,优选地N=19),遍历点f到点p之间的点,取第一个在矩形R内的点(或者取最后一个在矩形R外的点),作为原线段与矩形R的第一近似交点,同时也是第一线段A的终点,从而得到第一线段A;(注:这里的描述是用简单遍历的方式来查找近似交点,在具体实施当中也可以使用二分查找之类的算法进行进一步的优化)。
步骤5:接步骤4,继续对原线段上的点进行遍历,如果点p为原线段的最后一点,且点p仍落在矩形R内,则算法结束,线段擦除结果为第一线段A;
步骤6:接步骤4或者步骤8,继续对原线段上的点进行遍历,当检测到点p在矩形R外,将点p的前一点记为点k,在点p和点k之间插入N个点,使其均分为N+1等份,遍历点k到点p之间的点,取最后一个在矩形R内的点(或者取第一个在矩形R外的点),作为原线段与矩形R的第二近似交点,同时也是线段擦除结果中第二线段B的起点;
步骤7:接步骤6,继续对原线段上的点进行遍历,如果点p不在矩形R内,则将点p加入到第二线段B中,直到原线段的最后一点,将所述最后一点作为所述第二线段B的终点,从而得到第二线段B。
步骤8:接步骤1,如果点p是原线段的第一个点,且落在矩形R内,则算法从步骤6开始往下运行。
由此可见,本发明提供的线段擦除方法仅需对构成原线段的点进行一次遍历,即可获取
橡皮擦与原线段的的近似交点,得到原线段被擦除后的结果(第一线段和/或第二线段),计算量小,计算速度快,同时通过在原线段上插点的方法,近似得到的计算结果与精确结果非常相近,在精确度误差可接受的范围内,显著提高了运算效率,有利于改善用户体验。
参见图2,是本发明提供的线段擦除装置的一个实施例的装置结构图。本实施例的基本原理与前述方法实施一致,本实施例中未详述之处可参见前述方法实施例中的相关描述。
如图2所示,所述线段擦除装置包括:
遍历判断模块21,用于对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录;
近似交点获取模块22,用于获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点;
结果显示模块23,用于对记录的不在所述橡皮擦区域内的点以及所述近似交点进行显示,作为线段擦除的结果。
其中,所述近似交点获取模块22包括:
交点粗定位单元221,用于获取所述原线段上的相邻两点;其中,所述相邻两点中的一个点位于所述橡皮擦区域外,另一个点位于所述橡皮擦区域内;
点插入单元222,用于在所述相邻两点之间等间距地插入N个点;其中,N≥1;
近似交点查找单元223,用于从所述相邻两点以及所述N个点中查找与橡皮擦边沿最接近的点,将该点作为所述原线段与所述橡皮擦区域的近似交点并对该点进行记录。
图2中虽未画出,但在具体实施当中,所述装置还可以进一步包括:
间距计算模块,用于计算所述原线段上的相邻点之间的距离;
点插入模块,用于若所述相邻点之间的距离大于橡皮擦最窄处的宽度,则在所述原线段的各相邻点之间等间距地插入Round(d/w)个点;其中,Round()为向上取整函数,d为所述线段上相邻两点之间的距离,w为所述橡皮擦最窄处的宽度。
优选地,所述原线段为贝塞尔曲线。
综上所述,本发明提供的线段擦除方法和装置,通过对构成原线段的点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录,并通过在分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点之间插点的方式,获取所述原线段和所述橡皮擦区域的近似交点,将记录的不在所述橡皮擦区域内的点以及所述近似交点作为线段擦除的结果。线段擦除结果通过点遍历的方式进行,计算量较小,原线段与橡皮擦的近似交点通过插点的方式获取,计算结果的精确度可通过插入点的个数进行控制,可在精确度误差
可接受的范围内,显著提高线段擦除结果的运算效率。
需说明的是,以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。另外,本发明提供的装置实施例附图中,模块之间的连接关系表示它们之间具有通信连接,具体可以实现为一条或多条通信总线或信号线。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到本发明可借助软件加必需的通用硬件的方式来实现,当然也可以通过专用硬件包括专用集成电路、专用CPU、专用存储器、专用元器件等来实现。一般情况下,凡由计算机程序完成的功能都可以很容易地用相应的硬件来实现,而且,用来实现同一功能的具体硬件结构也可以是多种多样的,例如模拟电路、数字电路或专用电路等。但是,对本发明而言更多情况下软件程序实现是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在可读取的存储介质中,如计算机的软盘,U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,RandomAccess Memory)、磁碟或者光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。
Claims (10)
- 一种线段擦除方法,其特征在于,包括:对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录;获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点;对记录的不在所述橡皮擦区域内的点以及所述近似交点进行显示,作为线段擦除的结果。
- 如权利要求1所述的线段擦除方法,其特征在于,获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点,包括:获取所述原线段上的相邻两点;其中,所述相邻两点中的一个点位于所述橡皮擦区域外,另一个点位于所述橡皮擦区域内;在所述相邻两点之间等间距地插入N个点;其中,N≥1;从所述相邻两点以及所述N个点中查找与橡皮擦边沿最接近的点,将该点作为所述原线段与所述橡皮擦区域的近似交点并对该点进行记录。
- 如权利要求1所述的线段擦除方法,其特征在于,所述对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录,包括:判断所述原线段的第一个点是否在橡皮擦区域内,若不在,则将所述第一个点作为线段擦除结果中的第一线段的一个端点,并将所述第一个点之后连续的不在所述橡皮擦区域内的点添加到所述第一线段中;在所述获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点之后,还包括:将靠近所述第一个点的所述近似交点作为所述第一线段的另一个端点。
- 如权利要求1所述的线段擦除方法,其特征在于,所述对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录,包括:判断所述原线段的最后一个点是否在橡皮擦区域内,若不在,则将所述最后一个点作为线段擦除结果中的第二线段的一个端点,并将所述最后一个点之前连续的不在所述橡皮擦区 域内的点添加到所述第一线段中;在所述获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点之后,还包括:将靠近所述最后一个点的所述近似交点作为所述第二线段的另一个端点。
- 如权利要求1所述的线段擦除方法,其特征在于,在所述对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录之前,还包括:计算所述原线段上的相邻点之间的距离;若所述相邻点之间的距离大于橡皮擦最窄处的宽度,则在所述原线段的各相邻点之间等间距地插入Round(d/w)个点;其中,Round()为向上取整函数,d为所述线段上相邻两点之间的距离,w为所述橡皮擦最窄处的宽度。
- 如权利要求1~5任一项所述的线段擦除方法,其特征在于,所述原线段为贝塞尔曲线。
- 一种线段擦除装置,其特征在于,包括:遍历判断模块,用于对构成原线段的各个点进行遍历,判断各个点是否在橡皮擦区域内,对不在所述橡皮擦区域内的点进行记录;近似交点获取模块,用于获取分别位于所述橡皮擦区域外和位于所述橡皮擦区域内的相邻两点,通过在所述相邻两点之间插点的方式,从所述相邻两点之间获取所述原线段和所述橡皮擦区域的近似交点;结果显示模块,用于对记录的不在所述橡皮擦区域内的点以及所述近似交点进行显示,作为线段擦除的结果。
- 如权利要求6所述的线段擦除装置,其特征在于,所述近似交点获取模块包括:交点粗定位单元,用于获取所述原线段上的相邻两点;其中,所述相邻两点中的一个点位于所述橡皮擦区域外,另一个点位于所述橡皮擦区域内;点插入单元,用于在所述相邻两点之间等间距地插入N个点;其中,N≥1;近似交点查找单元,用于从所述相邻两点以及所述N个点中查找与橡皮擦边沿最接近的点,将该点作为所述原线段与所述橡皮擦区域的近似交点并对该点进行记录。
- 如权利要求6所述的线段擦除装置,其特征在于,所述装置还包括:间距计算模块,用于计算所述原线段上的相邻点之间的距离;点插入模块,用于若所述相邻点之间的距离大于橡皮擦最窄处的宽度,则在所述原线段的各相邻点之间等间距地插入Round(d/w)个点;其中,Round()为向上取整函数,d为所述线段上相邻两点之间的距离,w为所述橡皮擦最窄处的宽度。
- 如权利要求7~9任一项所述的线段擦除装置,其特征在于,所述原线段为贝塞尔曲线。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201610912303.XA CN106502607B (zh) | 2016-10-19 | 2016-10-19 | 一种线段擦除方法和装置 |
| CN201610912303.X | 2016-10-19 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2018072336A1 true WO2018072336A1 (zh) | 2018-04-26 |
Family
ID=58294227
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2016/113688 Ceased WO2018072336A1 (zh) | 2016-10-19 | 2016-12-30 | 一种线段擦除方法和装置 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN106502607B (zh) |
| WO (1) | WO2018072336A1 (zh) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114297977A (zh) * | 2021-12-16 | 2022-04-08 | 苏州浪潮智能科技有限公司 | 一种切断丝印的方法和装置 |
| CN115481475A (zh) * | 2022-09-21 | 2022-12-16 | 金鹏装配式建筑有限公司 | 用于cad中无法面域化的多段线重合判定方法 |
Families Citing this family (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107193424A (zh) * | 2017-06-27 | 2017-09-22 | 北京北纬天辰科技有限公司 | 一种智能电子式擦除方法及装置 |
| CN108805120A (zh) * | 2018-06-13 | 2018-11-13 | 广州视源电子科技股份有限公司 | 笔迹的处理方法和装置 |
| CN110007838B (zh) * | 2019-04-02 | 2020-12-11 | 广州视源电子科技股份有限公司 | 擦除控件的处理方法、装置和设备 |
| CN112286424B (zh) | 2019-07-25 | 2025-04-29 | 中兴通讯股份有限公司 | 笔画擦除方法、终端及计算机可读存储介质 |
| CN114924685A (zh) * | 2022-04-30 | 2022-08-19 | 新华三智能终端有限公司 | 一种书写交互方法、装置以及书写终端 |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101609560A (zh) * | 2009-07-16 | 2009-12-23 | 广东威创视讯科技股份有限公司 | 一种擦除笔迹的方法 |
| CN102566862A (zh) * | 2010-12-21 | 2012-07-11 | 汉王科技股份有限公司 | 交互式电子白板中几何图形的擦除方法和装置 |
| CN103578553A (zh) * | 2013-10-14 | 2014-02-12 | 江苏敏行信息技术有限公司 | 一种矢量线型快速擦除方法 |
| US20150234587A1 (en) * | 2014-02-17 | 2015-08-20 | Fujitsu Limited | Information processing apparatus, non-transitory readable medium, and handwriting input method |
-
2016
- 2016-10-19 CN CN201610912303.XA patent/CN106502607B/zh active Active
- 2016-12-30 WO PCT/CN2016/113688 patent/WO2018072336A1/zh not_active Ceased
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101609560A (zh) * | 2009-07-16 | 2009-12-23 | 广东威创视讯科技股份有限公司 | 一种擦除笔迹的方法 |
| CN102566862A (zh) * | 2010-12-21 | 2012-07-11 | 汉王科技股份有限公司 | 交互式电子白板中几何图形的擦除方法和装置 |
| CN103578553A (zh) * | 2013-10-14 | 2014-02-12 | 江苏敏行信息技术有限公司 | 一种矢量线型快速擦除方法 |
| US20150234587A1 (en) * | 2014-02-17 | 2015-08-20 | Fujitsu Limited | Information processing apparatus, non-transitory readable medium, and handwriting input method |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114297977A (zh) * | 2021-12-16 | 2022-04-08 | 苏州浪潮智能科技有限公司 | 一种切断丝印的方法和装置 |
| CN114297977B (zh) * | 2021-12-16 | 2024-01-23 | 苏州浪潮智能科技有限公司 | 一种切断丝印的方法和装置 |
| CN115481475A (zh) * | 2022-09-21 | 2022-12-16 | 金鹏装配式建筑有限公司 | 用于cad中无法面域化的多段线重合判定方法 |
| CN115481475B (zh) * | 2022-09-21 | 2023-09-19 | 金鹏装配式建筑有限公司 | 用于cad中无法面域化的多段线重合判定方法 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN106502607B (zh) | 2019-02-22 |
| CN106502607A (zh) | 2017-03-15 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2018072336A1 (zh) | 一种线段擦除方法和装置 | |
| CN102890697B (zh) | 基于地图限定区域的对象查找方法 | |
| CN108229740B (zh) | 一种商圈边界的确定方法、装置、服务器及存储介质 | |
| CN111202986A (zh) | 游戏中虚拟赛道的生成方法、装置、处理器及电子装置 | |
| WO2019214489A1 (zh) | 曲线擦除 | |
| CN115218915B (zh) | 模拟驾驶测试方法、装置、计算机设备和存储介质 | |
| CN111185013A (zh) | 基于虚拟赛道的游戏数据获取方法、处理器及电子装置 | |
| WO2018068196A1 (zh) | 一种血管脊线追踪方法及装置 | |
| CN114757035B (zh) | 卫星可见弧段的数据处理方法、装置、介质及设备 | |
| US11226993B2 (en) | Method and apparatus for clustering data stream | |
| KR102076600B1 (ko) | 오브젝트 추적 장치 및 그의 오브젝트 추적 방법 | |
| CN115147474A (zh) | 点云标注模型的生成方法、装置、电子设备及存储介质 | |
| CN115409070A (zh) | 离散数据序列临界点的确定方法、装置以及设备 | |
| CN111126299A (zh) | 面向时序目标检测的优化方法和评估系统 | |
| CN112286424A (zh) | 笔画擦除方法、终端及计算机可读存储介质 | |
| CN110470310A (zh) | 自动地图生成 | |
| CN117853382B (zh) | 基于稀疏标记物的图像矫正方法、装置及存储介质 | |
| US9390323B1 (en) | Recommending sites through metadata analysis | |
| CN108399179A (zh) | 确定道路曲率的方法和装置 | |
| CN105574907B (zh) | 信息处理方法及装置 | |
| CN109829440A (zh) | 一种检测道路差异的方法、装置、电子设备及存储介质 | |
| JP5731425B2 (ja) | 処理単位指定装置及びその方法、並びに処理単位を指定するためのコンピュータプログラム及びコンピュータプログラムを記録した記録媒体 | |
| CN111524209B (zh) | 电子书写方法、装置、终端以及存储介质 | |
| CN118898695A (zh) | 数字孪生三维场景中绘制贴地线的方法和系统 | |
| CN114445519B (zh) | 生成车道导向标记的方法、装置、设备、存储介质及产品 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 16919257 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 32PN | Ep: public notification in the ep bulletin as address of the adressee cannot be established |
Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 17/09/2019) |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 16919257 Country of ref document: EP Kind code of ref document: A1 |