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
Related
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.
I would like to find two vertices of two meshes (1 vertex per mesh) that define the closest distance between them. Or the two triangles would be fine I guess.
However I'm not sure how to search for this in CGAL's documentation, I'm sure that this is doable with some existing tool (probably based on a 3d distance field and/or AABBs). Could I please get a hint (keywords/link) on what to look for?
I've been pointed to the Optimal Distances CGAL package, but it's not exactly what I want, since it outputs the distance and the coordinates, so finding the vertex ID is an additional computational overhead.
I've already implemented a collision detection with CGAL to find the triangle-triangle intersection in a triangle-soup, using AABB-trees. I guess that I should be somehow close to this, although now a simple soup with all me object-triangles wouldn't do the job.
The solution found was this:
CGAL's Optimal Distances package can give an approximation of the closest distance between the convex hulls of two meshes, without explicitly computing the hulls. As a result one gets the shortest distance between these hulls, and the coordinates of the 2 points that lie on them and define this distance.
Then these coordinates can be used as a search-query in kd-trees that contains the original vertices of the meshes in order to find the closest vertices.
In case one mesh is non-convex, the hull that CGAL is using is very approximate, so convex decomposition might be necessary. In such a case one would have to check distances for each convex part and then take the shortest distance.
The above would result in something like this:
enter link description here
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 am not good with math,and i just need someone to point me in the right direction.
Latitude Longitude
N 36° 13.488' W 095° 54.295'
N 36° 13.488' W 095° 53.805'
Assume that all three are located on a flat plane, at the same elevation.
Assume that the curvature of the earth is not a factor.
Assume that there are exactly 69.1691 miles per degree of latitude.
Assume that there are 55.9588 miles per degree of longitude (Tulsa area only)..
I am trying to figure out what the last points coordinate is.
Can anyone help. I just dont know where to begin
There are numerous ways to find the third point. The angles in an equilateral triangle are all 60 degrees. The third point lies on the bisector of the line connecting the two points you have. Expressing the points and lines using vectors, rather than coordinates, helps.
But the truth is, if you do not have enough mathematical knowledge for this kind of problem, you probably ought not to be tackling it as a programming problem. How can you know you've done it right?
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.