How to find length of QuadCurve2D
Hi,
my requirement is as follows:
- I have QuadCurve2D with start,control and endpoint. I am able to move Curve on mouseclick. Now I want to put a point on the curve with equidistance to each other(i.e. as the curve increase these points should also be moved).
Idea which came into my mind is: Find out the length of the curve and then divide it by 3 and get the location of it.
Any good approach to do so? Will appreciate if there is any code avail
thanks
chintan
# 3
Here is an example:
--QuadLength.java--
import java.awt.geom.*;
public class QuadLength {
public static void main(String [] args) {
PathIterator iter =
(new QuadCurve2D.Double(0, 0, 100, 0, 100, 100)).getPathIterator(
null, 0.5);
double length = 0;
double [] curSeg = new double[2];
iter.currentSegment(curSeg);
iter.next();
double x0 = curSeg[0];
double y0 = curSeg[1];
while(!iter.isDone()) {
iter.currentSegment(curSeg);
length += Math.sqrt((curSeg[0] - x0)*(curSeg[0] - x0) +
(curSeg[1] - y0)*(curSeg[1] - y0));
x0 = curSeg[0];
y0 = curSeg[1];
iter.next();
}
System.out.println("Curve length:" + length);
}
}