Vector3D.java

Go to the documentation of this file.
00001 package theba.core.math;
00002 
00008 public class Vector3D {
00009         public double x, y, z;
00010 
00011         public Vector3D(double x, double y, double z) {
00012                 this.x = x;
00013                 this.y = y;
00014                 this.z = z;
00015         }
00016 
00017         public Vector3D(Point3D pt) {
00018                 this.x = pt.x;
00019                 this.y = pt.y;
00020                 this.z = pt.z;
00021         }
00022 
00023         @Override
00024         public String toString() {
00025                 return (float) x + "," + (float) y + "," + (float) z;
00026         }
00027 
00028         public double distanceFrom(Point3D p2) {
00029                 double a = x - p2.x;
00030                 double b = y - p2.y;
00031                 double c = z - p2.z;
00032 
00033                 return (Math.sqrt(a * a + b * b + c * c));
00034         }
00035 
00036         public void normalize() {
00037                 double length = distanceFrom(new Point3D(0, 0, 0));
00038                 x /= length;
00039                 y /= length;
00040                 z /= length;
00041         }
00042 }

Generated on Fri Nov 13 08:57:07 2009 for Theba by  doxygen 1.6.1