Method and device for quickly cutting triangle based on intersection point and storage medium
By numbering and obtaining attributes of vertices and intersections of triangles, the cut triangle is constructed, which solves the problem of low computational efficiency of triangle cutting algorithms in the prior art and the inability to retain additional attributes, and achieves efficient triangle cutting and attribute retention.
Patent Information
- Application Number
- CN202411993381.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2044-12-31
AI Technical Summary
Existing triangle cutting algorithms are inefficient in computing and cannot retain additional properties associated with triangle vertices, such as color and texture coordinates.
By numbering the three original vertices of the triangle and the possible intersection points, obtain the properties of the intersection points, and arrange them in preset order to form a PTS array, remove empty intersection points, extract the remaining intersection points and vertices, and build the cut triangle.
It realizes rapid cutting of triangles, improves computing efficiency, and can retain additional properties of triangle vertices to ensure the correctness of attributes.
Smart Images

Figure CN119762495A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of geometric data technology, and in particular to a method, device and storage medium for fast cutting of triangles based on intersection points. Background Art
[0002] At present, the triangle cutting algorithm is widely used in the Boolean operation and intersection cutting algorithm of geometric operation, so the efficiency of the algorithm has a great influence on the entire geometric operation;
[0003] Existing triangle cutting algorithms generally use the method of finding the intersection of triangles and then re-dividing the triangles. This method has a slow operation speed and requires complex mathematical calculations. It has high time and space complexity. At the same time, it cannot retain additional attributes associated with triangle vertices, such as color and texture coordinates. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide a method, device and storage medium for quickly cutting triangles based on intersection points, so as to solve the problems of low computational efficiency of existing triangle cutting algorithms and inability to retain additional attributes associated with triangle vertices.
[0005] According to a first aspect of an embodiment of the present invention, a method for quickly cutting triangles based on intersection points is provided, the method comprising:
[0006] The triangle is wound in the original direction, and the three original vertices of the triangle are numbered; possible intersection points between the straight line and the triangle are numbered;
[0007] Obtaining the attributes of the three original vertices of the triangle, and obtaining the attributes of the three intersection points respectively according to the distance and attributes of any intersection point from the two original vertices on the same straight line;
[0008] Arrange the numbers of the three original vertices and the numbers of the three intersection points in a preset order to obtain a PTS array;
[0009] While maintaining the order of each element of the PTS array, removing the intersection points whose attributes are empty in the PTS array;
[0010] Determine whether the number of remaining elements in the PTS array is three. If it is three, directly form a triangle with the points in the PTS array, save the obtained triangle and the attributes of the corresponding vertices in the cut triangle array, and trigger the end process;
[0011] If not, determine whether the second element and the last element in the PTS array are both original vertices; if so, move the first element in the PTS array to the end of the PTS array; if not, keep the order of the elements in the PTS array unchanged;
[0012] The last element, the first element and the second element in the PTS array form a triangle, and the obtained triangle and the attributes of the corresponding vertices are saved in the cut triangle array;
[0013] Delete the first element in the PTS array and repeat the above triangle extraction process until the end of the process is triggered.
[0014] Preferably,
[0015] The numbering of the three original vertices of the triangle comprises:
[0016] The three original vertices of the triangle are numbered as vertex PT1, vertex PT2 and vertex PT3 according to the original winding direction;
[0017] The numbering of possible intersection points between the straight line and the triangle comprises:
[0018] The intersection point of the straight line and the edge formed by vertices PT1 and PT2 is numbered as intersection point PT12, the intersection point of the straight line and the edge formed by vertices PT2 and PT3 is numbered as intersection point PT23, and the intersection point of the straight line and the edge formed by vertices PT3 and PT1 is numbered as intersection point PT31.
[0019] Preferably,
[0020] The attributes include: texture coordinates or color.
[0021] Preferably,
[0022] The method of obtaining the properties of the three intersection points according to the distance and properties of any intersection point from the two original vertices on the same straight line includes:
[0023] Get the distance from the intersection point to the two original vertices on the same straight line, and get the distance between the two original vertices;
[0024] The texture coordinates or colors of the intersection point are obtained according to the distances from the intersection point to two original vertices on the same straight line, the distance between the two original vertices, and the texture coordinates or colors of the two original vertices.
[0025] Preferably,
[0026] If the attribute is color, then obtain the RGB channel values of the three original vertices respectively;
[0027] When obtaining the color of any intersection point, the R channel value of the intersection point is obtained according to the distance from the intersection point to the two original vertices on the same straight line, the distance between the two original vertices, and the R channel values of the two original vertices;
[0028] Obtain the G channel value of the intersection point according to the distances from the intersection point to the two original vertices on the same straight line, the distance between the two original vertices, and the G channel values of the two original vertices;
[0029] Obtain the B channel value of the intersection point according to the distances from the intersection point to the two original vertices on the same straight line, the distance between the two original vertices, and the B channel values of the two original vertices;
[0030] The color of the intersection point is obtained according to the R channel value, G channel value, and B channel value of the intersection point.
[0031] Preferably,
[0032] The numbering of the three original vertices and the numbering of the three intersection points are arranged in a preset order to obtain a PTS array including:
[0033] The preset order of the elements in the PTS array is vertex PT1, intersection point PT12, vertex PT2, intersection point PT23, vertex PT3, intersection point PT31.
[0034] According to a second aspect of an embodiment of the present invention, a device for quickly cutting triangles based on intersections is provided, the device comprising:
[0035] Numbering module: used to number the three original vertices of the triangle according to the original winding direction; and number the possible intersection points between the straight line and the triangle;
[0036] Attribute acquisition module: used to acquire the attributes of the three original vertices of the triangle, and acquire the attributes of the three intersection points respectively according to the distance and attributes of any intersection point from the two original vertices on the same straight line;
[0037] A PTS array acquisition module: used for arranging the numbers of the three original vertices and the numbers of the three intersection points in a preset order to obtain a PTS array;
[0038] Empty intersection removal module: used to remove the intersections with empty attributes in the PTS array while maintaining the order of the elements in the PTS array;
[0039] The first judgment module is used to judge whether the number of remaining elements in the PTS array is three. If it is three, the points in the PTS array are directly combined into a triangle, and the obtained triangle and the attributes of the corresponding vertices are saved in the cut triangle array, triggering the end of the process;
[0040] The second judgment module is used for judging whether the second element and the last element in the PTS array are both original vertices if the number is not three; if so, moving the first element in the PTS array to the end of the PTS array; if not, keeping the order of the elements in the PTS array unchanged;
[0041] Extraction module: used for combining the last element, the first element and the second element in the PTS array into a triangle, and saving the obtained triangle and the attributes of the corresponding vertices in the cut triangle array;
[0042] Loop module: used to delete the first element in the PTS array and repeat the above triangle extraction process until the end of the process is triggered.
[0043] According to a third aspect of an embodiment of the present invention, there is provided a storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a main controller, each step in the above method is implemented.
[0044] The technical solution provided by the embodiments of the present invention may have the following beneficial effects:
[0045] The present application constructs the cut triangle by numbering the three original vertices of the triangle according to the original winding direction; numbering the possible intersections between the straight line and the triangle, sorting the vertices and intersections according to a preset order, then removing the empty intersections, and extracting the remaining intersections and vertices in a characteristic order; the present application performs simple and fast calculations by intersecting line segments with line segments in two dimensions and line segments with faces in three dimensions; obtaining the attributes of the three original vertices of the triangle, and respectively obtaining the attributes of the three intersections according to the distance and attributes of any intersection from the two original vertices on the same straight line; processing the newly generated triangle through an interpolation algorithm, calculating related attributes, and ensuring the correctness of the attributes.
[0046] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0048] Figure 1 is a schematic flow chart of a method for quickly cutting triangles based on intersections according to an exemplary embodiment;
[0049] Figure 2is a schematic diagram showing a possible situation where a straight line cuts a triangle according to another exemplary embodiment;
[0050] Figure 3 is a system schematic diagram of a device for quickly cutting triangles based on intersections according to another exemplary embodiment;
[0051] In the attached figure: 1-numbering module, 2-attribute acquisition module, 3-PTS array acquisition module, 4-empty intersection removal module, 5-first judgment module, 6-second judgment module, 7-extraction module, 8-loop module. DETAILED DESCRIPTION
[0052] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of devices and methods consistent with some aspects of the present invention as detailed in the appended claims.
[0053] Embodiment 1
[0054] Figure 1 is a flowchart of a method for fast cutting triangles based on intersections according to an exemplary embodiment. Figure 1 As shown, the method includes:
[0055] S1, numbering the three original vertices of the triangle according to the original winding direction; and numbering the possible intersection points between the straight line and the triangle;
[0056] S2, obtaining the attributes of the three original vertices of the triangle, and obtaining the attributes of the three intersection points respectively according to the distance and attributes of any intersection point from the two original vertices on the same straight line;
[0057] S3, arranging the numbers of the three original vertices and the numbers of the three intersection points in a preset order to obtain a PTS array;
[0058] S4, removing the intersection points with empty attributes in the PTS array while maintaining the order of the elements in the PTS array;
[0059] S5, determining whether the number of remaining elements in the PTS array is three, if so, directly forming a triangle from the points in the PTS array, and saving the obtained triangle and the attributes of the corresponding vertices in the cut triangle array, triggering the end of the process;
[0060] S6, if not three, determine whether the second element and the last element in the PTS array are both original vertices; if so, move the first element in the PTS array to the end of the PTS array; if not, keep the order of the elements in the PTS array unchanged;
[0061] S7, forming a triangle by combining the last element, the first element and the second element in the PTS array, and saving the obtained triangle and the attributes of the corresponding vertices in the cut triangle array;
[0062] S8, deleting the first element in the PTS array, and repeating the above triangle extraction process until the end of the process is triggered;
[0063] It is understandable that, depending on the actual situation, there may be situations where a straight line cuts a triangle, as shown in the following figure. Figure 2 As shown, according to the original winding direction of the triangle, the three original vertices of the triangle are numbered PT1, PT2, and PT3. Figure 2 In the situation shown, there are three possible intersections between the three sides of the triangle and the straight line, namely, the straight line intersects with any two sides of the triangle, and the points where the straight line and the triangle may intersect are numbered, the intersection of the straight line with the side composed of PT1 and PT2 is numbered PT12, the intersection of the straight line with the side composed of PT2 and PT3 is numbered PT23, and the intersection of the straight line with the side composed of PT3 and PT1 is numbered PT31; depending on whether the straight line cuts the triangle, these intersections either exist at any two or not; when calculating the intersection, linear interpolation is performed based on the distance between the intersection and the two related vertices, and the attributes related to the intersection are also calculated. For example, if the vertex has an attribute (texture coordinate or color) w, the attribute value of PT1 is w1, the attribute value of PT2 is w2, and the attribute value of the intersection PT12 is w 12 , then w 12 The calculation formula is:
[0064] w 12 =(PT12.distance(PT2)) / (PT2.distance(PT1)*w1+(PT12.distance(PT1))
[0065] / (PT2.distance(PT1)*w2
[0066] Wherein, PT12.distance(PT2) represents the distance from the intersection point PT12 to the original vertex PT2, (PT2.distance(PT1) represents the distance from the original vertex PT2 to the original vertex PT1, (PT12.distance(PT1) represents the distance from the intersection point PT12 to the original vertex PT1, w1 represents the texture coordinates or color of the original vertex PT1, and w2 represents the texture coordinates or color of the original vertex PT2; it is worth noting that if the attribute is color, the RGB three-channel values of the intersection need to be calculated separately. When calculating the RGB three-channel values of the intersection separately, the RGB three-channel values of the original vertex PT1 and the original vertex PT2 are also substituted into the formula respectively;
[0067] The points calculated in the previous step are organized into an array in the following order: PT1, PT12, PT2, PT23, PT3, PT31. This array is called PTS. On the premise of maintaining the order, remove the points that do not exist in PTS. As mentioned above, there will only be two intersection points when a straight line cuts a triangle, so there will only be two of the three intersection points. For the existing intersection points, there must be a distance relationship between them and the two original vertices on the same straight line, so the attributes will not be empty. Therefore, there are at least 3 points in the PTS array, that is, there is no straight line cutting the triangle, and at most 5 points, that is, there is a straight line cutting the triangle;
[0068] According to the array PTS composed of vertices and intersection points generated in the previous step, the triangles are re-divided as follows:
[0069] If the number of elements in the PTS array is three, it means that there is no straight line to split the triangle. The points in the PTS array are directly combined into a triangle, and the attributes of the vertices corresponding to the triangle are saved in the cut triangle array, and the algorithm ends.
[0070] If the number of PTS array elements is not three, indicating that there is a straight line cutting the triangle, then check the second point and the last point in the PTS array. If they are both original vertices, modify the order of the PTS array elements, take the first point in the PTS array out of the array, and put it at the end of the PTS array elements. If the second point and the last point are both original vertices, then the triangle generated in the next step will degenerate into a line segment. This step is to avoid this situation. Then, the last point, the first point, and the second point of the PTS array are combined into a triangle and placed in the cut triangle array. The above has ensured that the triangle composed of the last point, the first point, and the second point is not an edge of the original triangle and can be used directly as a normal triangle. If any of the second point and the last point is not an original vertex, directly combine the last point, the first point, and the second point of the PTS array into a triangle and place it in the cut triangle array.
[0071] Delete the first point in the PTS array, and then re-execute the above steps. After taking out the triangle formed by the last point, the first point and the second point, the first point is no longer related to the triangle. Refer to the Ear Clipping Method when triangulating polygons, and you can directly delete the first point.
[0072] Embodiment 2
[0073] Figure 3 is a system schematic diagram showing a device for quickly cutting triangles based on intersections according to another exemplary embodiment, the device comprising:
[0074] Numbering module 1: used to number the three original vertices of the triangle according to the original winding direction; and number the possible intersection points between the straight line and the triangle;
[0075] Attribute acquisition module 2: used to acquire the attributes of the three original vertices of the triangle, and acquire the attributes of the three intersection points respectively according to the distance and attributes of any intersection point from the two original vertices on the same straight line;
[0076] PTS array acquisition module 3: used to arrange the numbers of the three original vertices and the numbers of the three intersection points in a preset order to obtain a PTS array;
[0077] Empty intersection removal module 4: used to remove the intersections with empty attributes in the PTS array while maintaining the order of the elements in the PTS array;
[0078] The first judgment module 5 is used to judge whether the number of remaining elements in the PTS array is three. If it is three, the points in the PTS array are directly combined into a triangle, and the obtained triangle and the attributes of the corresponding vertices are saved in the cut triangle array, triggering the end of the process;
[0079] The second judgment module 6 is used for judging whether the second element and the last element in the PTS array are both original vertices if the number is not three; if so, moving the first element in the PTS array to the end of the PTS array; if not, keeping the order of the elements in the PTS array unchanged;
[0080] Extraction module 7: used for combining the last element, the first element and the second element in the PTS array into a triangle, and saving the obtained triangle and the attributes of the corresponding vertices in the cut triangle array;
[0081] Loop module 8: used to delete the first element in the PTS array and repeat the above triangle extraction process until the end of the process is triggered.
[0082] Embodiment three:
[0083] This embodiment provides a storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a main controller, each step in the above method is implemented;
[0084] It is understandable that the storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.
[0085] It can be understood that the same or similar parts of the above embodiments can be referenced to each other, and the contents not described in detail in some embodiments can refer to the same or similar contents in other embodiments.
[0086] It should be noted that, in the description of the present invention, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present invention, unless otherwise specified, the meaning of "plurality" refers to at least two.
[0087] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present invention belong.
[0088] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0089] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0090] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0091] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.
[0092] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0093] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A method for quickly cutting triangles based on intersection points, characterized in that: The method comprises: The triangle is wound in the original direction, and the three original vertices of the triangle are numbered; possible intersection points between the straight line and the triangle are numbered; Obtaining the attributes of the three original vertices of the triangle, and obtaining the attributes of the three intersection points respectively according to the distance and attributes of any intersection point from the two original vertices on the same straight line; Arrange the numbers of the three original vertices and the numbers of the three intersection points in a preset order to obtain a PTS array; While maintaining the order of each element of the PTS array, removing the intersection points whose attributes are empty in the PTS array; Determine whether the number of remaining elements in the PTS array is three. If it is three, directly form a triangle with the points in the PTS array, save the obtained triangle and the attributes of the corresponding vertices in the cut triangle array, and trigger the end process; If not, determine whether the second element and the last element in the PTS array are both original vertices; if so, move the first element in the PTS array to the end of the PTS array; if not, keep the order of the elements in the PTS array unchanged; The last element, the first element and the second element in the PTS array form a triangle, and the obtained triangle and the attributes of the corresponding vertices are saved in the cut triangle array; Delete the first element in the PTS array and repeat the above triangle extraction process until the end of the process is triggered.
2. The method according to claim 1, characterized in that The numbering of the three original vertices of the triangle comprises: The three original vertices of the triangle are numbered as vertex PT1, vertex PT2 and vertex PT3 according to the original winding direction; The numbering of possible intersection points between the straight line and the triangle comprises: The intersection point of the straight line and the edge formed by vertices PT1 and PT2 is numbered as intersection point PT12, the intersection point of the straight line and the edge formed by vertices PT2 and PT3 is numbered as intersection point PT23, and the intersection point of the straight line and the edge formed by vertices PT3 and PT1 is numbered as intersection point PT31.
3. The method according to claim 2, characterized in that The attributes include: texture coordinates or color.
4. The method according to claim 3, characterized in that The method of obtaining the properties of the three intersection points according to the distance and properties of any intersection point from the two original vertices on the same straight line includes: Get the distance from the intersection point to the two original vertices on the same straight line, and get the distance between the two original vertices; The texture coordinates or colors of the intersection point are obtained according to the distances from the intersection point to two original vertices on the same straight line, the distance between the two original vertices, and the texture coordinates or colors of the two original vertices.
5. The method according to claim 4, characterized in that If the attribute is color, then obtain the RGB channel values of the three original vertices respectively; When obtaining the color of any intersection point, the R channel value of the intersection point is obtained according to the distance from the intersection point to the two original vertices on the same straight line, the distance between the two original vertices, and the R channel values of the two original vertices; Obtain the G channel value of the intersection point according to the distances from the intersection point to the two original vertices on the same straight line, the distance between the two original vertices, and the G channel values of the two original vertices; Obtain the B channel value of the intersection point according to the distances from the intersection point to the two original vertices on the same straight line, the distance between the two original vertices, and the B channel values of the two original vertices; The color of the intersection point is obtained according to the R channel value, G channel value, and B channel value of the intersection point.
6. The method according to claim 2, characterized in that The numbering of the three original vertices and the numbering of the three intersection points are arranged in a preset order to obtain a PTS array including: The preset order of the elements in the PTS array is vertex PT1, intersection point PT12, vertex PT2, intersection point PT23, vertex PT3, intersection point PT31.
7. A device for quickly cutting triangles based on intersection points, characterized in that: The device comprises: Numbering module: used to number the three original vertices of the triangle according to the original winding direction; and number the possible intersection points between the straight line and the triangle; Attribute acquisition module: used to acquire the attributes of the three original vertices of the triangle, and acquire the attributes of the three intersection points respectively according to the distance and attributes of any intersection point from the two original vertices on the same straight line; A PTS array acquisition module: used for arranging the numbers of the three original vertices and the numbers of the three intersection points in a preset order to obtain a PTS array; Empty intersection removal module: used to remove the intersections with empty attributes in the PTS array while maintaining the order of the elements in the PTS array; The first judgment module is used to judge whether the number of remaining elements in the PTS array is three. If it is three, the points in the PTS array are directly combined into a triangle, and the obtained triangle and the attributes of the corresponding vertices are saved in the cut triangle array, triggering the end of the process; The second judgment module is used for judging whether the second element and the last element in the PTS array are both original vertices if the number is not three; if so, moving the first element in the PTS array to the end of the PTS array; if not, keeping the order of the elements in the PTS array unchanged; Extraction module: used for combining the last element, the first element and the second element in the PTS array into a triangle, and saving the obtained triangle and the attributes of the corresponding vertices in the cut triangle array; Loop module: used to delete the first element in the PTS array and repeat the above triangle extraction process until the end of the process is triggered.
8. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the main controller, the steps of the method for fast cutting triangles based on intersection points as described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Cutting method based on integrated three-dimensional GIS model
CN103413297A
Rapid section contour generation method suitable for a triangular mesh model
CN109872396A
Cutting method and system for cutting triangulation network using polyhedral
CN111833452A
Three-dimensional model cutting method and device, computer equipment and storage medium
CN113724401A
Mine three-dimensional geological modeling and layered cutting method
CN117173357A