How to find a polygon which a single point lies on - polygon

I have a list of polygons and a single point with its latitude and longitude. I want to find a polygon which the single point lies on.
Currently, I'm iterating over the whole list to find the answer, which seems a bit inefficient. Is there a better way to make it?

Not unless you have some prior information about this list. If you are given a list with no prior knowledge of its elements, you must check every item in the list to see if it meets the condition.

Related

how to determine OpenGL winding based on normals?

I am trying to understand how to manually generate objects.
I have a mesh, part of which I delete and create a new geometry in its place. I have information about the normals of deleted vertices. On the basis of which I have to build new faces (in a different size and quantity) looking in the same direction.
But I don’t understand how to choose the correct winding. It sounds easy when the lessons talk about CCW winding in screen space. But what if I have a bunch of almost chaotic points in the model space? How then to determine this CCW, which axis is used for this? I suggest that the nearest old normals might help. But what is the cheapest method to determine the correct order?
It turned out to be easier than I thought. It is necessary to find the cross product of the first two vectors from the vertices of a triangle, then find the dot of the resulting vector and the normal vector, if the result is negative, then during generation it is necessary to change the order of vertices.

Finding nearest element to a point STL format

A short introduction:
I have a body that is expressed by the outer-surface, given in STL form (set of triangular elements and their outside-pointing normal vector).
I'm trying to detect if a point given by coordinates is inside or outside the body.
The problem:
How do I find the nearest element to a given point?
More specifically, say you have found the nearest vertex to the point and this vertex is shared by two (or more) elements. Which is is the "nearest" one?
Note that the end result is determining if the point is inside or outside the body. A simple normal distance (dot product with the normal) does not solve the problem and can lead to ambiguous result based on which of the elements, sharing the node is selected.
Using the centroid of the element is also problematic.
Any suggestions, ideas (especially from people who have been involved in this issue before) are most welcomed!
EDIT:
I'll make the issue slightly harder. Say there's an open surface (but it covers the whole domain so that every point is on one of two sides of the surface, either in or out, based on the direction relative to the normal.
This also needs to be answered using the same approach.
EDIT2:
Answer was found!
Hope this helps!
The problem was answered with a variation of the ray-intersection method. 1. Find the nearest vertex, using the L2 norm (squared). 2. Consider the elements which share the vertex. It is recommended to have a connectivity list and not map them every time. 3. Cast a ray is cast from the interest point to the centroid of the first element. 4. Check among the elements in <2> which intersect the ray and select the one with the shortest intersection distance 5. Use the dot product of the intersection vector with the element normal (negative sign = outside, else inside)
(This was added to the question post itself)

Point/circle in polygons search in Marklogic 7 using cts:circle-intersect

I have a list of around 1100 polygons to iterate through in $polygons (none of them overlapping each other) and I need to find to which polygon my point or circle with a 1 mile radius belongs/intersects. I used the function below and it takes about 1 second and a half, which is good, but I was wondering, is there is another better/faster approach to it?
I read about R/M-tree algorithms, but I don't have any rectangle hierarchies indexed inside the DB. I'm also trying cts:polygon-intersect to see if it is faster, but I doubt it.
cts:circle-intersects(cts:circle(1,cts:point(5.8864790,51.0006240)), $polygons)
You can use cts:bounding-boxes to get bounding boxes (of varying granularity in the case of the polygons) and check whether they overlap, and only go to the more expensive check if they do. Checking whether two boxes intersect is very quick.
So far, cts:circle-intersects is the fastest, iterates in 1.3 seconds between all the 1100+ polygons. I've tried cts:polygon-intersects and cts:region-intersects also. Since this is not a very critical task in order to apply some fancy and speedy algorithms I will leave it like this for the moment.

Determine the points in the boundary of a given region in 2D

What is a good way to determine the points in the boundary of a given region in 2D?
Suppose that you are given a nested list with lists of two coordinates, e.g.
{ {x1,y1}, {x2,y2}, {x3,y3} }
Of course the actual nested list would have a lot more points than 3, which are associated to a given region in the plane. The nested list, for example, could determine a disk in the plane. Then, the output should be a nested list corresponding to a circle.
I don't want any image recognition stuff applied to a possible plot. I would like operations on the nested list.
This answer is based on #andand comment. The credit is all his.
If I have a nested list called "region", with lists of the 2d coordinates, I would get the "convex hull" of it writing
Needs["ComputationalGeometry`"]
regionhull = ConvexHull[ region ]
But "ConvexHull" gives us the indices of the lists within the nested list, in counterclockwise order, corresponding to the convex boundary of the region. Thus, an adittional step is needed, to make the needed output:
regionboundary = region[[ regionhull ]]
But still, this answer is incomplete. It seems to me that a "concave hull" algorithm would be the more general solution. Would anyone know anything about the concave hull in Mathematica? I may post an additional question for that.
Below, I show a figure to understand the concave and convex hull algorithms extracted from
https://gis.stackexchange.com/questions/1200/concave-hull-definition-algorithms-and-practical-solutions
A tutorial for the "Computational Geometry Package" is found at
http://reference.wolfram.com/mathematica/ComputationalGeometry/tutorial/ComputationalGeometry.html
** Addendum **
The package "alphahull" can solve the problem of finding the boundary of a concave region. Its description is found here:
http://cran.r-project.org/web/packages/alphahull/vignettes/alphahull.pdf
Sounds like you want some kind of interpolation technique. http://en.wikipedia.org/wiki/Interpolation

Computing the area of a complex (self-intersecting) polygon

I'm making a program that selects an area within a canvas by clicking a sequence of points. The points clicked are linked by some lines this way: every new point is linked with the first and the last ones. I'm looking for an algorithm that computes the area of the resulting polygon.
Intersections are allowed, and here is the complexity, so the algorithm must manage this case by finding the polygon according to the ordered sequence of points clicked and calculating its area.
After many searches, the best I've found is this http://sigbjorn.vik.name/projects/Triangulation.pdf, but I would need something easier to implement in Processing.js.
First cut the line segments where they intersect. If the input set is small, you can simply check every pair. Otherwise use an R-Tree. Then compute a constrained (Delaunay) Triangulation. Then determine the inner triangles using rayshooting and sum up their areas.
hth

Resources