

public class Point3D{

	float[] point3D;
	float x, y, z;

	// Constructors

	public Point3D(){
		// Constructs a 0 point (0, 0, 0, 1)
		point3D = new float[4];
		for (int i = 0; i < 3; i++){
			point3D[i] = 0;
		}
		point3D[3] = 1;
		x=0; y=0; z=0;
	}

	public Point3D(float ax, float ay, float az){
		// Constructs point (x, y, z, 1)
		x = ax;
		y = ay;
		z = az;
		point3D = new float[4];
		point3D[0] = x;
		point3D[1] = y;
		point3D[2] = z;
		point3D[3] = 1;
	}
	
	public Point3D(Point3D p) {
        copy(p);
    }
    

	// Acessors

	public void setX(float ax){
	   x = ax;
		point3D[0] = x;
	}

	public void setY(float ay){
	   y = ay;
		point3D[1] = y;
	}

	public void setZ(float az){
	   z = az;
		point3D[2] = z;
	}
	
	public void setW(float w){
		point3D[3] = w;
	}

	public float getX(){
		return point3D[0];
	}

	public float getY(){
		return point3D[1];
	}

	public float getZ(){
		return point3D[2];
	}

	public float getW(){
		return 1;
	}

	public void set(int index, float value){
		point3D[index] = value;
		if (index == 0) x = value;
		if (index == 1) y = value;
		if (index == 2) z = value;
	}

	public float get(int index){
		return point3D[index];
	}

   
   public void copy(Point3D p) {
      point3D = new float[4];
		point3D[0] = p.getX();
		point3D[1] = p.getY();
		point3D[2] = p.getZ();
		x = p.x;
		y = p.y;
		z = p.z;
		point3D[3] = 1;
    }

	
	public String toString()
	{
		return "(" + point3D[0] + ", " + point3D[1] + ", " + point3D[2] + ")";
	} 

}
