next up previous contents
Next: Fixed size matrices Up: Fixed size vectors Previous: Other sizes of fixed   Contents

Setting/extracting parts of fixed size vectors

Apart from the cross product routines gan_vec3_cross_[qs]() defined only for 3-vectors, there are a few other miscellaneous routines which apply to a subset of the fixed size vectors. These routines enable setting or extracting parts of a fixed size vector using another fixed size with a different size. The most comprehensive set of such routines is for vectors of size four. So for instance to extract the first three elements of a 4-vector and write them into a 3-vector, use
      Gan_Vector3 v3x;
      Gan_Vector4 v4x;

      gan_vec4_fill_q ( &v4x, 1.0, 2.0, 3.0, 4.0 );
      gan_vec4_get_v3t_q ( &v4x, &v3x ); /* macro */
or alternatively
      v3x = gan_vec4_get_v3t_s ( &v4x ); /* function */
both of which set v3x to {1.0, 2.0, 3.0}. To build a 4-vector from a 3-vector and a scalar use
      gan_vec3_fill_q ( &v3x, 1.0, 2.0, 3.0 );
      gan_vec4_set_parts_q ( &v4x, &v3x, 4.0 ); /* macro */
or alternatively
      v4x = gan_vec4_set_parts_s ( &v3x, 4.0 ); /* function */
both of which set v4x to {1.0, 2.0, 3.0, 4.0}. To build a 4-vector from two 2-vectors use
      Gan_Vector3 v2xt, v2xb;
      Gan_Vector4 v4x;

      gan_vec2_fill_q ( &v2xt,  1.0, 2.0 );
      gan_vec2_fill_q ( &v2xb, 3.0, 4.0 );
      gan_vec4_set_blocks_q ( &v4x, &v2xt, &v2xb ); /* macro */
(note that the ``t'' and ``b'' in v2xt and v2xb stand for the ``top'' and ``bottom'' parts of vector ${\bf x}$), or alternatively
      v4x = gan_vec4_set_blocks_s ( &v2xt, &v2xb ); /* function */
both of which again set v4x to {1.0, 2.0, 3.0, 4.0}.

For 3-vectors the equivalent set of functions involves splitting the 3-vector into the x,y coordinates as a 2-vector and z as the scalar. Then we have

      Gan_Vector2 v2xt;
      Gan_Vector3 v3x;

      gan_vec3_fill_q ( &v3x, 1.0, 2.0, 3.0 );
      gan_vec3_get_v2t_q ( &v3x, &v2xt ); /* macro, or */
      v2xt = gan_vec3_get_v2t_s ( &v3x ); /* function */
the last two lines of which both set v2xt to {1.0, 2.0}. To build a 3-vector from a 2-vector and a scalar use
      gan_vec2_fill_q ( &v2xt, 1.0, 2.0 );
      gan_vec3_set_parts_q ( &v3x, &v2xt, 3.0 ); /* macro, or */
      v3x = gan_vec3_set_parts_s ( &v2xt, 3.0 ); /* function */
both of which set v3x to {1.0, 2.0, 3.0}.


next up previous contents
Next: Fixed size matrices Up: Fixed size vectors Previous: Other sizes of fixed   Contents
2006-03-17