Vectors and matrices

Name

Vectors and matrices -- simple operations on vectors and matrices.

Synopsis


#include <gts.h>



#define     gts_vector_init                 (v, p1, p2)
#define     gts_vector_scalar               (v1, v2)
#define     gts_vector_cross                (C,A,B)
#define     gts_vector_norm                 (v)
#define     gts_vector_normalize            (v)
void        gts_vector_print                (GtsVector v,
                                             FILE *fptr);
void        gts_vector4_print               (GtsVector4 v,
                                             FILE *fptr);

typedef     GtsMatrix;

GtsMatrix*  gts_matrix_new                  (gdouble a00,
                                             gdouble a01,
                                             gdouble a02,
                                             gdouble a03,
                                             gdouble a10,
                                             gdouble a11,
                                             gdouble a12,
                                             gdouble a13,
                                             gdouble a20,
                                             gdouble a21,
                                             gdouble a22,
                                             gdouble a23,
                                             gdouble a30,
                                             gdouble a31,
                                             gdouble a32,
                                             gdouble a33);
void        gts_matrix_assign               (GtsMatrix *m,
                                             gdouble a00,
                                             gdouble a01,
                                             gdouble a02,
                                             gdouble a03,
                                             gdouble a10,
                                             gdouble a11,
                                             gdouble a12,
                                             gdouble a13,
                                             gdouble a20,
                                             gdouble a21,
                                             gdouble a22,
                                             gdouble a23,
                                             gdouble a30,
                                             gdouble a31,
                                             gdouble a32,
                                             gdouble a33);
GtsMatrix*  gts_matrix_zero                 (GtsMatrix *m);
GtsMatrix*  gts_matrix_identity             (GtsMatrix *m);
GtsMatrix*  gts_matrix_projection           (GtsTriangle *t);
GtsMatrix*  gts_matrix_scale                (GtsMatrix *m,
                                             GtsVector s);
GtsMatrix*  gts_matrix_translate            (GtsMatrix *m,
                                             GtsVector t);
GtsMatrix*  gts_matrix_rotate               (GtsMatrix *m,
                                             GtsVector r,
                                             gdouble angle);
GtsMatrix*  gts_matrix_transpose            (GtsMatrix *m);
gdouble     gts_matrix_determinant          (GtsMatrix *m);
GtsMatrix*  gts_matrix_inverse              (GtsMatrix *m);
GtsMatrix*  gts_matrix3_inverse             (GtsMatrix *m);
GtsMatrix*  gts_matrix_product              (GtsMatrix *m1,
                                             GtsMatrix *m2);
guint       gts_matrix_compatible_row       (GtsMatrix *A,
                                             GtsVector b,
                                             guint n,
                                             GtsVector A1,
                                             gdouble b1);
guint       gts_matrix_quadratic_optimization
                                            (GtsMatrix *A,
                                             GtsVector b,
                                             guint n,
                                             GtsMatrix *H,
                                             GtsVector c);
void        gts_matrix_print                (GtsMatrix *m,
                                             FILE *fptr);
void        gts_matrix_destroy              (GtsMatrix *m);

Description

The functions described in this section allow to perform simple transformations on point coordinates. In particular projection onto a plane passing through the vertices of a given triangle or quadratic optimization problems.

Details

gts_vector_init()

#define     gts_vector_init(v, p1, p2)

Given two points p1 and p2, fills v with the coordinates of vector p1->p2.

v :

a GtsVector.

p1 :

a GtsPoint.

p2 :

another GtsPoint.


gts_vector_scalar()

#define     gts_vector_scalar(v1, v2)

Given two vectors v1 and v2 evaluates to the scalar product v1.v2.

v1 :

a GtsVector.

v2 :

another GtsVector.


gts_vector_cross()

#define     gts_vector_cross(C,A,B)

Given two vectors A and B fills C with the coordinates of the cross-product A^B.

C :

a GtsVector.

A :

another GtsVector.

B :

and another.


gts_vector_norm()

#define     gts_vector_norm(v)

v :


gts_vector_normalize()

#define     gts_vector_normalize(v)

v :


gts_vector_print ()

void        gts_vector_print                (GtsVector v,
                                             FILE *fptr);

Print s to file fptr.

v :

a GtsVector.

fptr :

a file descriptor.


gts_vector4_print ()

void        gts_vector4_print               (GtsVector4 v,
                                             FILE *fptr);

Print v to file fptr.

v :

a GtsVector4.

fptr :

a file descriptor.


GtsMatrix

typedef GtsVector4               GtsMatrix;

A GtsMatrix is a 3x3 matrix.


gts_matrix_new ()

GtsMatrix*  gts_matrix_new                  (gdouble a00,
                                             gdouble a01,
                                             gdouble a02,
                                             gdouble a03,
                                             gdouble a10,
                                             gdouble a11,
                                             gdouble a12,
                                             gdouble a13,
                                             gdouble a20,
                                             gdouble a21,
                                             gdouble a22,
                                             gdouble a23,
                                             gdouble a30,
                                             gdouble a31,
                                             gdouble a32,
                                             gdouble a33);

Allocates memory and initializes a new GtsMatrix.

a00 :

element [0][0].

a01 :

element [0][1].

a02 :

element [0][2].

a03 :

element [0][3].

a10 :

element [1][0].

a11 :

element [1][1].

a12 :

element [1][2].

a13 :

element [1][3].

a20 :

element [2][0].

a21 :

element [2][1].

a22 :

element [2][2].

a23 :

element [2][3].

a30 :

element [3][0].

a31 :

element [3][1].

a32 :

element [3][2].

a33 :

element [3][3].

Returns :

a pointer to the newly created GtsMatrix.


gts_matrix_assign ()

void        gts_matrix_assign               (GtsMatrix *m,
                                             gdouble a00,
                                             gdouble a01,
                                             gdouble a02,
                                             gdouble a03,
                                             gdouble a10,
                                             gdouble a11,
                                             gdouble a12,
                                             gdouble a13,
                                             gdouble a20,
                                             gdouble a21,
                                             gdouble a22,
                                             gdouble a23,
                                             gdouble a30,
                                             gdouble a31,
                                             gdouble a32,
                                             gdouble a33);

Set values of matrix elements.

m :

a GtsMatrix.

a00 :

element [0][0].

a01 :

element [0][1].

a02 :

element [0][2].

a03 :

element [0][3].

a10 :

element [1][0].

a11 :

element [1][1].

a12 :

element [1][2].

a13 :

element [1][3].

a20 :

element [2][0].

a21 :

element [2][1].

a22 :

element [2][2].

a23 :

element [2][3].

a30 :

element [3][0].

a31 :

element [3][1].

a32 :

element [3][2].

a33 :

element [3][3].


gts_matrix_zero ()

GtsMatrix*  gts_matrix_zero                 (GtsMatrix *m);

Initializes m to zeros. Allocates a matrix if m is NULL.

m :

a GtsMatrix or $NULL.

Returns :

the zero'ed matrix.


gts_matrix_identity ()

GtsMatrix*  gts_matrix_identity             (GtsMatrix *m);

Initializes m to an identity matrix. Allocates a matrix if m is NULL.

m :

a GtsMatrix or NULL.

Returns :

the identity matrix.


gts_matrix_projection ()

GtsMatrix*  gts_matrix_projection           (GtsTriangle *t);

Creates a new GtsMatrix representing the projection onto a plane of normal given by t.

t :

a GtsTriangle.

Returns :

a pointer to the newly created GtsMatrix.


gts_matrix_scale ()

GtsMatrix*  gts_matrix_scale                (GtsMatrix *m,
                                             GtsVector s);

Initializes m to a scaling matrix for s. Allocates a matrix if m is NULL.

m :

a GtsMatrix or NULL.

s :

the scaling vector.

Returns :

the scaling matrix.


gts_matrix_translate ()

GtsMatrix*  gts_matrix_translate            (GtsMatrix *m,
                                             GtsVector t);

Initializes m to a translation matrix for t. Allocates a new matrix if m is NULL.

m :

a GtsMatrix or NULL.

t :

the translation vector.

Returns :

the translation matix.


gts_matrix_rotate ()

GtsMatrix*  gts_matrix_rotate               (GtsMatrix *m,
                                             GtsVector r,
                                             gdouble angle);

Initializes m to a rotation matrix around r by angle. Allocates a new matrix if m is NULL.

m :

a GtsMatrix or NULL.

r :

the rotation axis.

angle :

the angle (in radians) to rotate by.

Returns :

the rotation matrix.


gts_matrix_transpose ()

GtsMatrix*  gts_matrix_transpose            (GtsMatrix *m);

m :

a GtsMatrix.

Returns :

a pointer to a newly created GtsMatrix transposed of m.


gts_matrix_determinant ()

gdouble     gts_matrix_determinant          (GtsMatrix *m);

m :

a GtsMatrix.

Returns :

the value of det(m).


gts_matrix_inverse ()

GtsMatrix*  gts_matrix_inverse              (GtsMatrix *m);

m :

a GtsMatrix.

Returns :

a pointer to a newly created GtsMatrix inverse of m or NULL if m is not invertible.


gts_matrix3_inverse ()

GtsMatrix*  gts_matrix3_inverse             (GtsMatrix *m);

m :

a 3x3 GtsMatrix.

Returns :

a pointer to a newly created 3x3 GtsMatrix inverse of m or NULL if m is not invertible.


gts_matrix_product ()

GtsMatrix*  gts_matrix_product              (GtsMatrix *m1,
                                             GtsMatrix *m2);

m1 :

a GtsMatrix.

m2 :

another GtsMatrix.

Returns :

a new GtsMatrix, product of m1 and m2.


gts_matrix_compatible_row ()

guint       gts_matrix_compatible_row       (GtsMatrix *A,
                                             GtsVector b,
                                             guint n,
                                             GtsVector A1,
                                             gdouble b1);

Given a system of n constraints A.x=b adds to it the compatible constraints defined by A1.x=b1. The compatibility is determined by insuring that the resulting system is well-conditioned (see Lindstrom and Turk (1998, 1999)).

A :

a GtsMatrix.

b :

a GtsVector.

n :

the number of previous constraints of A.x=b.

A1 :

a GtsMatrix.

b1 :

a GtsVector.

Returns :

the number of constraints of the resulting system.


gts_matrix_quadratic_optimization ()

guint       gts_matrix_quadratic_optimization
                                            (GtsMatrix *A,
                                             GtsVector b,
                                             guint n,
                                             GtsMatrix *H,
                                             GtsVector c);

Solve a quadratic optimization problem: Given a quadratic objective function f which can be written as: f(x) = x^t.H.x + c^t.x + k, where H is the symmetric positive definite Hessian of f and k is a constant, find the minimum of f subject to the set of n prior linear constraints, defined by the first n rows of A and b (A.x = b). The new constraints given by the minimization are added to A and b only if they are linearly independent as determined by gts_matrix_compatible_row().

A :

a GtsMatrix.

b :

a GtsVector.

n :

the number of constraints (must be smaller than 3).

H :

a symmetric positive definite Hessian.

c :

a GtsVector.

Returns :

the new number of constraints defined by A and b.


gts_matrix_print ()

void        gts_matrix_print                (GtsMatrix *m,
                                             FILE *fptr);

Print m to file fptr.

m :

a GtsMatrix.

fptr :

a file descriptor.


gts_matrix_destroy ()

void        gts_matrix_destroy              (GtsMatrix *m);

Free all the memory allocated for m.

m :

a GtsMatrix.