c:/Users/efeyhl/devs/math2/c_vector.h File Reference

C-functions for vector operations. More...

#include "c_basic_math.h"

Go to the source code of this file.

Defines

#define MAX_VECTOR_DIM   64
 max. number of elements in a vector

Functions

BM_STATUS initDblVector (double *vector, const unsigned int dim, const double value)
 set all elements of the vector to value
BM_STATUS copyDblVector (double *dest, const double *source, const unsigned int dim)
 copy all elements of vector source to vector dest
BM_STATUS addDblVector (double *result, const double *augend, const double *addend, const unsigned int dim)
 safe vector addition
BM_STATUS subDblVector (double *result, const double *minuend, const double *subtrahend, const unsigned int dim)
 safe vector subtraction
double innerProductDblVector (const double *multiplier, const double *multiplicand, const unsigned int dim, BM_STATUS *bms)
 safe vector inner product
BM_STATUS doubleMulDblVector (double *result, const double *vector, const unsigned int dim, const double scalar)
 safe vector multiplication with a scalar
BM_STATUS doubleDivDblVector (double *result, const double *vector, const unsigned int dim, const double scalar)
 safe vector divsion with a scalar
BM_STATUS crossProductDblVector (double *result, const double *multiplier, const double *multiplicand, const unsigned int dim)
 safe vector cross product
double lengthDblVector (const double *vector, const unsigned int dim, BM_STATUS *bms)
 length of vector ( abs(vector) )
BM_STATUS invertDirectionDblVector (double *result, const double *vector, const unsigned int dim)
 invert direction of vector ( -(vector) )
int isNullDblVector (const double *vector, const unsigned int dim, BM_STATUS *bms)
 is null vector ( |vector| < MICRO (0.000001) )
int is1DblVector (const double *vector, const unsigned int dim, BM_STATUS *bms)
 is 1 vector ( |vector| == 1 )
BM_STATUS directionDblVector (double *direction, const double *vector, const unsigned int dim)
 returns the unit direction vector of vector ( |dir| == 1 )
int compareLengthDblVector (const double *vector1, const double *vector2, const unsigned int dim, BM_STATUS *bms)
 compares the length of 2 vectors ( |v1| compare |v2| )
double angleDblVector (const double *vector1, const double *vector2, const unsigned int dim, BM_STATUS *bms)
 calculates the crossing angle of 2 vectors
int isEqualDblVector (const double *vector1, const double *vector2, const unsigned int dim, BM_STATUS *bms)
 is vector1 equal vector2 ( vector1 == vector2 )
int isParallelDblVector (const double *vector1, const double *vector2, const unsigned int dim, BM_STATUS *bms)
 checks the direction of vector1 and vector2 (dir1 == dir2) or (-dir1==dir2)
int isOrthogonalDblVector (const double *vector1, const double *vector2, const unsigned int dim, BM_STATUS *bms)
 checks if vector1 is orthogonal to vector2

Detailed Description

C-functions for vector operations.

This file contains all C-style functions for safe vector operations

Author:
Eckhardt Feyhl (2010 Nov. 13)

Function Documentation

BM_STATUS addDblVector ( double *  result,
const double *  augend,
const double *  addend,
const unsigned int  dim 
)

safe vector addition

result = augend + addend

Parameters:
result [out] pointer to the destination vector's first element. Can also point to augend or addend.
augend [in] pointer to the vector's first element
addend [in] pointer to the vector's first element
dim [in] number of elements in the vectors
Returns:
basic math status informations
0 = no error
possible errors are: undef, overflow, negative
double angleDblVector ( const double *  vector1,
const double *  vector2,
const unsigned int  dim,
BM_STATUS bms 
)

calculates the crossing angle of 2 vectors

returns the angle in radiand

Parameters:
vector1 [in] pointer to the vector's first element
vector2 [in] pointer to the vector's first element
dim [in] number of elements in the vectors
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the result in double format (see above)
int compareLengthDblVector ( const double *  vector1,
const double *  vector2,
const unsigned int  dim,
BM_STATUS bms 
)

compares the length of 2 vectors ( |v1| compare |v2| )

returns -1 if |vector1| < |vector2|
returns 0 if |vector1| == |vector2|
returns 1 if |vector1| > |vector2|

Parameters:
vector1 [in] pointer to the vector's first element
vector2 [in] pointer to the vector's first element
dim [in] number of elements in the vectors
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the result of the compare (see above)
-2 if an error occured
BM_STATUS copyDblVector ( double *  dest,
const double *  source,
const unsigned int  dim 
)

copy all elements of vector source to vector dest

Parameters:
dest [out] pointer to the destination vector's first element
source [in] pointer to the source vector's first element
dim [in] number of elements in vector
Returns:
basic math status informations
0 = no error
undef = error
BM_STATUS crossProductDblVector ( double *  result,
const double *  multiplier,
const double *  multiplicand,
const unsigned int  dim 
)

safe vector cross product

result (vector) = multiplier * multiplicand

Parameters:
result [out] pointer to the vector's first element It's strictly forbidden that result points to multiplier or multiplicand. (will be checked!!!)
multiplier [in] pointer to the vector's first element
multiplicand [in] pointer to the vector's first element
dim [in] number of elements in the vectors
Returns:
basic math status informations
0 = no error
possible errors are: undef, overflow, negative
BM_STATUS directionDblVector ( double *  direction,
const double *  vector,
const unsigned int  dim 
)

returns the unit direction vector of vector ( |dir| == 1 )

calculates the direction of vector

Parameters:
direction [out] pointer to the vector's first element
vector [in] pointer to the vector's first element
dim [in] number of elements in the vectors
Returns:
basic math status informations
0 = no error
possible errors are: undef
BM_STATUS doubleDivDblVector ( double *  result,
const double *  vector,
const unsigned int  dim,
const double  scalar 
)

safe vector divsion with a scalar

result (vector) = vector / scalar

Parameters:
result [out] pointer to the vector's first element Can also point to vector.
vector [in] pointer to the vector's first element
dim [in] number of elements in the vectors
scalar [in] the value to be divided with each element of vector
Returns:
basic math status informations
0 = no error
possible errors are: undef, overflow, negative
BM_STATUS doubleMulDblVector ( double *  result,
const double *  vector,
const unsigned int  dim,
const double  scalar 
)

safe vector multiplication with a scalar

result (vector) = vector * scalar

Parameters:
result [out] pointer to the vector's first element Can also point to vector.
vector [in] pointer to the vector's first element
dim [in] number of elements in the vectors
scalar [in] the value to be multiplied with each element of vector
Returns:
basic math status informations
0 = no error
possible errors are: undef, overflow, negative
BM_STATUS initDblVector ( double *  vector,
const unsigned int  dim,
const double  value 
)

set all elements of the vector to value

Parameters:
vector [out] pointer to the vector's first element
dim [in] number of elements in vector
value [in] the value to be set into each element in vector
Returns:
basic math status informations
0 = no error
undef = error
double innerProductDblVector ( const double *  multiplier,
const double *  multiplicand,
const unsigned int  dim,
BM_STATUS bms 
)

safe vector inner product

result (scalar) = multiplier * multiplicand

Parameters:
multiplier [in] pointer to the vector's first element
multiplicand [in] pointer to the vector's first element
dim [in] number of elements in the vectors
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the result (scalar) of this operation in double format
BM_STATUS invertDirectionDblVector ( double *  result,
const double *  vector,
const unsigned int  dim 
)

invert direction of vector ( -(vector) )

result = -(vector)

Parameters:
result [out] pointer to the vector's first element Can also point to vector.
vector [in] pointer to the vector's first element
dim [in] number of elements in the vectors
Returns:
basic math status informations
0 = no error
possible errors are: undef
int is1DblVector ( const double *  vector,
const unsigned int  dim,
BM_STATUS bms 
)

is 1 vector ( |vector| == 1 )

returns 1 if the length of the vector == 1 (+-MICRO)

Parameters:
vector [in] pointer to the vector's first element
dim [in] number of elements in the vectors
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
-1 = error
0 = length of vector != 1 (+-MICRO)
1 = vector is a unit vector (length == 1 (+-MICRO))
int isEqualDblVector ( const double *  vector1,
const double *  vector2,
const unsigned int  dim,
BM_STATUS bms 
)

is vector1 equal vector2 ( vector1 == vector2 )

returns 1 both vectors are equal

Parameters:
vector1 [in] pointer to the vector's first element
vector2 [in] pointer to the vector's first element
dim [in] number of elements in the vectors
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
-1 = error
0 if vector1 <> vector2
1 if vector1 == vector2 (+-MICRO)
int isNullDblVector ( const double *  vector,
const unsigned int  dim,
BM_STATUS bms 
)

is null vector ( |vector| < MICRO (0.000001) )

returns 1 if the length of the vector >= MICRO

Parameters:
vector [in] pointer to the vector's first element
dim [in] number of elements in the vectors
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
-1 = error
0 = length of vector >= MICRO
1 = vector is a null vector (length < MICRO)
int isOrthogonalDblVector ( const double *  vector1,
const double *  vector2,
const unsigned int  dim,
BM_STATUS bms 
)

checks if vector1 is orthogonal to vector2

returns 1 if vector1 is orthogonal (normal) to vector2

Parameters:
vector1 [in] pointer to the vector's first element
vector2 [in] pointer to the vector's first element
dim [in] number of elements in the vectors
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
< 0 = error
0 if vector1 is not orthongonal to vector2
1 if vector1 is orthogonal to vector2
int isParallelDblVector ( const double *  vector1,
const double *  vector2,
const unsigned int  dim,
BM_STATUS bms 
)

checks the direction of vector1 and vector2 (dir1 == dir2) or (-dir1==dir2)

returns 1 if vector1 is parallel to vector2
retruns 2 if vector1 is anti parallel to vector2 (oposite direction)

Parameters:
vector1 [in] pointer to the vector's first element
vector2 [in] pointer to the vector's first element
dim [in] number of elements in the vectors
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
< 0 = error
0 if vector1 is not parallel and not anti parallel to vector2
1 if vector1 is parallel to vector2
2 if vector1 is anti parallel to vector2
double lengthDblVector ( const double *  vector,
const unsigned int  dim,
BM_STATUS bms 
)

length of vector ( abs(vector) )

length (scalar) = |vector|

Parameters:
vector [in] pointer to the vector's first element
dim [in] number of elements in the vectors
bms [out,opt] A pointer to receive basic math status informations (can be null).
bms remains unchanged if there is no error in this operation.
bms acts accumulative.
Returns:
the length of the vector in double format
BM_STATUS subDblVector ( double *  result,
const double *  minuend,
const double *  subtrahend,
const unsigned int  dim 
)

safe vector subtraction

result = minuend - subtrahend

Parameters:
result [out] pointer to the destination vector's first element. Can also point to augend or addend.
minuend [in] pointer to the vector's first element
subtrahend [in] pointer to the vector's first element
dim [in] number of elements in the vectors
Returns:
basic math status informations
0 = no error
possible errors are: undef, overflow, negative
 All Classes Files Functions Variables Typedefs Defines
Generated on Mon Nov 22 06:27:34 2010 by  doxygen 1.6.3