Test if a 3D Point is with an extruded "2.5D" Polygon - c++

I need to check if a point given as x,y,z coordinates is within an extruded 2.5D Polygon. I thought it should be possible to achieve using a 2D point-in-polygon check (e.g. [1]) with additional distance checks.
I'd like to avoid creating meshes for the polygon for performance reasons. Is it possible?
[1] How can I determine whether a 2D Point is within a Polygon?

Related

Generate the faces of a 3D object given its points and edges

I have a 3D wire-frame consisting of 3D points and edges. How do I go about identifying sets of vertices forming a face of the 3D object?
I am using QT and want to render a 3D object given its point set and edge set. The best I have been able to do is given three points forming a triangular face, I am able to render it in 3D. But how to do the same given more points and edges? Or, alternatively, how to break down the set in sets of 3 points forming a triangular face?
Just take your first edge and its vertices (V1 and V2).
Find all edges that use V2 - their second vertices are your potential V3's.
For each potential V3 check if you have edge V1-V3 - if so, then you've found a triangle V1-V2-V3. For most meshes you should have one or two such triangles. When you're adding a new triangle always check if wasn't found already.
Do the same for edges that use V1.
Take next edge and repeat.
Depending on your exact data, edge directions, etc. it may need slight modifications but you should get the point.

Preforming geometry on a plane

In my current c++ program I am dealing with a plane that is intersected by several other planes. I want to find the polygon formed by the lines that define the intersections of the planes. For simplicity and computation speed, it seems like my best bet is to get the lines that form the intersections and then work out the polygon in 2d on the surface of the plane. Does anyone have an idea how to translate the lines(represented by a position and a direction vector) onto the plane and the final polygon back into 3d?
In general, this isn't possible to do. The simplest counterexample is the intersection of two planes where the two centers overlap. Viewing it edge-on, it would look like a plus sign. There is no polygon that results from this intersection; a line segment, yes, but no polygon. If you want to draw the resulting polygon, then it needs to be convex, as well which puts more constraints on the allowable intersection configurations.

Normal of point via its location on STL mesh model

Can someone tell me the best way to estimate the normal at a point on CAD STL geometry?
This is not exactly a question on code, but rather about efficiency and approach.
I have used an approach in which I compare the point whose normal needs to be estimated with all the triangles in the mesh and check to see if it lies inside the triangle using the barycentric coordinates test. (If the value of each barycentric coordinate lies between 0 and 1, the point lies inside.) This post explains it
https://math.stackexchange.com/questions/4322/check-whether-a-point-is-within-a-3d-triangle
Then I compute the normal of that triangle to get the point normal.
The problem with my approach is that, if I have some 1000 points, and if the mesh has say, 500 triangles, that would mean doing some 500X1000 checks. This takes a lot of time.
Is there an efficient data structure or approach I could use, to pinpoint the right triangle? Or a library that could get the work done?
A relatively easy solution is by using a grid: decompose the space in a 3D array of voxels, and for every voxel keep a list of the triangles that interfere with it.
By interfere, I mean that there is a nonempty intersection between the voxel and the bounding box of the triangle. (When you know the bounding box, it is straight forward to tell what voxels it covers.)
When you want to test a point, find the voxel it belongs to and compare to the list of triangles. You will achieve a speedup equal to N/M, where M is the average number of triangles per voxel.
The voxel size should be chosen carefully. Too small will result in a too big data structure; too large will make the method ineffective. If possible, adjust to "a few" triangles per voxel. (Use the average triangle size - square root of double area - as a starting value.)
For better efficiency, you can compute the exact intersections between the triangles and the voxels, using a 3D polygon clipping algorithm (rather than a mere bounding box test), but this is more complex to implement.

Determine if a point is interior or exterior to a 3D Alpha-shapes surface in CGAL

I am using CGAL to create the concave hull of a set of 3D points using ex_alpha_shapes_3 example. Next, I would like to find out whether a point query in space is located within the surface created by the triangular concave hull faces (the output of ex_alpha_shapes_3 code) or not. A "point in polygon" technique should be useful for this purpose. I would appreciate it if anyone could help me with this problem.
You can use the locate function and depending on the simplex the point fall on and the output of the function classify of the simplex you'll directly know if you're inside, outside or on the boundary.
whatever simplex type, EXTERIOR is exterior, INTERIOR is interior.
If the point falls on an edge, REGULAR is on the boundary and SINGULAR depends whether what an isolated edge should be in your setting
If the points fall on a vertex, REGULAR is on the boundary and SINGULAR is depends whether an isolated input point should be in your setting
I don't know about CGAL, but there are a few heuristics you can use given that your polyhedron is known to be convex. You can do a lot of the work in essentially 2D. You can use any axes, but let's assume we are working in the XY plane and momentarily ignoring the Z component. Since your shape is convex, there will generally only be two triangles whose XY coordinates surround the XY coordinates of your point. For any triangle, you can quickly determine if x[min] < x[point] < x[max] and likewise for y. If those tests fail, move on. If they succeed, a little further testing is needed to determine whether the point is actually inside the triangle. Once you have located 2 acceptable triangles, find the Z value for each triangle at the point's (X,Y). If the point's Z is between the Z values for the faces, then the point is inside the solid.

Find a point in a complex polygon

This polygon could be shaped like a C
I tried the formula located here
How can I determine whether a 2D Point is within a Polygon?
however it doesn't actually correctly predict if the point is in the polygon.
Easiest way - especially for lots of points is to triangulate the polygon then do a point in triangle test.
You could convert the polygon into a set of convex polygons but that is trickier.
See also Random points inside a 4-sided Polygon