3 /**************************************************************************
5 * Java Grande Forum Benchmark Suite - Version 2.0 *
9 * Java Grande Benchmarking Project *
13 * Edinburgh Parallel Computing Centre *
15 * email: epcc-javagrande@epcc.ed.ac.uk *
17 * Original version of this code by *
18 * Florian Doyon (Florian.Doyon@sophia.inria.fr) *
19 * and Wilfried Klauser (wklauser@acm.org) *
21 * This version copyright (c) The University of Edinburgh, 1999. *
22 * All rights reserved. *
24 **************************************************************************/
30 * This class reflects the 3d vectors used in 3d computations
33 //implements java.io.Serializable
53 * @param a the x coordinate
54 * @param b the y coordinate
55 * @param c the z coordinate
57 public Vec(float a, float b, float c) {
72 * Default (0,0,0) constructor
81 * Add a vector to the current vector
82 * @param: a The vector to be added
84 public final void add(Vec a) {
91 * adds: Returns a new vector such as
94 public static Vec adds(float s, Vec a, Vec b) {
95 return new Vec(s * a.x + b.x, s * a.y + b.y, s * a.z + b.z);
99 * Adds vector such as:
101 * @param: s The multiplier
102 * @param: b The vector to be added
104 public final void adds(float s,Vec b){
111 * Substracs two vectors
113 public static Vec sub(Vec a, Vec b) {
114 return new Vec(a.x - b.x, a.y - b.y, a.z - b.z);
118 * Substracts two vects and places the results in the current vector
119 * Used for speedup with local variables -there were too much Vec to be gc'ed
120 * Consumes about 10 units, whether sub consumes nearly 999 units!!
121 * cf thinking in java p. 831,832
123 public final void sub2(Vec a,Vec b) {
129 public static Vec mult(Vec a, Vec b) {
130 return new Vec(a.x * b.x, a.y * b.y, a.z * b.z);
133 public static Vec cross(Vec a, Vec b) {
135 new Vec(a.y*b.z - a.z*b.y,
140 public static float dot(Vec a, Vec b) {
141 return a.x*b.x + a.y*b.y + a.z*b.z;
144 public static Vec comb(float a, Vec A, float b, Vec B) {
146 new Vec(a * A.x + b * B.x,
151 public final void comb2(float a,Vec A,float b,Vec B) {
157 public final void scale(float t) {
163 public final void negate() {
169 public final float normalize() {
171 len =(float) Math.sqrt(x*x + y*y + z*z);
180 public final String toString() {
181 return "<" + x + "," + y + "," + z + ">";