Clipper Library Union Function Error - clipperlib

I am trying to perform "Union" of two polygons in Clipper Library. The problem is there is a 2mm gap between the two closest egdes of the two polygons. So the result is still two polygons. Is there a way to remove gap between polygons if it is less than, say, 5mm?
Thanks in advance.

Before performing Union, I offsetted all the polygons by 5 and then again by -5. After this, the Union function worked correctly, even for polygons with gaps between them. I got what I needed, but does anyone know the reason for this?

Related

Polygon searching

Which of these (k-d tree, r-tree) would be suitable for searching and indexing polygon.
My usecase is that i have been given some lat-long points (min 3 for a valid polygon) and from these points i need to find the polygon which is the smallest one.
By smallest i mean that if there is a polygon inside another polygon, then the inside polygon should be returned.
And if polygon overlap, they should not be chosen.
I think finding the location and then the area might be tried but i am not sure.
I would also like get some idea about which data structure would be useful. I think postgis uses R-tree indexing.
R-tree is good for polygons, because it works on bounding boxes, including all the points for a particular polygon. You can easily find candidate polygons and then do a fine-grain check for overlap, area, etc.
Kd-tree works on points, so polygons would be hard to index.
R-tree also supports adding and removing data items. As I recall a kd-tree, once built, is hard to update for new or changing data.

Calculate whether two hexahedrons intersects or not

Can i easily calculate this programmatically?
I can calculate it easily when the two hexahedrons are convex,
but them can be concave.
Is there just an only way to calculate intersections of the line segments and half planes?
Because you write about "intersections of line segments", I assume that you are asking about hexagons, not hexahedrons:
You should use the same method as for general polygons, so basically check for segment intersections. The naive implementation is O(n*n) but in your case with fixed n=6 this might not even be an issue.
You probably also want to check if one of the hexagons is completely inside the other one. If you already found out that there is no intersection, you just have to check if one point of the polygon is inside the other one. Again, you should use the method for general polygons.

How do I check if a set of plane polygones create a watertight polyhedra

I am currently wondering if there is a common algorithm to check whether a set of plane polygones, not nescessarily triangles, contruct a watertight polyhedra. Each polygon has an oriantation (normal vector). A simple solution would just be to say yes or no. A more advanced version would be to point out the edges, where the polyhedron is "open". I am not really interesed on how to close to polyhedra.
I would like to point out, that my "holes" are not nescessarily small, e.g., one face of a cube might be missing. Thus, the "undersampling correction" algorithms dont seem to be the correct approach. Furthermore, I am talking of about 100 - 1000, not 1000000 polygons, so computation time should not really be a problem.
Any hints or tips?
kind regards,
curator
I believe you can use a simple topological test -- count the number of times each edge appears in the full list of polygons.
If the set of polygons define the surface of a closed volume, each edge should have count>=2, indicating that each edge is shared by (at least) two adjacent polygons. If the surface is manifold count==2 exactly.
Edges with count==1 indicate open regions of the surface.
The above answer does not cover many cases. A more correct (but not necessarily complete: I wouldn't know) algorithm is to ensure that every edge of every polygon (or of the mesh/polyhedron) has an even number of faces connected to it. Consider the following mesh:
The segment (line) between the closest vertex and the one below is attached to 3 faces (one one of the outer triangle and two of the inner triangle), which is greater than two faces. However this is clearly not closed.

What's the opposite of tesselation?

From what I understand, taking a polygon and breaking it up into composite triangles is called "tesselation". What's the opposite process called and can anyone link me to an algorithm for it?
Essentially, I have a list of 2D triangles and I need an algorithm to recombine them into a polygon.
Thanks!
I think you need to transform your triangles as a half edge data structure, and then you should be able to easily find the half edges which have no opposite.
It's called mesh decimation. Here is some code I wrote to do this for a class. Tibur is correct that the half edge data structure makes this much more efficient.
http://www.cs.virginia.edu/~mjh7v/advgfx/proj1/
The thing that you are calling tessellation is actually called triangulation. The thing you are searching for is tessellation (you may have heard of it referred to as tiling).
If you are more specific about the problem you are trying to solve (e.g. do you know the shape of the final polygon?) I can try to recommend some more specific algorithms.

Sorting polygons for correct alpha blending in DirectX 9?

What is the correct way to sort polygons so that they blend properly? The basic concept I think is to render the furthest polygon first back to closest in order. But what about cases of intersecting polygons?
What is the correct way to sort
polygons so that they blend properly?
Sort them back to front.
But what about cases of intersecting polygons?
Simply ... don't do it. If you have no choice then you will have to split the polygons along their intersection as you go.
Edit: Its worth bearing in mind that finding the intersections and splitting will be very slow. You could use some sort of acceleration structure to aid you.
Its quite common to use a BSP to sort and split static transparent polys.
Frankly I would go for depth peeling and compositing passes. I have seen some implementation of this algorithm and most of the time peeling 2 or 3 layers is "good enough".
This will also save you from having to managed different data structures for storing your meshes. One drawback is that it can be a bit performance intensive, for example if you have a lot of transparent meshes.

Resources