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
Related
Note: I'm very much from a programming background, not a mathematics background. This will become obvious very quickly.
Assume I have a bounded n-dimensional space - for example here I'll use n=2. In that space, I have a set of pre-defined points. (As it happens, I'm doing something questionable with genetic algorithms for finding minima in non-mathematically-solvable equations, but that's not directly relevant).
Next, I have defined a new point within that 2D space. I want to know which three (n+1) points form the smallest (or possibly nearest?) triangle that contains that point. Illustration here:
Now, as that illustration shows, I'm not entirely sure what I'm doing, in that I've failed to adequately describe the criteria by which the candidate triangles are judged - points 10, 5, and 8 would enclose the point within a triangle of smaller area, for example. This is because those specifics are somewhat flexible. What I really care about is:
Computational efficiency: I could potentially end up scaling this algorithm up to thousands of points in a hundred dimensions. As such, I need a solution that's better than exhaustively testing every potential convex hull against a specific equation, and ideally one with a decent big-O notation. Presumably I'm going to need a more intelligent structure that a big unordered list to do this.
If I had a preferred criteria, it's proximity of the hull vertices to the test point. However, if it's easier to build an algorithm which judges by area/volume or something else, I can live with that.
I need to be able to handle edge-cases, where the test-point is, for example, on the edge between two vertices.
Where do I even start with this? Some cursory googling suggests Voronoi diagrams might be a step in the right direction, is that correct? What are the right tools for this job? Any help would be greatly appreciated.
BACKGROUND
So I'm creating a program that recognizes chess moves. So far, I have implemented a fair number of algorithms to come up with the best results possible. What I've found so far is that the combination of undistorting an image (using undistort ), then applying a histogram equalization algorithm, and finally the goodFeaturesToTrack algorithm (I've found this to be better than the harris corner detection) yields pretty decent results. The goal here is to have every corner of every square accounted for with a point. That way, when I apply canny edge detection, I can process individual squares.
EXAMPLE
WHAT I'VE CONSIDERED
http://www.nandanbanerjee.com/index.php?option=com_content&view=article&id=71:buttercup-chess-robot&catid=78&Itemid=470
To summarize the link above, the idea is to find the upper-leftmost, upper-rightmost, lower-leftmost, and lower-rightmost points and divide the distance between them by eight. From there you would come up with probable points and compare them to the points that are actually on the board. If one of the points doesn't match, simply replace the point.
I've also considered some sort of mode, like finding the distance between neighboring points and storing them in a list. Then I would perform a mode operation to figure out the most probable distance and use that to draw points.
QUESTION
As you can see, the points are fairly accurate over most of the squares (though there are random points that do not do what I want). My question is what do you think the best way to find all corners on the chessboard (I'm open to all ideas) and could you give me a somewhat detailed description (just enough to steer me in the right direction or more if you choose :)? Also, (and this is a secondary question) do you have any recommendations on how to proceed in order to best recognize a move? I'm attempting to implement multiple ways of doing so and am going to compare methods to obtain best results! Thank you.
Please read these two links:
http://www.aishack.in/tutorials/sudoku-grabber-opencv-plot/
How to remove convexity defects in a Sudoku square?
I have a connected shape that consists of squares put together, e.g. take a squared paper and draw a line along the existing lines that ends at its beginning and does not cross itself.
The goal is now to find an algorithm (not brute-force) that fills this shape with as few, non-overlapping rectangles as possible.
I'm looking for the optimal solution. As can be seen in the images, the naive greedy approach (take the largest rectangle) does not work.
(Optimal)
(Greedy)
My scenario is vertices reduction, but I'm sure there are other use-cases as well.
Note: This problem seems basic, but I was not able to find a solution elsewhere. Also, is this problem NP-hard?
Edit: I just realized that, in my scenario, filling the shape with as few non-overlapping triangles as possible, would give an even better result.
I've spend a lot of time researching this, since I asked the initial question. For the first problem (optimally filling the shape with rectangles), I've written the solution here under the header "Optimal Greedy Meshing":
http://blackflux.wordpress.com/2014/03/01/meshing-in-voxel-engines-part-2/
The complexity is actually better (faster) than for optimally triangulating a polygon without holes. The slowest part is the Hopcroft-Karp algorithm.
Treating the shape as a polygon is also discussed in the linked blog post. Note that I'm also considering holes.
The first problem is harder than the one with triangles; for triangles, see the algorithms in
http://en.wikipedia.org/wiki/Polygon_triangulation
which can do it without any extra vertices.
This is similar to the bin packing problem, but with some changes.
What I have is a timeseries of annotated data, and when I draw the chart, I want to place the annotations in the position that overall minimizes distance from the annotated point.
This chart, (gratuitously stolen) shows what I'd like to do:.
I know this is an optimization problem, but I have no idea where to begin. What I was doing first, was placing it at the corresponding x, and moving up/down y to find a location that was available and save the area that has been drawn. While that worked, it doesn't really make best use of available space, and I'm wondering if there's something better.
I'm wondering if there's any known algorithms out there that attack this or similar problems?
Added note: It doesn't need to be optimal, but it absolutely needs to be fast. This is done during rendering, so the UI is blocked while this executes.
There are a wide range of approaches to this difficult problem. I'd suggest starting at the Wikipedia article on automatic label placement. You might also get some ideas from the realm of force-based algorithms for graph drawing.
I would do it like this- use a simple "first fit" algorithm and start with an arbitrary order for placing the labels. Score the result with something like the sum of the distance squared from each annotated point. I would do the distance squared to avoid having all of them be really close except for one that is a long ways away.
If your first solution is lower than some threshold, use it and move on. If it isn't, take the worst fits (i.e. the labels that are the farthest from the annotated point) and move them up in the placement order and start over. Iterate this until you either get a solution that is good enough or you run out of time, in which case you take the best solution of the lot and go with it.
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: