/* 6.837 Project #3
 * Russell Sammon
 * 11/1/98
 */

import java.lang.Math;
import java.awt.*;
import java.io.*;

public class Point3D {
  float x;
  float y;
  float z;

  /*****************************************************************************/
  /* Constructors */
  /*****************************************************************************/
  public Point3D() {
  };
  
  public Point3D(float initx, float inity, float initz) {
    x=initx;
    y=inity;
    z=initz;
  }
  
  public Point3D(Point3D copy) {
    x= copy.x;
    y= copy.y;
    z= copy.z;
  }


  /*****************************************************************************/
  /* Basic Methods */
  /*****************************************************************************/
  public String toString() {
    return new String(" ["+x+", "+y+", "+z+"]");
  }

  public void set(int i, float value) {
    //set element i to value
    if (i==0) x=value;
    else if (i==1) y=value;
    else if (i==2) z=value;
  }


  public float get(int i) {
    // return element i
    if (i==0) return(x);
    else if (i==1) return(y);
    else if (i==2) return(z);
    else return(0);
  }

  public void copy (Point3D original) {
    x= original.x;
    y= original.y;
    z= original.z;
  }
  
  public void print() {
    System.out.println("("+x+", "+y+", "+z+")");
    }
  
  /*****************************************************************************/
  /* Vector Methods */
  /*****************************************************************************/
  public void normalize() {
    float magnitude;
    
    magnitude= (float)Math.sqrt(x*x + y*y + z*z);
    x= x/magnitude;
    y= y/magnitude;
    z= z/magnitude;
  }

  public static Point3D crossProduct (Point3D a, Point3D b) {
    //return the cross product of vectors a and b
    Point3D temp= new Point3D();
    temp.x= a.y*b.z - a.z*b.y;
    temp.y= a.z*b.x - a.x*b.z;
    temp.z= a.x*b.y - a.y*b.x;
    return(temp);
  }

  public static float dotProduct (Point3D a, Point3D b) {
    //return the dot product of vectors a and b
    return(a.x*b.x + a.y*b.y + a.z*b.z);
  }

  public void scale (float c) {
    x*=c;
    y*=c;
    z*=c;
  }

  public static Point3D subtract (Point3D a, Point3D b) {
    //SUBTRACT A FROM B     ====   B - A
    //return the difference between vectors a and b
    //equivalent to the vector that runs from point a to point b
    Point3D temp= new Point3D();
    temp.x= b.x - a.x;
    temp.y= b.y - a.y;
    temp.z= b.z - a.z;
    return(temp);    
  }
}

