//Point 3D class
// slightly extended from original, includes some vector math.


public class Point3D {
    public float x, y, z;           // coordinates of vertex
    
    public Point3D() {
      x=y=z=0.0f;
    }
    
    public Point3D(float xval, float yval, float zval) {
        x = xval;
        y = yval;
        z = zval;
    }
    public Point3D(Point3D P) {
	x = P.x;
	y = P.y;
	z = P.z;
    }
  
  public void copy(Point3D P) {
    x = P.x; y = P.y; z = P.z;
  }
    public String toString() {
        return new String(" ["+x+", "+y+", "+z+"]");
    }
    
    //some vector algebra:
    public void incr(Point3D b) {
    	x += b.x; y+= b.y; z+=b.z;
    }
    
    public Point3D plus(Point3D b) {
    	Point3D P = new Point3D(x,y,z);
    	P.incr(b);
	return P;
    }
    public Point3D minus(Point3D b) {
    	Point3D P = new Point3D(-b.x,-b.y,-b.z);
    	P.incr(this);
	return P;
    }
    public float normalize() {
    	float s = (float)Math.sqrt(x*x+y*y+z*z);
    	x/=s; y/=s; z/=s;
	return s;
    }
    public float dot(Point3D b) {
    	return (x*b.x + y*b.y + z*b.z);
    }
    public Point3D cross(Point3D b) {
    	Point3D P = new Point3D();
    	P.x = (y * b.z) - (z * b.y);
    	P.y = (z * b.x) - (x * b.z);
    	P.z = (x * b.y) - (y * b.x);
	return P;
    }
    public void scale(float f) {
    	x *= f; y *=f; z*=f;
    }
  
}


	
