Skip to Main Content

IndexedLineArray problem

843799Nov 20 2001 — edited Nov 21 2001
In my application, I am creating an IndexedLineArray which represents a cubic 3d curve. However, when the curve is drawn, as well as showing the 3d curve correctly, a straight line is drawn from the first point to the last. Any ideas why? Should this happen? If so, is there any way to stop it?
The code is as follows:
import javax.media.j3d.*;
import javax.vecmath.*;
import java.lang.Math.*;

public class CubicCurve3D extends Shape3D{

	public CubicCurve3D(Point3d p1, Point3d p2, Point3d p3, Point3d p4){

		this.setGeometry(createGeometry(p1,p2,p3,p4));
	}

	public Geometry createGeometry(Point3d p1, Point3d p2, Point3d p3, Point3d p4){

		// setup the IndexedLineArray to represent the point
		IndexedLineArray curveLine = new IndexedLineArray(76, GeometryArray.COORDINATES, 76);
		// Add vertices to the array
		setupLineArray(p1,p2,p3,p4,curveLine);

		return curveLine;


	}

	// This method adds the vertices into the array
	public void setupLineArray(Point3d p1, Point3d p2, Point3d p3, Point3d p4, IndexedLineArray curve){

		int currPos = 0;

		for(double i = 0; i < 0.75; i = i + 0.01){

			// Work out point
			double nx, ny, nz, u;
			u = i/0.75;
			// Equations to work out point
			nx = ((p1.x)*Math.pow((1-u),3.0)) + ((p2.x)*(3*u)*Math.pow((1-u),2.0)) + ((p3.x)*(3*u*u)*(1-u)) + ((p4.x)*Math.pow(u,3.0));
			ny = ((p1.y)*Math.pow((1-u),3.0)) + ((p2.y)*(3*u)*Math.pow((1-u),2.0)) + ((p3.y)*(3*u*u)*(1-u)) + ((p4.y)*Math.pow(u,3.0));
			nz = ((p1.z)*Math.pow((1-u),3.0)) + ((p2.z)*(3*u)*Math.pow((1-u),2.0)) + ((p3.z)*(3*u*u)*(1-u)) + ((p4.z)*Math.pow(u,3.0));
			Point3d p = new Point3d(nx,ny,nz);

			// Put point into IndexedLineArray
			try{
				curve.setCoordinate(currPos,p);
				curve.setCoordinateIndex(currPos,currPos);
			}  catch (Exception e) {
			System.out.println("Exception when currPoss = " + currPos + ", i = " + i);
			}

			currPos++;
		}

	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked due to inactivity on Dec 19 2001
Added on Nov 20 2001
2 comments
32 views