i would like to know how to define the control point, here is what i do now, but it is really not efficient and the curve is not smooth.
MyPoint pointStart = list.get(0);
path.moveTo(pointStart.getLocationX(), pointStart.getLocationY());
MyPoint pointEnd = list.get(list.size() - 1);
for (int i = 1; i < list.size() - 1; i++) {
MyPoint point = list.get(i);
if (i % 3 == 0) {
MyPoint controlPoint1 = list.get(i - 2);
MyPoint controlPoint2 = list.get(i - 1);
MyPoint endPoint = point;
path.curveTo(controlPoint1.getLocationX(), controlPoint1.getLocationY(), controlPoint2.getLocationX(), controlPoint2.getLocationY(), endPoint.getLocationX(), endPoint.getLocationY());
((Graphics2D) g).draw(path);
}
}
path.lineTo(pointEnd.getLocationX(), pointEnd.getLocationY());
GeneralPath.curveTo()
uses Bézier curves, for which control points are NOT supposed to be part of the curve itself, but are here to determine the inflection of the curve at is end points (as can be seen in the curve drawn on the former Wikipedia link).
It seems what you're looking for is a spline curve which intersects all provided points. Unfortunately, this type of curve doesn't seem to be supported by Java2D. But you could probably implement it, if you have some good geometry knowledge (and with the help of Wikipedia) and some time to waste.
Another way, might be (I haven't tried it though), for a given pair of points Pi & Pi+1 to join with a curve, to determine control points based on previous and next points Pi-1 and Pi+2; might be worth investigating.