Find a point in a complex polygon - opengl

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

Related

Find closest point from point outside polygon mesh to polygon mesh

I have a polygon mesh defining a valid inner region and a point outside of this polygon mesh. From this point i want to find the closest point on the surface on my polygon mesh.
I have no background in computational geometry and don't know the buzzwords. How can i achieve this using cgal or any other library in C++?
You might have a look at the Location Functions in CGAL.

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.

How should I send a Polygon with a hole for the Winding number Point in Polygon test?

I want to check if a point is in the Polygon (which can have a hole/holes within it). Right now a polygon with a hole is represented as multiple polygons when the hole and the outside polygon doesn't have a common vertex. Under these circumstances how should the points of the polygon be send to the function (found at the bottom) ?.
Would sending an array of points be valid?
The point is inside the polygon if and only if it is inside the outer perimeter of the polygon and outside the hole.
If you are not told which polygon is which, it doesn't matter; the point is inside the complex polygon iff it is inside exactly one of the two.

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.

Sorting of vertices after intersection of 3d isosurface with plane

Here is another geometric problem:
I have created an 3-dimensional triangulated iso-surface of a point cloud using the marching cubes algorithm. Then I intersect this iso-surface with a plane and get a number of line segments that represent the contour lines of the intersection.
Is there any possibility to sort the vertices of these line segments clockwise so that I can draw them as a closed path and do a flood fill?
Thanks in advance!
It depends on how complex your isosurface is, but the simplest thing I can think of that might work is:
For each point, project to the plane. This will give you a set of points in 2d.
Make sure these are centered, via a translation to the centroid or center of the bounding box.
For each 2d point, run atan2 and get an angle. atan2 just puts things in the correct quadrant.
Order by that angle
If your isosurface/plane is monotonically increasing in angle around the centroid, then this will work fine. If not, then you might need to find the 2 nearest neighbors to each point in the plane, and hope that that makes a simple loop. In face, the simple loop idea might be simpler, because you don't need to project and you don't need to compute angles - just do everything in 3d.