next up previous contents
Next: Fixed size vector addition Up: Fixed size vectors Previous: Fixed size vectors   Contents

Creating and accessing fixed size vectors

Single fixed size vectors are such simple objects, it makes sense to normally use declare structure variables directly, rather than use pointers to structures created by malloc(). So to create a double precision 3-vector, use the declaration
      Gan_Vector3 v3x;
From now on, we shall describe the functions for double precision vectors only. Single precision functions are very similar and will be explained below. Setting the coordinates of a 3-vector can be achieved by one of
  1. Initialising the 3-vector when it is created, as in
          Gan_Vector3 v3x = {1.0, 2.0, 3.0};
    

  2. Accessing the structure elements directly:
          v3x.x = 1.0; v3x.y = 2.0; v3x.z = 3.0;
    
  3. Using the macro call
          gan_vec3_fill_q ( &v3x, 1.0, 2.0, 3.0 );
    
    Note that the Gnu C compiler prints a warning when the above call is compiled, and also for most other similar calls in the linear algebra package. This warning can be avoided by inserting an initial (void) cast:
          (void)gan_vec3_fill_q ( &v3x, 1.0, 2.0, 3.0 );
    
    We omit this cast in the following to keep the exposition simple.
  4. The equivalent function call
          v3x = gan_vec3_fill_s ( 1.0, 2.0, 3.0 );
    
Setting a 3-vector to zero can be accomplished using one of the calls
      gan_vec3_zero_q ( &v3x ); /* macro, OR */
      v3x = gan_vec3_zero_s(); /* function call */

Copying 3-vectors can be accomplished either by direct assignment

      Gan_Vector3 v3y;

      v3y = v3x;
or by use of the one of the routines
      gan_vec3_copy_q ( &v3x, &v3y ); /* macro, OR */
      v3y = gan_vec3_copy_s ( &v3x ); /* function call */


next up previous contents
Next: Fixed size vector addition Up: Fixed size vectors Previous: Fixed size vectors   Contents
2006-03-17