1
6 class Vect implements java.io.Serializable {
7
8 private static final long serialVersionUID = Version.getSUID();
9
10 public double X[];
11
12
13
14 public Vect() {X=new double[3];}
15
16 public Vect(double x, double y, double z) {
17 X = new double[3];
18 X[0] = x;
19 X[1] = y;
20 X[2] = z;
21 }
22
23 public Vect(Vect old) {
24 X = new double[3];
25 X[0] = old.X[0];
26 X[1] = old.X[1];
27 X[2] = old.X[2];
28 }
29
30 public void copyVal(Vect old) {
31 X[0] = old.X[0];
32 X[1] = old.X[1];
33 X[2] = old.X[2];
34 }
35
36 static Vect cross(Vect A,Vect B) {
37 return(new Vect(A.X[1]*B.X[2]-A.X[2]*B.X[1],
38 A.X[2]*B.X[0]-A.X[0]*B.X[2],
39 A.X[0]*B.X[1]-A.X[1]*B.X[0]));
40 }
41 static double dot(Vect A,Vect B) {
42 return(A.X[0]*B.X[0] + A.X[1]*B.X[1] + A.X[2]*B.X[2]);
43 }
44 public double mag() {
45 return(Math.sqrt(dot(this,this)));
46 }
47 public void print() {
48 System.out.println("("+X[0]+" "+X[1]+" "+X[2]+")");
49 }
50
51 public String toString() {
52 return("("+X[0]+" "+X[1]+" "+X[2]+")");
53 }
54
55 public void scale(double s) {
56 X[0]*=s;
57 X[1]*=s;
58 X[2]*=s;
59 }
60
61 public double hdist(Vect other) {
62 return(Math.sqrt((this.X[0]-other.X[0])*(this.X[0]-other.X[0]) +
63 (this.X[1]-other.X[1])*(this.X[1]-other.X[1])));
64 }
65
66 public double vdist(Vect other) {
67 double res = this.X[2] - other.X[2];
68 return((res>0?res:-res));
69 }
70
71 public boolean equals(Object o) {
72 return(X[0]==((Vect)o).X[0] && X[1]==((Vect)o).X[1] && X[2]==((Vect)o).X[2]);
73 }
74 }
75
76
77