Bezier curve approximation for large amount of points - java

I have about hundred points, that I want to approximate with Bezier curve, but if there are more than 25 points (or something like that), factorial counting in number of combination causes number overflow.
Is there a way of approximating such amount of points in a Bezier-like way (smooth curve without passing through all points, except first and last)?
Or do I need to choose another approximation algorithm with the same effect?
I'm using default swing drawing tools.
P.S. English is not native for me, so probably I've used wrong math terms somewhere.

Do you want to get one Bezier curve fitting best in all 100 points? If that is the case Jim Herold has a very detailed explanation how to do it. A further optimisation could be reducing the amount of points using the Douglas-Peucker algorithm.

Related

Actual performance benefits of distance squared vs distance

When calculating the distance between two 3D points in Java, I can compute the distance, or the distance squared between them, avoiding a call to Math.sqrt.
Natively, I've read that sqrt is only a quarter of the speed of multiplication which makes the inconvenience of using the distance squared not worthwhile.
In Java, what is the absolute performance difference between multiplication and calculating a square root?
I Initially wanted to add this as a comment, but it started to get too bid, so here goes:
Try it yourself. Make a loop with 10.000 iterations where you simply calculate a*a + b*b and another separate loop where you calculate Math.sqrt(a*a + b*a). Time it and you'll know. Calculating a square root is an iterative process on its own where the digital (computer bits) square root converges closer to the real square root of the given number until it's sufficiently close (as soon as the difference between each iteration is less than some really small value). There are multiple algorithms out there beside the one the Math library uses and their speed depends on the input and how the algorithm is designed. Stick with Math.sqrt(...) in my opinion, can't go wrong and it's been tested by a LOT of people.
Although this can be done very fast for one square root, there's a definite observable time difference.
On a side note: I cannot think of a reason to calculate the square root more than once, usually at the end. If you want to know the distance between points, just use the squared value of that distance as a default and make comparisons/summations/subtractions or whatever you want based on that default.
PS: Provide more code if you want a more "practical" answer

Given a set of points, find the maximum number of triangles

Is there an algorithm that can tell you what points to connect to form a triangle given a set of points? None of the connecting lines can intersect, however triangles can be inside of other triangles.
Given a general set of points in R^d the Delaunay triangulation is often an optimal choice for tessellation.
Specifically, the Delaunay triangulation will tessellate the convex hull of the point set into a set of non-overlapping elements, ensuring that the radius of the largest circumsphere is minimised - this means that the triangulation is optimal in terms of its "compactness", or in other words, elements with good aspect ratio are generated.
Efficient algorithms to construct Delaunay triangulations are not trivial, but there are a number of good libraries out there - I can recommend Triangle, CGAL or Qhull (for high dimensional problems) also JDT is apparently an implementation in Java, though I've never used it.
I am not sure it is exactly what you are looking for, but it may be of some help: Graph Theory
I am also attempting to solve this problem. This is a link to the github branch of someone who works on this for the game Ingress, which is why I'm interested in the solution. However, to my knowledge the optimal solution is found through brute force (I may be wrong on this), and has other factors it maximizes and minimizes. Also I think there are things such as taking in an E6 latitude/longitude and projects onto a Gnomonic projection to determine shortest routes, however I think this can be discounted when going through the code. I don't think there is your solution in this code, but it might be a good jumping off point for you, me, and anyone else looking into this problem.

Cluster analysis - finding the center of a cluster

I've created two clustering algorithms: k-means and divisive, maybe later I'll add aglomerative as well. I have to analyze how good they are with high dimension data, and for that I have to calculate the average/sum distance to the clusters center. In the case of k-means, it's easy, i have the centroid, but how to find the center in the divisive/aglomerative algorithm?
While I'm here: I've currently implemented Euclede's, Manhattans and Pearsons distance, are there any more distance measures which i could use?
Thanks in advance!
You may want to get this book:
Encyclopedia of distances, Michel Deza, Elena Deza, 590 pages.
which covers many of the alternate distance functions you could use.
Probably a few hundred different distances ...
However, you will also need to look into your evaluation method -- if it is centroid based, it will be biased towards k-means. So the comparison is likely unfair.
Furthermore, if you use artificial data, make sure you do not unfairly favor one method over another because the method correlates with the way you generate your data (e.g. if you generate Gaussian clusters, it favors methods such as k-means).
The goal of my work is to analyze these clusters, when they have to create clusters from data with high dimensionality. It is hard to evaluate them and it's very unlikely that the result will be completely fair, so I'm going to use the average, accumulated distance between records in one cluster and the minimal distance between two records from different clusters.
Regarding the way on how to find the center of a cluster in Hierarchical clustering algorithms - the same formula used in k-means, used to recalculate the centroid after each iteration.

Approximate Minimum Feedback Arc Set implementation in Java

I'd like to find an implementation of an approximate algorithm for the Minimum Feedback Arc Set in Java but I did not find anything so far. Does anyone have something in mind?
It appears that the simplest approximate algorithm one can implement (but with no minimality guarantees) is the one of this paper:
A fast and effective heuristic for the feedback arc set problem, by P. Eades, X. Lin, W.F. Smyth.
It is very easy to implement and works quite fast for large graphs (I tried it on a graph of 2.5 million edges and around 100 thousand nodes and broke all cycles in less than a minute).

Interpolating between Functions [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Interpolation over an array (or two)
I have a set of CSV files that contain points of a 2D function... in other words I have four CSV files, each is the result of evaluating a function f(x, y) at different y values. I need to interpolate between these data such that I can calculate an arbitrary f for a certain x and y. The CSV files have varying lengths and x-values. Does anyone know of a library or algorithm in Java for this task? Linear interpolation is OK, as is spline interpolation.
Thanks,
taktoa
Ok, first of all I assume the "CSV" bit is irrelevant, let's assume you have read those into memory and merged them together (they're the values of the same function, right?). Now you have a single set of f(x,y) values for different (x,y) pairs and would like to interpolate between those. Fine so far?
If you stick to linear interpolation, there's still the question of how many points to take into account, which will depend on the level of noise in the measurements. In the simplest case one would use just the three nearest points to identify the plane they lie in and use that to find the value for the point in question. This option requires neither libraries nor algorithms, apart from vector addition, subtraction, cross product and dot product.
More sophisticated solutions would generally require some sort of fitting, e.g. (weighted) least squares.
The simplest function is to find the closest points and use linear interpolation. e.g. chose two of three closest points and interpolate them.
Or you can take a weighted average based on distance. Or you can pick a close point and then find points on the "other side" of the closest point to improve the interpolation.
Lagrange interpolation would be simple and accurate.

Categories

Resources