I have a polygon P made of N vertices. I need an algorithm that, given P, subdivide it in a certain number of convex polygons each using at most M vertices.
Ps.
P is a 2D polygon. Furthermore, i can use a polygon triangulation, but i am interested in algorithms that subdivide P into convex polygons having more than 3 vertices (and, as said above, at most M).
Quadtree methods would be my recommendation. Check those out.
Related
I need a method to project 3d conics to 2d. None of the articles tell how to do this with rational beziers. Another thing I need a method for is moving 3d or 2d conics to 4d or 3d respectively (as in a reverse projection). I read somewhere that rational beziers can be split by moving them to a higher dimension and splitting the resulting non-rational curve with de Casteljau and then moving back. I seem to recall that perspective projection of conic beziers can be represented exactly with conic beziers, and that it may involve splitting into several curves. I don't understand any of the articles on any site on beziers.
Since there aren't any better answers, here's what I can offer off the top of my head...
Perspective transformation can change parabolas into ellipses or hyperbolas and vice-versa, so even though P0, P1, and P2 can be directly mapped, the weights will change.
Assuming a conic with weights (1,w,1), however, the distance along the line from (P0+P2)/2 to P1 at which it intersects the curve is simply related to the weight w, and that lets you find the new weight as follows:
Map P0, P1, and P2 to P0', P1', P2'
Calculate the midpoint M' = (P1'+P2')/2
Inverse map M' to M, and calculate the intersection point I of the line M-P1 with the original curve.
Map the intersection point I to I', to get the point at which the new curve should intersect M'-P1'
Calculate the new weight w' from the position of the intersection I'. The curve gets to I at t=0.5, so w' = (M'-I')/(P1'-I'). Note that this division makes sense, because the vectors being divided are collinear. You can divide their lengths or just the largest coordinate.
If you expand out all the steps, I'm sure there are ways to simplify this procedure.
Context
I have to implement a polygon triangulation algorithm for a school assignment. I chose to follow the algorithm described in the book "Computational Geometry: Algorithms and Applications".
The input is a polygon stored as a doubly-connected edge list. The first step is to partition the polygon into monotone pieces. In order to do so, it's necessary to perform a line sweep and process each vertex according to its type. According to the authors, the vertex types are described as follows:
We distinguish five types of vertices in P—see Figure 3.3. Four of these
types are turn vertices: start vertices, split vertices, end vertices, and merge
vertices. They are defined as follows. A vertex v is a start vertex if its two
neighbors lie below it and the interior angle at v is less than π; if the interior
angle is greater than π then v is a split vertex. (If both neighbors lie below
v, then the interior angle cannot be exactly π.) A vertex is an end vertex if
its two neighbors lie above it and the interior angle at v is less than π; if the
interior angle is greater than π then v is a merge vertex. The vertices that
are not turn vertices are regular vertices. Thus a regular vertex has one of its
neighbors above it, and the other neighbor below it.
The problem
I can't figure out how to differentiate start vertices from split vertices, or end vertices from merge vertices. How can I do it?
Additional info
My data struct for the DCEL is something like this
class HalfEdge {
HalfEdge *previous, *next, *twin;
Point *to, *from;
};
Maybe if you keep track of a counter clock-wise orientation of the polygon's boundary (i.e. keep the edges directed), you could distinguish the two. Say the consecutive vertices are v[i-1], v[i], v[i+1] and v[i-1] and v[i+1] are below v[i]. Then form the 2D vectors v[i]-v[i-1] and v[i+1]-v[i]. After that, calculate the determinant det( v[i]-v[i-1] , v[i+1]-v[i] ). If the determinant is positive, then the vertex is start. If the determinant is negative, the vertex is split.
I have the coordinates of n points on a sphere and I know they are all coplanar. How can I find the edges of the polygon which has the vertex the n given points?
OK, your problem is weird ordering.
Project all points onto any convenient plane - the simplest approach is using OXY, OXZ or OYZ plane (choose one that is not perpendicular to your plane) - in this case you just use (P[i].X. P[i].Y, 0) for P[i] point and sort projected 2D points by angle against the first point - it works because points on sphere arc form convex polygon. Then use this ordering as polygon vertex indexes.
Based on Finding the centroid of a polygon? (P. Bourke), I would like to compute a weighted centroid (i.e. each vertex has an associated weight). There is a formula given in Find the centroid of a polygon with weighted vertices but I think it is not valid (if weights are all the same, you don't get the centroid (see https://math.stackexchange.com/questions/3177/why-doesnt-a-simple-mean-give-the-position-of-a-centroid-in-a-polygon).
You cannot compare centroid for polygon with masses in vertices only (imagine iron balls connected with cocktail tubes) and centroid for polygon with mass distributed over the area (imagine polygon carved from steel sheet).
In the first case use formula from Find the centroid of a polygon with weighted vertices, in the second- the last link given
Given two simple polygons P and Q where P is convex but Q not, how fast can one compute the difference $P - Q$ between P and Q if P has n and Q has m vertices?
One can assume that the polygons are given as list of vertices ordered in clockwise direction.
"How fast" depends on lots of parameters, so I think, we should start with how to do it,first.
Firstly, I assume polygons lie on the same plane. Start with computing the finite intersection of each line of P with each line of Q. If the intersection exists and intersection point lies on intersecting lines(I mean between start and end, not on them), divide line into two and continue finite line-line intersections iteratively. Then, categorize each line segment(now I can call them as segment because that they are all divided if necessary) by using a point in polygon computation with mid-points of segments..Inner,Outer or OnthePolygon...After categorization construct a new polygon from the lines of P that lies outside of Q and lines of Q that lies inside of the P. Here, your challenge will be dealing with tolerances and lines that are lies on eachother..At first glance, overall algorithm is like this..
This algorithm can be improved by eliminating lines and even polygons by computing their ranges(min and max for each axis). Except from the hardware, programming language or data handling parameters, the speed of this operation is dependent on the input polygons and their orientation.