English 中文(简体)
Delete holes in a Polygon
原标题:

I have a polygon determined by an Array of Points.

This polygon is crossing itself making some holes in the polygon itself.

My questions is: How can I omit this holes and just get the exterior points of the polygon?

Or what will be the same and probably easier: Which Algorithm for checking if a point is inside a Polygon should I use to detect the points in the holes of the polygon as inside points?

Thanks in advance,

/roger

最佳回答

First, find all intersections of edges, add these intersections to the vertices list, and split the edges at these intersections. Then, start with one vertex that is obviously an external one (e.g. the "rightmost") and trace the outline, adding edges and vertices to the result sets. Tracing the outline is simply going along the edge with minimum angle to the last edge.

问题回答

You might want to find the convex hull of all the points in your polygon.

One algorithm for doing this is Graham-Scan with complexity O(nlgn). From Cormen:

Let Q be the set of all points in your polygon
Graham-Scan(Q)

1  let p0 be the point in q with the minimum y-coordinate or the leftmost in case of tie
2  let (p1, p2,...,pm) be the remaining points in Q, sorted by polar angle around p0
       if more than one point shares the same polar angle, keep the farthest point

3  let S be an empty stack
4  PUSH(p0, S)
5  PUSH(p1, S)
6  PUSH(p2, S)
7  for i = 3 to m
8    while the angle formed by points NEXT_TO_TOP(S), TOP(S), and pi makes a non-left turn
9        POP(S)
10   PUSH(pi, S)
11 return S

S now contains all of the outer points of your polygon. You ll have to do some polar math, but that s pretty simple. To sort by polar order sort all points on their cotangent with your bottom most point. I forget the code for checking a right turn, but it s on the internet if you just search fro Graham-Scan. Hope this helps!





相关问题
Bounding ellipse

I have been given an assignement for a graphics module, one part of which is to calculate the minimum bounding ellipse of a set of arbitrary shapes. The ellipse doesn t have to be axis aligned. This ...

Line segment in a triangle

How can we check if a line segment falls partially or fully inside a triangle? Cheers.

Line Segments from a point

I have a point p, and 2 line segments in a 2D plane. Point p is a location of view from where camera is looking towards the line segments. I want to check if line segment 1 is partially or fully ...

Creating a surface of triangles from a set of 2D points

I have a set of points and I need to convert the set to (non-overlapping) triangles (or a big polygon if equivalent)... The application: I have a list of locations (latitude,longitude) from a country,...

Radial plotting algorithm

I have to write an algorithm in AS3.0 that plots the location of points radially. I d like to input a radius and an angle at which the point should be placed. Obviously I remember from geometry ...

Delete holes in a Polygon

I have a polygon determined by an Array of Points. This polygon is crossing itself making some holes in the polygon itself. My questions is: How can I omit this holes and just get the exterior ...

Finding cycle of 3 nodes ( or triangles) in a graph

I am working with complex networks. I want to find group of nodes which forms a cycle of 3 nodes (or triangles) in a given graph. As my graph contains about million edges, using a simple iterative ...

热门标签