You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The C codes in this repository are extracted and extended from one Computer Aided Engineering (CAE) project. The main goal is to get intersections or unions of two 3D convex polygons. The codes emphasize the implementation of a general algorithm for Boolean operations of polygons, in which the intersection and inner points are used to construct new polygon for each Boolean operation. This algorithm is similar to the widely known Sutherland-Hodgman algorithm for convex polygon clipping, and implement general idea for both intersection and merge operations.
4
+
The C codes in this repository are extracted and extended from one Computer Aided Engineering (CAE) project. The main goal is to get intersections or unions of two 3D convex polygons. The codes emphasize the implementation of a general algorithm for Boolean operations of polygons, in which the intersection and inner points are used to construct new polygon for each Boolean operation. This algorithm is similar to the widely known Sutherland-Hodgman algorithm for convex polygon clipping, and implements general idea for both intersection and merge operations.
5
5
6
6
Data structure
7
7
8
-
The data structure for polygons is just array in built-in floating number which represents ordered points set in 3D space. The order of points set in the first (poly1) and second (poly2) polygon should be identical (both clockwise or both counterclockwise if viewing along a certain direction). Obviously the polygons should be planar (or approximately planar based on geometric tolerance) for valid Boolean operations. The reason why the polygons are 3D is that the application scenarios in CAE is always three dimensional and some approximate cases should be treated. Because the focus of functions in the codes is on Boolean operations of two polygons, no extra tree-like data structure is introduced to improve the efficiency of geometric calculation, which is commonly used in Boolean operations of polygons (graphs) in large amount. The application in CAE shows the codes are efficient if the number of points and Boolean operations are not larger than 1M.
8
+
The data structure for polygons is just array in built-in floating number which represents ordered points set in 3D space. The order of points set in the first (poly1) and second (poly2) polygon should be identical (both clockwise or both counterclockwise if viewing along a certain direction). Obviously the polygons should be planar (or approximately planar based on geometric tolerance) for valid Boolean operations. The reason why the polygons are 3D is that the application scenarios in CAE are always three dimensional and some approximate cases should be treated. Because the focus of functions in the codes is on Boolean operations of two polygons, no extra tree-like data structure is introduced to improve the efficiency of geometric operations, which is commonly used in Boolean operations of polygons (graphs) in large amount. The application in CAE shows the codes are efficient if the number of points and Boolean operations are not larger than 1M.
9
9
10
10
Algorithm
11
11
@@ -17,10 +17,18 @@ There is a Makefile in this repository, just type
17
17
18
18
make
19
19
20
-
in a Unix-like OS environment in which gcc has been deployed, then a shared library named "libpolyboolean.so" and an exec named "polyop" will be generated. You can also use the script in file cclib2exe to build this programme.
20
+
in a Unix-like OS environment in which gcc has been deployed, then a shared library named "libpolyboolean.so" and an exec named "polyop" will be generated. You can also use the script in file cclib2exe to build this programme.
21
21
22
22
The codes in source file main.c represent some examples which call Boolean operation functions in source file convex_poly_boolean.c. The examples include
23
23
1. intersection and union sets of two moving triangles.
24
24
2. intersection and union sets between one static hexagon and one moving square.
25
25
26
-
Note that enough memory should be allocated for result polygon after Boolean operations. There are comments in source file convex_poly_boolean.c, which describe each geometric function. The functions in section of basic geometry calculation are low-level and can be used for other target of computational geometry.
26
+
There is a golden file output_golden which records all the ouputs of examples, after running exec file like
27
+
28
+
bin/polyop > output
29
+
30
+
the accuracy of the codes can be monitored using the command
31
+
32
+
diff output output_golden
33
+
34
+
Note that enough memory should be allocated for result polygons after Boolean operations. There are comments in source file convex_poly_boolean.c, which describe each Boolean operation and helper function. The functions in geometry3d_basic.c belong to low-level geometric operations and can be used for other targets of computational geometry.
0 commit comments