1 /**************************************************************************
3 * Java Grande Forum Benchmark Suite - Version 2.0 *
7 * Java Grande Benchmarking Project *
11 * Edinburgh Parallel Computing Centre *
13 * email: epcc-javagrande@epcc.ed.ac.uk *
15 * Original version of this code by *
16 * Florian Doyon (Florian.Doyon@sophia.inria.fr) *
17 * and Wilfried Klauser (wklauser@acm.org) *
19 * This version copyright (c) The University of Edinburgh, 1999. *
20 * All rights reserved. *
22 **************************************************************************/
28 * This class reflects the 3d vectors used in 3d computations
31 //implements java.io.Serializable
51 * @param a the x coordinate
52 * @param b the y coordinate
53 * @param c the z coordinate
55 public Vec(double a, double b, double c) {
70 * Default (0,0,0) constructor
79 * Add a vector to the current vector
80 * @param: a The vector to be added
82 public final void add(Vec a) {
89 * adds: Returns a new vector such as
92 public static Vec adds(double s, Vec a, Vec b) {
93 return new Vec(s * a.x + b.x, s * a.y + b.y, s * a.z + b.z);
97 * Adds vector such as:
99 * @param: s The multiplier
100 * @param: b The vector to be added
102 public final void adds(double s,Vec b){
109 * Substracs two vectors
111 public static Vec sub(Vec a, Vec b) {
112 return new Vec(a.x - b.x, a.y - b.y, a.z - b.z);
116 * Substracts two vects and places the results in the current vector
117 * Used for speedup with local variables -there were too much Vec to be gc'ed
118 * Consumes about 10 units, whether sub consumes nearly 999 units!!
119 * cf thinking in java p. 831,832
121 public final void sub2(Vec a,Vec b) {
127 public static Vec mult(Vec a, Vec b) {
128 return new Vec(a.x * b.x, a.y * b.y, a.z * b.z);
131 public static Vec cross(Vec a, Vec b) {
133 new Vec(a.y*b.z - a.z*b.y,
138 public static double dot(Vec a, Vec b) {
139 return a.x*b.x + a.y*b.y + a.z*b.z;
142 public static Vec comb(double a, Vec A, double b, Vec B) {
144 new Vec(a * A.x + b * B.x,
149 public final void comb2(double a,Vec A,double b,Vec B) {
155 public final void scale(double t) {
161 public final void negate() {
167 public final double normalize() {
169 len = Math.sqrt(x*x + y*y + z*z);
178 public final String toString() {
179 return "<" + x + "," + y + "," + z + ">";