next up previous contents index
Next: Matrices Up: Toolkit classes: MatrixVector, Previous: Toolkit classes: MatrixVector,

Vectors

 

The Vector class is a toolkit of vector functions that is used by Mirage. They are accessed using the command Vector::<function_name>(a, b, c) e.g. Vector::sub(to, from, dir);

  // Adds vectors a and b, stores the result in vector result
  // which may be one of a or b.
  static void add(vector a, vector b, vector result);

  // Add a fraction of vector a to vector b.
  //Stores result in b
  static void addfrac(double frac, vector a, vector b);

  // Subtracts vector b from vector a, stores the result in 
  // vector result which may be one of a or b.
  static void sub(vector a, vector b, vector result);

  // Calculates the scalar dot product of two vectors a and b
  static double dot(vector a, vector b);

  // Sets vector a to equal vector b.
  static void set(vector a, vector b);

  // Assigns the given values to the vector a.
  static void assign(vector a, double xval, double yval, 
                     double zval);

  // Returns the magnitude of the vector a.
  static double magnitude(vector a);

  // Finds the minimum of two vectors on a value-by-value basis.
  // ie.  result[X] = MIN(a[X], b[X]);
  //      result[Y] = MIN(a[Y], b[Y]);
  //      result[Z] = MIN(a[Z], b[Z]);
  inline static void min(vector a, vector b, vector result);

  // Finds the maximum of two vectors on a value-by-value basis.
  inline static void max(vector a, vector b, vector result);

  // Scales a vector a by the given scalar quantity s, stores 
  //result in vector result.
  static void scale(double s, vector a, vector result);

  // Normalises a vector.
  // If the vector has length 0 this will cause an error. 
  // set msg to be a useful string which can locate where the error
  // was caused when the error message is produced.
  // Error Message: 
  // ``*** Divide by zero in <msg>, continuing...
  static void normalise(vector v, char *msg);

  // Cross product (a x b), stores result in result.
  static void cross(vector a, vector b, vector result);

  // Stretch a vector; same format as the object's stretch 
  // routine.
  static void stretch(double x, double y, double z, vector v);

  // Shift a vector; same format as the object's shift routine.
  static void shift(double x, double y, double z, vector v);

  // Rotate a vector; same format as the object's rotate routine.
  static void rotate(axis from, axis to, double angle, vector v);

  // Rotate a vector; same format as the object's rotate routine.
  static void rotate(axis around, double angle, vector v);

  // Rotate a vector; same format as the object's rotate routine.
  static void rotate(vector given_fwd, vector given_up, 
                     vector v);

  // Shear a vector; same format as the object's shear routine.
  static void shear(axis from, axis to, double amount, vector v);



Sophie Day
Fri Feb 20 15:47:19 NZDT 1998