ivutils
Loading...
Searching...
No Matches
vector_3a.h File Reference

N-dimensional vectors and some useful functions for work with them. More...

#include <cmath>
#include <limits>
#include <algorithm>
#include "math_utils.h"
Include dependency graph for vector_3a.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  vec_prod_traits< T, N >
 Traits class for vector product. More...
 
class  Vector_Nt< T, N, storage_t >
 N-dimensional vector of the type T and some useful operations. More...
 
struct  vec_less< vec_t >
 Comparison in the order of components. More...
 

Macros

#define VEC_INFTY   std::numeric_limits<vec_type>::max()
 "infinitely large" number
 
#define INT_INFTY   std::numeric_limits<int>::max()
 "infinitely large" integer number
 
#define MULT_EPSILON   1024
 how bigger is "ininitely small" number then std::numeric_limits<...>::epsilon().
 
#define VEC_ZERO   (MULT_EPSILON*std::numeric_limits<vec_type>::min())
 "infinitely small" number for multiplication and division (here smallest to be able to divide by)
 
#define VEC_ZERO_EPS   (MULT_EPSILON*std::numeric_limits<vec_type>::epsilon())
 "infinitely small" number (compared to 1) for addition and subtraction.
 

Functions

template<class T >
Vector_Nt< T, 3 > operator% (const Vector_Nt< T, 3 > &x, const Vector_Nt< T, 3 > &y)
 Vector product for N=3.
 
template<class T >
vec_type operator% (const Vector_Nt< T, 2 > &x, const Vector_Nt< T, 2 > &y)
 Vector product for N=2.
 
vec_type vec_area (const Vector_2 &vect1, const Vector_2 &vect2)
 returns polygon area based on vectors vect1 and vect2
 
vec_type dist_max (Vector_3 *va1, Vector_3 *va2, int n)
 finds the maximum distance between vector pairs
 
vec_type dist_av (Vector_3 *va1, Vector_3 *va2, int n)
 finds average distance between vector pairs
 
vec_type diff_av (Vector_3 *va1, Vector_3 *va2, int n, int *minind=0, int *maxind=0)
 finds the average difference norm between two vector sets of the same length optionally gives the indices for maximal and minimal difference va2 can be nullptr, then the norm of va1 is used
 
Vector_3 FindPerp (const Vector_3 &vAB)
 finds suitable perpendicular to a vector
 
Vector_3 GetScope (const Vector_3 *varr, long n, Vector_3 *box_min, Vector_3 *box_max)
 Returns the average (center) vector of the vector array and coordinates of a minimal box in which it is contained.
 
Vector_3 GetIScope (const Vector_3 *varr, long *indarr, long n, Vector_3 *box_min, Vector_3 *box_max)
 the same with long index array
 
Vector_3 GetIScopei (const Vector_3 *varr, int *indarr, int n, Vector_3 *box_min, Vector_3 *box_max)
 the same with int index array
 
void clear_vecarri (int n, Vector_3 *vec, int *ind=0)
 clears vector array with optional integer index
 
Vector_3 Reflect (Vector_3 &ini, double t, Vector_3 &dir, double *box, int flag=0x7, const Vector_3 &force=Vector_3())
 reflects the vector ini+dir*t+0.5*force*t^2 to be inside a box limited by 0 and box sizes changes dir according to the final state fills crossed dir with bit flags corresponding directions along which the walls were crossed
 
template<class vec_inp_it >
Vector_3 get_extent (vec_inp_it beg, vec_inp_it end, Vector_3 *box_min=nullptr, Vector_3 *box_max=nullptr)
 Calculates extent of the vector container.
 
template<class inp_it , class vector_tt >
vector_tt::value_type gramm_schmidt_project (inp_it orth_set_beg, inp_it orth_set_end, const vector_tt &inp_vec, vector_tt &out_vec)
 Performs a step of the Stabilized Gramm-Schidt orthonormalization algorithm.
 
template<class T , int N>
distance2edge (const Vector_Nt< T, N > &point, const Vector_Nt< T, N > &e1, const Vector_Nt< T, N > &e2, Vector_Nt< T, N > *pos=nullptr)
 Calculates a distance between a poinbt point and an edge formed by points e1 and e2.
 

Detailed Description

N-dimensional vectors and some useful functions for work with them.

Macro Definition Documentation

◆ MULT_EPSILON

#define MULT_EPSILON   1024

how bigger is "ininitely small" number then std::numeric_limits<...>::epsilon().

We use this parameter since std::numeric_limits<...>::epsilon() is too small.

◆ VEC_ZERO_EPS

#define VEC_ZERO_EPS   (MULT_EPSILON*std::numeric_limits<vec_type>::epsilon())

"infinitely small" number (compared to 1) for addition and subtraction.

The exact value is MULT_EPSILON * std::numeric_limits<vec_type>::epsilon()

Function Documentation

◆ get_extent()

template<class vec_inp_it >
Vector_3 get_extent ( vec_inp_it  beg,
vec_inp_it  end,
Vector_3 box_min = nullptr,
Vector_3 box_max = nullptr 
)

Calculates extent of the vector container.

Returns
the center of the vector set, optionally (if arguments are not nullptr) fills the bounding box in box_min, box_max.

◆ gramm_schmidt_project()

template<class inp_it , class vector_tt >
vector_tt::value_type gramm_schmidt_project ( inp_it  orth_set_beg,
inp_it  orth_set_end,
const vector_tt &  inp_vec,
vector_tt &  out_vec 
)

Performs a step of the Stabilized Gramm-Schidt orthonormalization algorithm.

Given a set of orthogonal unit vectors defined by [orth_beg, orth_end) orthonormalizes inp_vec with respect to this set (removes all projections to the set). The result is recorded to out_vec, which is normalized.

Returns
the norm of out_vec before normalization. If return value is <=VEC_ZERO, then inp_vec may be considered as linearly dependent of the supplied set.