How can I divide a convex polygon into quadrilaterals considering the hatched polygons (holes) already in place. Any suggestions will be greatly helpful.
What am I actually trying to do is to find quadrilateral strips as two of them are shown below. I thought may be dividing the whole polygon into quadrilaterals would help achieving this.
Related
I have a polygon with collinear points. I want to triangulate the polygon while retaining all the collinear points, since I require those vertices on the generated meshes. Currently I tried to use poly2tri, but it doesn't support collinear points. Is there a polygon triangulation algorithm which support collinear points?
Try moving the points slightly, so they are not colinear. Doing the meshing and then moving the points back.
I tried running the meshing algorithm, then perturbing all the points it missed, then running it again.
It can be quite slow but it does work.
A simple polygon with collinear vertices presents a serious problem for the "ear splitting" triangulation. The best example to see this problem - sketch yourself a 5-point star. Pick any of the points as the convex vertex for a candidate ear.
The diagonal for this ear lies completely within the polygon, and doesn't form "X" intersections with any of the other edges, so by the criteria for a "valid diagonal", it should work. But, notice that once you slice off the ear, the remaining polygon is no longer a simple polygon - because it contains two vertices where the edges meet at a straight (180 deg.) angle. That alone disqualifies the new sub-polygon as "simple", and it will crash any attempt to continue triangulation on it using ear-splitting. I will post a separate question on how best to triangulate these ill-conditioned polys.
I have arbitrary many lines in 3D space which are all parallel to each other. Now I want to find the convex hull of these lines. To illustrate this, I've drawn a picture:
I know the start- and endpoints of all lines (the blue dots). The lines are not equally long. If a viewer looks in the direction of the lines (marked as the viewer direction in the pic) he sees only the dots. Now I want to find the convex hull of these dots. Hopefully its clear what I mean.
My idea was to project the start or endpoints on a plane which is perpendicular to the line's direction. After that I can apply some kind of convex hull algorithm to these points. But I have no idea how.
Your idea is exactly correct. One way to accomplish this is to define a vector v along your viewing direction, and then rotate v to the z-axis. The same rotation will convert lines to vertical lines. Then drop the z-coordinate of the endpoints to get your projected points. Then compute the convex hull. There are hull algorithms all over the web, including my own here.
Here's a suggestion based on the calculus of variations.
Consider enclosing your collection of parallel line segments in a simple closed curve minimizing the area of the curve given the constraint that it has to enclose all your segments.
Your "curve" is going to be piecewise linear, so there you might be able to use a P.W basis function in the iterations, though it's possible that you could run into some singularities when the algorithm needs to drop a segment.
I have a group of points (x,y) and I need to find out the distance between the two that are farthest apart.
What is the most efficient way to find this?
Thanks
Well, compairing every point against every other point is certainly not efficient.
The most efficient way involves finding the convex hull, which is the convex polygon (no angles > 180) surrounding all points.
After that, you find the farthest points on the hull, using antipodal pairs.
Algorithm described here:
http://www.seas.gwu.edu/~simhaweb/cs153/lectures/module1/module1.html
This is a programming homework assignment, of which I have no qualms about doing it myself however I'm quite stuck on the geometry of it. I need to be able to determine the exact point of intersection given the center and radius of a circle and two end points of a vertical line segment, and since geometry isn't my forte I was hoping for some help (even pointers in the right direction would be appreciated!)
This probably isn't the best place to ask a question like this but I'm not really sure where else to look for help, my apologies if it's against the rules or something.
edit:
My apologies, what I am really having trouble with is determining what the points of intersection are (and if there is one intersection or two.) I've tried each solution given and they work great for determining if there is an intersection or not but my problem still persists as I mis-worded my question. If anyone can help with that it'd be much appreciated!
Try http://mathworld.wolfram.com/Circle-LineIntersection.html, this covers the geometry aspect of your problem quite well.
If C=(x0,y0) is the center, r the radius, and k the abscissa of the line, you have
y = y0 +/- sqrt(r^2-(k-x0)^2), but no intersection if r < abs(k-x0)
using the centre [x,y] of the circle, find the distance of this particular line from the centre.refer
now if this distance is > radius of the circle => the line won't intersect. otherwise, it will.
What is a good algorithm for reducing the number of vertices in a polygon without changing the way it looks very much?
Input: A polygon, represented as a list of points, with way too many verticies: raw input from the mouse, for example.
Output: A polygon with much fewer verticies that still looks a lot like the original: something usable for collision detection, for example (not necessarily convex).
Edit: The solution to this would be similar to finding a multi-segmented line of best fit on a graph. It's called Segmented Least Squares in my algorithms book.
Edit2: The Douglas Peucker Algorithm is what I really want.
Edit: Oh look, Simplifying Polygons
You mentioned collision detection. You could go really simple and calculate a bounding convex hull around it.
If you cared about the concave areas, you can calculate a concave hull by taking the centroid of your polygon, and choosing a point to start. From the starting point rotate around the centroid, finding each vertex you want to keep, and assigning that as the next vertex in the bounding hull. The complexity of the algorithm would come in how you determined which vertices to keep, but I'm sure you thought of that already. You can throw all your vertices into buckets based on their location relative to the centroid. When a bucket gets more than an arbitrary number of vertices full, you can split it. Then take the mean of the vertices in that bucket as the vertex to use in your bounding hull. Or, forget the buckets, and when you're moving around the centroid, only choose a point if its more than a given distance from the last point.
Actually, you could probably just use all the vertices in your polygon as "cloud of points" and calculate the concave hull around that. I'll look for an algorithm link. Worst case on this would be a completely convex polygon.
Another alternative is to start with a bounding rectangle. For each vertex on the rectangle, find the distance from the point to the polygon. For the farthest vertex, split it into two more vertices and move them in some. Repeat until some proportion of either vertices or area is met. I'd have to think about the details of this one a little more.
If you care about the polygon actually looking similar, even in the case of a self-intersecting polygon, then another approach would be required, but it doesn't sound like thats necessary since you asked about collision detection.
This post has some details about the convex hull part.
There's a lot of material out there. Just google for things like "mesh reduction", "mesh simplification", "mesh optimization", etc.