What algorithm's can be used to fill an irregular 3D object? - algorithm

I have an irregular polygon in 3D, and have coordinates of points present on the boundary of the polygon. Assume that I have placed cubes of some size on all such points present on the boundary. With the help of these cubes I can search for all 3D objects which intersect with my polygon. Now in order search for all objects which are either inside or outside my polygon I need to populate the 3D polygon with such cubes.
Can anyone help on how can I fill in my 3D polygon with all such cubes.

You dont need to fill the polyhedron (this is the name of a 3d polygon), instead you could calculate its hull, which might be a Convex Hull or concave hull depending on your intent.

Related

Algorithm for 3D polygonal chain intersection

I have two 3D polygonal chains and I want to know if they intersect or not. This problem is known as the Polygonal Chain Intersection. Good algorithms exists for the 2D case, but I have not seen any for the 3D case
Anybody can help with this?
Ok, maybe this is a stupid algorithm, but why don't you pick some plane (in general position, or one of the coordinate planes), project orthogonally the two 3D chains onto the plane and solve the 2D problem using one of these efficient algorithms, which will allow you to locate all points of intersection between the projections and all pairs of segments from the two 3D chains, whose projections intersect at the intersection points. Then from each intersection 2D point, draw the line through that point, perpendicular to the plane and check where this line intersects each of the two 3D segments, one from the first 3D chain, the other from the second, whose projections intersect at the 2D intersection point. If the resulting points are different, the 2D projected intersection point is not a true 3D intersection point. Else, you get an intersection point for the 3D chains.

Create a 3D polyhedron from 2D convex polygon in bullet physics

I have a convex polygon in Oxy plane (defined by some vertices and edges). I would like to create a 3D polyhedron from extruding this polygon in z axis for some distance h. How can I do this in bullet physics?
Thank you for your time.
The extrusion is simple to do by hand. For each vertex in the polygon you duplicate it, and set the Z value to the distance h. Then you can create a btConvexHullShape from the points in the set. Since it's a convex hull and not a triangle mesh you don't need to worry about the face information. If you look at the btConvexHullShape constructor you'll notice it only takes a list of points as the parameter.

Voxelize a Polygon Mesh

I've implemented Marching Cube and Marching Tetrahedron algorithms to convert a voxel grid into a polygon mesh. Now I'm interested in doing the opposite, taking a polygon mesh and approximating it in a voxel grid.
I'm currently just working out my approach and curious if anyone has any guidelines. I can find the list of triangles that intersect any voxel cube fairly easily, but how do you convert the triangles into values held by the voxel vertices?
Steps
Determine which cubes are inside, outside, and on the border. Border is easy to determine, since if the a cube contains any triangles it is on the border.
From there I imagine I need to follow the triangle normals and project along the voxel grid to determine inside/outside. Mark all vertices that are completely surrounded by inside as 1 and all surrounded by outside as -1.
?? This is the part i'm confused about. I need to take the triangles and somehow interpolate their values into vertex values. My guess is I need to find all points of the triangle that collide with the AABB of the voxel subunit or inside it and project it onto all subunit axes. From there I need to take those accumulated positions and figure out what the values should be based by setting the values between [-1,1] such that interpolation would most closely approximate the hull within the boundary unit. <--- this part is what i don't 100% understand.
If I understand correctly, the values you should associate to the voxel corners are signed distances to the surface (positive outside, negative inside), so that the surface itself is at level zero.
If a voxel is cut by a single triangle, you can just assign the distance to the plane of the triangle. If there are several triangles that cross, the situation is more complex. You might consider the orthogonal projections of the corners onto the triangles and see to which triangle they belong.

rendering n-point polygon with face in 3D

Newbie to three.js. I have multiple n-sided polygons to be displayed as faces (I want the polygon face to be opaque). Each polygon is facing a different direction in 3D space (essentially theses faces are part of some building).
Here are a couple of methods I tried, but they do not fit the bill:
Used Geometry object and added the n-vertices and used line mesh. It created the polygon as a hollow polygon. As my number of points are not just 3 or 4, I could not use the Face3 or Face4 object. Essentially a Face-n object.
I looked at the WebGL geometric shapes example. The shape object works in 2D and extrusion. All the objects in the example are on one plane. While my requirement is each polygon has a different 3D normal vector. Should I use 2D shape and also take note of the face normal and rotate the 2D shape after rendering.
Or is there a better way to render multiple 3D flat polygons with opaque faces with just x, y, z vertices.
As long as your polygons are convex you can still use the Face3 object. If you take one n-sided polygon, lets say a hexagon, you can create Face3 polygons by taking vertices numbered (0,1,2) as one face, vertices (0,2,3) as another face, vertices (0,3,4) as other face and vertices (0,4,5) as last face. I think you can get the idea if you draw it on paper. But this works only for convex polygons.

Merge overlapping triangles into a polygon

I've got a bunch of overlapping triangles from a 3D model projected into a 2D plane. I need to merge each island of touching triangles into a closed, non-convex polygon.
The resultant polygons shouldn't have any holes in them (since the source data doesn't).
Many of the source triangles share (floating point identical) edges with other triangles in the source data.
What's the easiest way to do this? Performance isn't particularly important, since this will be done at design time.
Try gpc, or the General Polygon Clipper Library.
Imagine the projection onto a plane as a "view" of the model (i.e. the direction of projection is the line of sight, and the projection is what you see). In that case, the borders of the polygons you want to compute correspond to the silhouette of the model.
The silhouette, in turn, is a set of edges in the model. For each edge in the silhouette, the adjacent faces will have normals that either point away from the plane or toward the plane. You can check this be taking the dot product of the face normal with the plane normal -- look for edges whose adjacent face normals have dot products of opposite signs with the projection direction.
Once you have found all the silhouette edges you can join them together into the boundaries of the desired polygons.
Generally, you can find more about silhouette detection and extraction by googling terms like mesh silouette finding detection. Maybe a good place to start is here.
I've also found this[1] approach, which I will be trying next.
[1] 2d outline algorithm for projected 3D mesh

Resources