// Position.java by David Binger <binger@centre.edu>
// Copyright (C) 1997 David Binger
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, 
// Boston, MA  02111-1307, USA.

// Version 2.1



import java.io.*;

public class Position
implements Serializable {

  public double x,y,z;

  private void writeObject(ObjectOutputStream out)
  throws IOException {
    out.writeDouble(x);
    out.writeDouble(y);
    out.writeDouble(z);
  }

  private void readObject(ObjectInputStream in)
  throws IOException, ClassNotFoundException {
    x = in.readDouble();
    y = in.readDouble();
    z = in.readDouble();
  }

  public Position(double a,double b,double c) {
    x = a; y = b; z = c;
  }

  public Position(double a,double b) {
    x = a; y = b; z = 0;
  }  

  public final int x() { return (int)x; }

  public final int y() { return (int)y; }

  public final static double dot(Position a,Position b) {
    return a.x*b.x+a.y*b.y+a.z*b.z;
  }

  public final double length() {
    return Math.sqrt(x*x+y*y+z*z);
  }

  public static final double distance(Position a,Position b) {
    double x = a.x-b.x;
    double y = a.y-b.y;
    double z = a.z-b.z;
    return Math.sqrt(x*x+y*y+z*z);
  }

  public final void normalize() {
    double len = length();
    x /= len;
    y /= len;
    z /= len;
  }

  public String toString() {
      // String s = x+" "+y+" "+z;
    String s = x+" "+y;
    return "(Position "+s+" )";
  }


}








