next up previous contents
Next: 3D Vector Algebra Functions Up: Tina Maths Library Previous: Random Variables   Contents

2D and 3D vector geometry

2D and 3D geometry is quite fundamental to the model based approach to computer vision and even when algorithms are not specifically model based they are still often a compact way to construct and implement an algorithm. In Tina vectors are represented as structures, for example a 3-vector is defined as:

typedef struct vec3
{
    Ts_id ts_id;                /* Tina structure identifier */
    float   el[3];
}       Vec3;

The internal structure should not be used. The x-component of a 3-vector should be got and set using statements like:

vx = vec3_x(v);

and

vec3_x(v) = vx;

(this is allowed since vec3_x() is a macro).

A 3-vector with given components can be constructed using the function vec3(), e.g.

v = vec3(1.0, 2.0, 3.0);

A fairly complete set of vector algebra and geometry functions is provided, look before you write your own. Most of these functions pass arguments by value and return a structure. Though there is a slight overhead in passing a structure rather than a pointer the advantage is that translating vector algebra into code can be almost transparent. For example a function to find the component of a vector u perpendicular to a unit vector v

p = u-(u.v)v

can be defined by

Vec3    vec3_projperp(Vec3 u, Vec3 v)  /**component of  u  perpendicular
                                                                 to unit  v**/
{
    return (vec3_diff(u, vec3_times(vec3_dot(u, v), v)));
}

Occasionally 2-vectors with integer components are needed (e.g. to represent positions on a graphics window). A structure Ipos (integer position) is provided to deal with this, together with a limited set of functions to manipulate them.



Subsections
next up previous contents
Next: 3D Vector Algebra Functions Up: Tina Maths Library Previous: Random Variables   Contents
root 2017-11-18