import javax.vecmath.*; import java.util.*; // Vector class ParametricCurve { Vector pointList; Vector timeList; float epsilon; float t0; float t1; Function3f fun; public ParametricCurve ( float tZero, float tOne, float e, Function3f f ) { t0 = tZero; t1 = tOne; epsilon = e; fun = f; timeList = new Vector(64); timeList.addElement( new Float(t0) ); pointList = new Vector(64); Vector3f v = fun.valueAt(t0); pointList.addElement( v ); buildVector ( t1 ); } public void buildVector ( float t1 ) { float t0 = ((Float)timeList.lastElement()).floatValue(); while ( Math.abs ( t1 - t0 ) >= epsilon ) { buildVector ( (t0 + t1)/2 ); t0 = ((Float)timeList.lastElement()).floatValue(); } Vector3f v0 = (Vector3f)pointList.lastElement(); t0 = ((Float)timeList.lastElement()).floatValue(); Vector3f v1 = fun.valueAt(t1); while ( ! v1.epsilonEquals( v0, epsilon ) ) { buildVector ( (t0 + t1)/2 ); t0 = ((Float)timeList.lastElement()).floatValue(); v0 = (Vector3f)pointList.lastElement(); } timeList.addElement(new Float(t1)); pointList.addElement(v1); } public void print () { Enumeration p = pointList.elements(); Enumeration t = timeList.elements(); while ( p.hasMoreElements() ) { float f = ((Float) t.nextElement()).floatValue(); Vector3f v = (Vector3f) p.nextElement(); System.out.println ( "t = " + f + " v = " + v.toString() ); } } public void draw ( WireMesh w ) { Enumeration p = pointList.elements(); if ( !p.hasMoreElements() ) return; Vector3f next = (Vector3f) p.nextElement(); while ( p.hasMoreElements() ) { Vector3f prev = next; next = (Vector3f) p.nextElement(); w.lineVector3f ( prev, next ); } } public static void main ( String[] args ) { Function3f function = new Helix ( 1, 1 ); ParametricCurve p = new ParametricCurve ( 0, 3, 0.25f, function ); p.print(); } }