// D3Vector.java // 3次元 ベクトル クラス // Copyright (C) 1996, 1997 Y.Nagatani // nagatani@eken.phys.nagoya-u.ac.jp public class D3Vector { public double x, y, z; D3Vector () { set (0,0,0); } D3Vector (double x, double y, double z) { set (x, y, z); } public D3Vector set (double x, double y, double z) { this.x = x; this.y = y; this.z = z; return this; } public D3Vector translate (D3Vector vect) { return add (vect); } public D3Vector add (D3Vector vect) { this.x += vect.x; this.y += vect.y; this.z += vect.z; return this; } public D3Vector scalar (double s) { this.x *= s; this.y *= s; this.z *= s; return this; } private D3Vector rotate (double arg, double v[]) { double sin = Math.sin (arg), cos = Math.cos (arg); double A = v[0], B = v[1]; v[0] = cos * A + sin * B; v[1] = - sin * A + cos * B; return this; } public D3Vector rotXY (double arg) { double sin = Math.sin (arg), cos = Math.cos (arg); double A = x, B = y; x = cos * A + sin * B; y = - sin * A + cos * B; return this; } public D3Vector rotYZ (double arg) { double v[] = {y, z}; rotate (arg, v); y = v[0]; z = v[1]; return this; } public D3Vector rotZX (double arg) { double v[] = {z, x}; rotate (arg, v); z = v[0]; x = v[1]; return this; } }