I am trying to create a polygon in VB6 using the polygon function.
I have many points in random order that I would like to create the polygon with.
Unfortunately, the order is important when developing a polygon, as i get a jagged looking polygon, as opposed to a nice closed polygon.
I was wondering if anyone had any good ideas/tricks to develop an algorithm that can go through these points and put them in an appropriate order.
Thanks so much!
To keep things simple and the solution unique, you should start with a convex hull algorithm like this one ("Gift Wrapping"):
http://en.wikipedia.org/wiki/Gift_wrapping_algorithm
Should not be too hard to implement in VB. If you have problems with that, ask a new question.
I used the Graham Scan Algorithm to actually go ahead and solve this problem.
http://en.wikipedia.org/wiki/Graham_scan
If you follow the pseudocode, be careful.
The line
while ccw(points[M-1], points[M], points[i]) <= 0:
Should be
while ccw(points[M-1], points[M], points[i]) >= 0:
Related
I know that when your sweepline encounters three centers of your array, you have to check if there is something called "circle points".
I understand that circle points are the poles of the circle that goes through the other 3 points, but my questions is, which is the efficient way to do this, because what you really want is the center of the circle which is the vertex of three Voronoi poligons, so what came to my head is to find the three mediatrices and the intersection of the three will be the center, but it seems to me that if I do that the algorithm will be mor closely to a brute force algorithm, I hope you could help me with this, thanks in advance
EDIT: I think it's worth saying that I'm working on Julia, and that I've already done two brute force algorithms, one aproximate and one exact
There is a rather good and detailed description of this algorithm in this course book:
https://www.springer.com/gp/book/9783540779735
They explain how efficiency is obtained by adding pointers between the status tree and the parts of the diagram being constructed.
Maybe it can help. I have not implemented the algorithm myself.
I am working on a tool which modifies geometries. One task is to move points that their (Euclidian) distances among each other are bigger than a given distance by considering that the sum of the moved ways is a minimum. A non-iterative solution which does not measure distances in between is preferred.
I need a algorithm in 3d, but a 1d or 2d explanation as a starting point would be very welcome.
The later coding will be in Python. In case a solution already exists I would use it.
A link to a book or paper related to this problem would be also helpful.
Thanks Hans G
My problem is as follows:
I have a convex hull which could look like this:
I would like to group significantly close points together to be represented by some form of averaging, which could be the mean or median point for example.
I am more so focused on how to do the grouping.
How can I perform this grouping in a systematic way?
I understand this seems like a very simple question and the answer is obvious. My main problem is in attempts to solve this I end up with some corner cases such as the answer will change depending on where I start on the hull. For example if I started from the red line and worked clockwise I would end up with (if I made no attempt to catch the corner case):
I had many attempts at this and every time I rethought my idea I ended up with a new corner case that felt unwieldy. I have a habit of finding the most un-intuitive way to solve a problem so I thought it best to ask the a community. A comparative example to the problem I am having now is I've been asked to find an element in a sorted array and I'm initially performing a linear search and I have a gut feeling there is something better out there.
I could not find exactly what I wanted with my research. I found hull simplifying algorithms but it changed the shape of the hull too much which did not suit the goal of my program.
I will add a note here at the end that I am using OpenCV with C++ to generate a convex hull on a project I am working on. Just in case this is a worth while detail (and why I added OpenCV as a tag).
Consider using Douglas–Peucker algorithm
It is intended to simplify polylines, throwing out less important points.
Thanks Berriel for addition: it is implemented in OpenCV: approxPolyDP
I am looking for an algorithm that can connect points together with a continuous curve line. Imagine drawing from point a to b to c until the last point, and when you draw from point to point, the line must be a curve and is continuous with respect to the previous point and next point, as if the given points are just samples of a closed loop. Please see figure below for illustration.
Are there such algorithm for something like this?
*The circles in the figure are my list of points.
Given that your points are ordered, spline interpolation is definitely the best way to go here. (As indicated by by bo1024's comment) I highly recommend the following notes:
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/
And specifically the section here would be most relevant to getting a closed loop like you asked for:
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-curve-closed.html
EDIT: If the curve has to pass through the points, then the unique degree n solution is the Lagrange interpolating polynomial. You can just make one polynomial for each component of your points vectors using the formula on the wiki page:
http://en.wikipedia.org/wiki/Lagrange_polynomial
Unfortunately Lagrange interpolation can be pretty noisy if you have too many points. As a result, I would still recommend using some fixed degree spline interpolation. Instead of B-splines, another option are Hermite polynomials:
http://en.wikipedia.org/wiki/Cubic_Hermite_spline
These will guarantee that the curve passes through the points. To get a closed curve, you need to repeat the the first d points of your curve when solving for the coefficients, where d is the degree of the Hermite spline you are using to approximate your points.
The problem is very similar to the travelling salesman problem, you may be able to extend some of the algorithms used to solve it to suit your case.
For instance, evolutionary algorithms are easy to adapt and you will find lot of references about using them to solve the TSP.
I have a list of (about 200-300) 2d points. I know needs to find the polygon that encloses all of them. The polygon has to be convex, and it should be as complex as possible (i.e. not a rectangular bounding box). It should find this in as low as possible time, but there are no restrictions on memory.
You may answer in pseudocode or any language you want to use.
Sounds like you're looking for a convex hull algorithm? It's been more than a decade since I was taught about these, but the name Graham Scan sticks in my mind and would probably be where I'd start.
Take a look at Graham's Algorithm.
Qhull is good software for computing 2D convex hulls.
If it is a real world problem - as in, not an academic one - there's never really a reason to solve such a generic problem yourself.