c++ Finding closest four of a set of points [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I have a set of points, each with an x and y coordinates. I would like to find the 4 of these points that are closest to together (if plotted all the points would be at different locations, but 4 of these points are always closer to each other, and I want to be able to identify which of the points these four are programmatically ). How do I go about doing this? I'm told it has to do with k-means or nearest-neighbors, but from my search results so far, I don't see how I could get it to work for my case since I'm finding the proximity of the points relative to each other and not to some fixed point. Any suggestions as to what topic/algorithm to look into, or code snippets will be much appreciated.
I thought an image of the exact problem might help. So these 8 points are contained in a vector, and I'd like to be able to identify which four are the ones clustered on the right.
Thanks in advance.

A brute force method would be to select every possible selection of four points (every permutation) and calculate e.g.:
1) the area enclosed by the points,
2) the perimeter of the convex hull of the points,
3) ...
and you'll find your four points by getting the minimum of the values calculated by 1), 2) or 3).

Build a Delaunay Triangulation graph in nlog(n) complexity, there will be less than 2n edges to go over in order to find the four shortest ones.
you could try poly2tri.
You'd want to go over the edges like this: choose an edge, go three times to the shortest connected edge, and sum the edge lengths. save the vertices and the length sum of the minimal edge sum encountered thus far, and exhaust all the possible shortest neighbouring length combinations.

Related

Qt Graph Drawing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I've recently begun development on a project that requires me to visualize graphs, and I am looking for a decent algorithm to tackle this problem.
The graphs I'm drawing model data flow, so a reasonable drawing could be left-to-right or top-to-bottom. They are, of course, directed and mostly acyclic -- that is, there might be a few backwards edges, but these would be a small proportion and I would be happy to remove these before calculating vertex positions if having a DAG as input would substantially improve runtime.
I'm using C++ and Qt for this project and am already very familiar with the Elastic Nodes and the Diagram Scene examples Qt provides. If anyone has seen KCacheGrind, what I'm trying to do is similar to its call graph visualization.
My current attempts have included an original algorithm that assigns each node to a layer based on its minimum distance from the root and then tries to position the nodes inside each layer in such a way that edge crossings are minimized. I was unable to implement the last part of that correctly, and I believe the problem to be NP-Hard.
What I'm looking for is guidance as to what kinds of algorithms have been used to efficiently solve this problem in the past.
I'd suggest using QGraphicsScene to implement directed acyclic graph. Also please check these links to help you out with implementation:
https://github.com/qknight/automate
http://invalidmagic.wordpress.com/2009/12/10/qgraphicsscene-used-as-a-qabstractitemmodel/
http://socnetv.sourceforge.net/

DEM to TIN library [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm developing an application with C++ and i need to convert raster data (DEM) to Triangulated Irregular network (TIN), any library suggested ?
I tryed with arcGIS but I need Code in c++
I am not sure whether there are existing C++ libraries that already implements this conversion.
But this can give you a rough idea of what would have to be implemented if this was to be done from scratch in C++ (with the STL and the CGAL library):
convert your raster data into a triangulated grid of elevated
points (each DEM sample becomes a TIN vertex with x/y/z coordinates and the 4 neighboring samples in the DEM are connected via 2 TIN triangles). That's the easy part. Obviously this is a TIN, except that it's not irregular at all and probably contains too many samples.
remove redundant vertices from the TIN (one by one), and re-triangulate the hole that was just created. Repeat until satisfied. That's the difficult part. First, you need to have some criterion to measure how redundant a TIN vertex is (some measure of local flatness of the TIN for instance). The vertices should be ordered according to this criterion (read this as use a priority queue to order the vertices with this measure as the priority). When the most redundant vertex is removed, the corresponding hole has to be triangulated (you need to find the vertices along the border of the hole and triangulate the polygon) and the measure of redundancy of the neighboring vertices has to be updated. Finally, you obviously need to decide to stop this process at some point (have a minimum allowed redundancy).

the efficient algorithm for finding the area of polygon [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am looking for the best (efficient algorithm for calculating the area of 2D polygon (especially for triangle given three points). I search on the web and I found the following link, but still I'm not sure that they are efficient in terms of memory cost or not (since my mesh is huge).
I am wondering if there is any tricks in c++ (I'm newbie in c++) which could be applied on them:
here are the links:
(stackoverflow)
How to determine if a point is in a 2D triangle?
http://www.softwareandfinance.com/Visual_CPP/Triangle_Area_Perimeter.html
It's worth to mention that the final target is to find out if a point is inside (NOT on the border) the polygon.
thanks for any help.
Joachim Pileborg suggested in comments that the area isn't needed, but that misses the point: there's an efficient algorithm which does require an intermediate value, that just so happens to be 2*Area.
However, in this case the problem is actually the input domain: a mesh of triangles. That means almost every vertex borders on two triangles. It's not like "point P lies on the left of edge E, so it's not in triangle T". There are a large set of triangles Ti, some of which lie on the left, some of which lie on the right, and one directly on either side of a given edge.
Given that complexity, you should pre-process the mesh. Partition it in some manageable chunks, e.g. 16x16, and note for each triangle in which chunks it lies. Any point P lies in exactly one chunk, so you need to test perhaps 1% of triangles (a single triangle may lie in multiple chunks, but the average is low).
(You rarely if ever need to do just a single point-to-mesh match, so preprocessing is justified. And pre-calculate the area while you're at it.)

Suggestions for alternative 3D space partition tessellation, different from Voronoi and Delaunay [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have a system of mono-disperse spheres inside a cubic box. I am studying the volume distribution inside the sample, after tessellating it with either Voronoi and Delaunay tessellations. I am interested on some properties which should not depend on the tessellation.
Currently, I am comparing with the values obtained from Voronoi and Delaunay. I would like to know if you are familiar with another space partition approach (It is important that the final sum of the individual cells add up to the total volume, and the cells should be disjoint). Furthermore, in case you know another kind of tessellation, do you also know a library which already implements it, preferable in C/C++ or python?
Some variations, like Laguerre partitions, coincide with my current Voronoi approach since the spheres are mono-disperse. Another candidate will be the Centroidal Voronoi tessellation, although I have not found yet a library to do that (although it could lead to evenly spaced cells which does not reflect the disorder inside the system, which is not desirable).
Thanks in advance for your kind help.

Normalizing histograms? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
What is normalizing histograms? When and why would I use it? What are its advantages?
I don't understand the concept at all- when I try to apply it to my histogram, when I use back projection, I don't get any results.
Could someone give me a non-technical explanation of normalization?
I am using OpenCV
PS: Don't send me to wikipedia- I don't understand the Wikipedia Page
Thanks
It's very simple, actually. A normalized histogram is one in which the sum of the frequencies is exactly 1. Therefore, if you express each frequency as a percentage of the total, you get a normalized histogram.
What is the use of a normalized histogram? Well, if you studied probability and/or statistics, you might know that one property required for a function to be a probability distribution for a random variable is that the total area under the curve is 1. That's for continuous-variable functions. For discrete functions, the requirements is that the sum of all values of the function is 1. So a normalized histogram can be thought of a probability distribution function which shows how probable each of the values of your random variable is.