001 package edu.isi.gamebots.examples; 002 003 import java.lang.*; 004 005 import edu.isi.gamebots.client.Bot; 006 import edu.isi.gamebots.examples.*; 007 008 009 /** 010 * Vector3D is a 3 by 1 matrix (or is that 1 by 3?). The 'D' in Vector3D stands 011 * for Double, not dimension. This class is based off of a class in the 012 * javax.vecmath library. Since I didn't think everyone wanted to install an 013 * entire library just for these example implementations, I recreate it here. 014 */ 015 public class Vector3D implements Cloneable { 016 // Public Data 017 public double x; 018 public double y; 019 public double z; 020 021 // Public Methods 022 /////////////////////////////////////////////////////////////////////////// 023 public Vector3D() { 024 } 025 026 public Vector3D( double x, double y, double z ) { 027 this.x = x; 028 this.y = y; 029 this.z = z; 030 } 031 032 public Vector3D( Vector3D vec ) { 033 x = vec.x; 034 y = vec.y; 035 z = vec.z; 036 } 037 038 public boolean near( Vector3D loc, double delta ) { 039 return near( loc.x, loc.y, loc.z, delta ); 040 } 041 042 public boolean near( double x, double y, double z, double delta ) { 043 double d, dist; 044 045 d = x-this.x; 046 dist = d*d; 047 d = y-this.y; 048 dist += d*d; 049 d = z-this.z; 050 dist += d*d; 051 052 return dist < delta*delta; 053 /* // Old code: 2delta Cube 054 delta = Math.abs( delta ); 055 return (Math.abs(x-this.x)<delta) && 056 (Math.abs(y-this.y)<delta) && 057 (Math.abs(z-this.z)<delta); 058 */ 059 } 060 061 public String toString() { 062 return x+","+y+","+z; 063 } 064 }