computational-geometry

Convex hull of 4 points

假装没事ソ 提交于 2019-11-28 21:33:34
I would like an algorithm to calculate the convex hull of 4 2D points. I have looked at the algorithms for the generalized problem, but I wonder if there is a simple solution for 4 points. Take three of the points, and determine whether their triangle is clockwise or counterclockwise:: triangle_ABC= (A.y-B.y)*C.x + (B.x-A.x)*C.y + (A.x*B.y-B.x*A.y) For a right-handed coordinate system, this value will be positive if ABC is counterclockwise, negative for clockwise, and zero if they are collinear. But, the following will work just as well for a left-handed coordinate system, as the orientation

Is there a robust C++ implementation of the Bentley-Ottmann algorithm?

折月煮酒 提交于 2019-11-28 21:24:49
The Bentley-Ottoman algorithm finds all crossings in a set of line segments. For a well known and important algorithm, it seems quite weird that a C++ implementation of Bentley-Ottmann algorithm — the implementation that can handle all the degenerated cases (i.e., no special assumption on the sweeping line and the number of intersection points, and so on) — is simply not available. The only code I can found is here , but it doesn't seem to handle the generalized case . Is Bentley-Ottmann algorithm already implemented in any well-tested library, such as Boost or LEDA? If yes, may I have the

Generate new polygons from a cut polygon (2D)

帅比萌擦擦* 提交于 2019-11-28 20:49:22
I'm stuck with this little problem and my algorithm to solve this doesn't hold for all cases. Does anybody has an idea how to solve this? Here's an example polygon: example http://img148.imageshack.us/img148/8804/poly.png Formal description We have a list of points in CW order defining the polygon. We also can query whether a point is a cutting point with is_cut(p) , where p is a given point. Now we want to compute new polygons caused by this "cut". The algorithm should do this: Input: {a, c1, b, c4, c, c5, d, c6, e, c3, f, c2} Output: {a, c1, c2} , {b, c4, c3, f, c2, c1} , {d, c6, c5} , {e,

Getting a bounded polygon coordinates from Voronoi cells

…衆ロ難τιáo~ 提交于 2019-11-28 20:46:23
I have points (e.g., lat, lon pairs of cell tower locations) and I need to get the polygon of the Voronoi cells they form. from scipy.spatial import Voronoi tower = [[ 24.686 , 46.7081], [ 24.686 , 46.7081], [ 24.686 , 46.7081]] c = Voronoi(towers) Now, I need to get the polygon boundaries in lat,lon coordinates for each cell (and what was the centroid this polygon surrounds). I need this Voronoi to be bounded as well. Meaning that the boundaries don't go to infinity, but rather within a bounding box. Given a rectangular bounding box, my first idea was to define a kind of intersection

Expand fill of convex polygon

对着背影说爱祢 提交于 2019-11-28 19:15:50
问题 I have a convex polygon P1 of N points. This polygon could be any shape or proportion (as long as it is still convex). I need to compute another polygon P2 using the original polygons geometry, but "expanded" by a given number of units. What might the algorithm be for expanding a convex polygon? 回答1: To expand a convex polygon, draw a line parallel to each edge and the given number of units away. Then use the intersection points of the new lines as the vertices of the expanded polygon. The

How to know if a line intersects a plane in C#?

左心房为你撑大大i 提交于 2019-11-28 18:36:56
I have two points (a line segment) and a rectangle. I would like to know how to calculate if the line segment intersects the rectangle. From my "Geometry" class: public struct Line { public static Line Empty; private PointF p1; private PointF p2; public Line(PointF p1, PointF p2) { this.p1 = p1; this.p2 = p2; } public PointF P1 { get { return p1; } set { p1 = value; } } public PointF P2 { get { return p2; } set { p2 = value; } } public float X1 { get { return p1.X; } set { p1.X = value; } } public float X2 { get { return p2.X; } set { p2.X = value; } } public float Y1 { get { return p1.Y; }

determine if a given point is inside the polygon

拟墨画扇 提交于 2019-11-28 18:29:46
Given a convex polygon as a counter-clockwise list of n vertices, give O(lgn) algorithm to determine if a given point is inside the polygon. Assume the basic operations take O(1). I am think a direction that: if a point is inside a convex polygon, what is the special relationship among the points and all the vertecies or edges? Also, I am guessing the trick here is the convex polygon which makes the algorithm lgn. The only solution for this problem I know of requires O(n) polygon preprocessing time. Afterwards each query point against a preprocessed polygon is handled in O(lg n) time. Just

Testing whether a polygon is simple or complex

前提是你 提交于 2019-11-28 18:24:32
For a polygon defined as a sequence of (x,y) points, how can I detect whether it is complex or not? A complex polygon has intersections with itself, as shown: Is there a better solution than checking every pair which would have a time complexity of O(N 2 )? There are sweep methods which can determine this much faster than a brute force approach. In addition, they can be used to break a non-simple polygon into multiple simple polygons. For details, see this article , in particular, this code to test for a simple polygon . See Bentley Ottmann Algorithm for a sweep based O((N + I)log N) method

Draw a parallel line

只愿长相守 提交于 2019-11-28 17:53:56
I have x1,y1 and x2,y2 which forms a line segment. How can I get another line x3,y3 - x4,y4 which is parallel to the first line as in the picture. I can simply add n to x1 and x2 to get a parallel line but it is not what i wanted. I want the lines to be as parallel in the picture. What you want to do is to offset the coordinates in the orthogonal direction. If you know vector math, multiply the vector created by the distance between the endpoints of the line by the following matrix: [ 0 -1 ] [ 1 0 ] Say that the first line has the points (x1,y1) , (x2,y2) , with x=x2-x1 , y=y2-y1 . We also

How do I derive a Voronoi diagram given its point set and its Delaunay triangulation?

半腔热情 提交于 2019-11-28 17:52:44
I'm working on a game where I create a random map of provinces (a la Risk or Diplomacy). To create that map, I'm first generating a series of semi-random points, then figuring the Delaunay triangulations of those points. With that done, I am now looking to create a Voronoi diagram of the points to serve as a starting point for the province borders. My data at this point (no pun intended) consists of the original series of points and a collection of the Delaunay triangles. I've seen a number of ways to do this on the web, but most of them are tied up with how the Delaunay was derived. I'd love