C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Point belonging to which Polygon

By : Saber
Date : December 01 2020, 04:55 PM
I wish this help you So first of all, you say your query returns nil. Well, that's not true. The first method on your query results returns nil. Your query returned an empty array. i.e. it didn't throw an error but did not yield any results. in rgeo when a method returns nil that normally means something else.
you need to make sure both the region and the point data came from the same projections. Its possible if not likely that your points are geographic (lonlat) coordinates. PostGIS can only do spatial joins on flat planes. If you formatted geographic coords as geographic types (using things like the RGeo::Geographic factories), trying to do a spatial join w/ a geographic shape for a projected (flat) data column should throw an error. But if you didn't, and generated the Point instances with Cartesian or Geometric types, throwing the geographic points into the method is surely going to return []. After all, 32, -81 are points on a geometric projection too.
code :

Share :

## Given a polygon and a point in 2D, how can one find the feature (vertex or edge) of the polygon closest to the point?

By : user3607602
Date : March 29 2020, 07:55 AM
wish helps you If the polygon is convex, then the overhead of the voronoi calculation far exceeds that of the naive approach.
If this is run many times, and each time the point changes slightly, you only need to check 3 segments (think about it: as you move around, assuming many checks, then the closest edge will only change to an adjacent edge)

## Polygon Collision Testing / Polygon Overlap Test in C# - Not Point in Polygon

By : Habiba Salim
Date : March 29 2020, 07:55 AM
will help you I am testing to determine if two polygons overlap. I have developed a first version which does a simple point in polygon test (Fig 1). However I am looking to revamp that method to deal with situations where no vertices of polygon A are in polygon B but their line segments overlap (Fig B). , Here is an example with using Region:
code :
``````  GraphicsPath grp = new GraphicsPath();

// Create an open figure
grp.AddLine(10, 10, 10, 50); // a of polygon
grp.AddLine(10, 50, 50, 50); // b of polygon
grp.CloseFigure();           // close polygon

// Create a Region regarding to grp
Region reg = new Region(grp);
``````

## How can i find shortest point on a polygon from a point to that polygon (not it's distance )

By : del
Date : March 29 2020, 07:55 AM
Does that help I don't know if this answers your question, but here's a piece of code I wrote several years ago.
It calculates the point index out of a list of polygon points and the distance of the perpendicular to the nearest edge.
code :
``````    // Polygon points
List<Vector2> p;

/// <summary> Calculates the perpendicular vector from nearest point on polygon to given point. If no points available minIndex is -1. </summary>
public void GetPolygonDist(Vector2 point, out Vector2 minDist, out int minIndex) {
if (p.Count == 0) { minDist = Vector2.Null(); minIndex = -1; return; }
Vector2 dist;
minDist = point - p[0];
minIndex = 0;
for (int i = 0; i < p.Count - 1; i++) {
Vector2 l = p[i + 1] - p[i];                                        // Edge
if (l.GetLength() < 1e-9) continue;                                 // Ignore edge of length almost zero
Vector2 d = point - p[i];                                           // Polygon point to point
Vector2 b = (l * d) / (l * l) * l;                                  // Projection to edge
double f = Math.Sign(b * l) * (b.GetLength() / l.GetLength());      // Where on the edge is the perpendicular?
if (f < 0.0) dist = point - p[i];                                   // Point before the edge
else if (f > 1.0) dist = point - p[i + 1];                          // Point after the edge
else dist = d - b;                                                  // Perpendicular
if (dist.GetSquaredLength() < minDist.GetSquaredLength()) {
minDist = dist;
minIndex = i;
}
}
}
``````

## Point in polygon algorithm that returns true when the test point is on a polygon edge

By : btbear
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Expanding the polygon a bit is an option but this can be tricky with concave polygons.
My recommendation would be to shift the point into different directions (up/down/left/right) by a tiny amount and do the calculation for each of these shifted points. Then count it as being inside if at least one of the shifted points is determined to be inside.

## For a point in a concave polygon, what is the closest point outside the polygon?

By : Nikhil Sharma
Date : March 29 2020, 07:55 AM
To fix the issue you can do Approach with extending the line outwards looks good enough for most cases
If you determine that the closest point is corner, just get external point at bisector of outer angle.