Geogram
Version 1.9.1
A programming library of geometric algorithms
|
Generic maths vector. More...
#include <geogram/basic/vecg.h>
Public Types | |
typedef vecng< DIM, T > | vector_type |
This vector type. | |
typedef T | value_type |
The type of the vector coordinates. | |
Public Member Functions | |
vecng () | |
Default vector constructor. More... | |
template<class T2 > | |
vecng (const vecng< DIM, T2 > &v) | |
Constructs a vector by copy. More... | |
template<class T2 , index_t DIM2> | |
vecng (const vecng< DIM2, T2 > &v) | |
template<class T2 > | |
vecng (const T2 *v) | |
Constructs a vector from an array. More... | |
vecng (const std::initializer_list< T > &Vi) | |
Constructs a vector from an initializer list. More... | |
index_t | dimension () const |
Gets the vector dimension. More... | |
T * | data () |
Gets modifiable vector data. More... | |
const T * | data () const |
Gets non-modifiable vector data. More... | |
T & | operator[] (index_t i) |
Gets a modifiable vector coordinate. More... | |
const T & | operator[] (index_t i) const |
Gets a non-modifiable vector coordinate. More... | |
T | length2 () const |
Gets the squared length of the vector. | |
T | length () const |
Gets the length of the vector. | |
T | distance2 (const vector_type &v) const |
Gets the squared distance to a vector. More... | |
T | distance (const vector_type &v) const |
Gets the distance to a vector. More... | |
vector_type & | operator+= (const vector_type &v) |
Adds a vector in place. More... | |
vector_type & | operator-= (const vector_type &v) |
Subtracts a vector in place. More... | |
template<class T2 > | |
vector_type & | operator*= (T2 s) |
Multiplies by a scalar in place. More... | |
template<class T2 > | |
vector_type & | operator/= (T2 s) |
Divides by a scalar in place. More... | |
vector_type | operator+ (const vector_type &v) const |
Adds 2 vectors. More... | |
vector_type | operator- (const vector_type &v) const |
Subtracts 2 vectors. More... | |
template<class T2 > | |
vector_type | operator* (T2 s) const |
Multiplies a vector by a scalar. More... | |
template<class T2 > | |
vector_type | operator/ (T2 s) const |
Divides a vector by a scalar. More... | |
vector_type | operator- () const |
Negates a vector. More... | |
Static Public Attributes | |
static const index_t | dim = DIM |
The dimension of the vector. | |
Related Functions | |
(Note that these are not member functions.) | |
template<index_t DIM, class T > | |
T | dot (const vecng< DIM, T > &v1, const vecng< DIM, T > &v2) |
Computes the dot product of 2 vectors. More... | |
template<class T2 , index_t DIM, class T > | |
vecng< DIM, T > | operator* (T2 s, const vecng< DIM, T > &v) |
Multiplies a scalar by a vector. More... | |
template<index_t DIM, class T > | |
T | length (const vecng< DIM, T > &v) |
Gets the norm of a vector. More... | |
template<index_t DIM, class T > | |
T | length2 (const vecng< DIM, T > &v) |
Gets the square norm of a vector. More... | |
template<index_t DIM, class T > | |
T | distance2 (const vecng< DIM, T > &v1, const vecng< DIM, T > &v2) |
Gets the square distance between 2 vectors. More... | |
template<index_t DIM, class T > | |
T | distance (const vecng< DIM, T > &v1, const vecng< DIM, T > &v2) |
Gets the distance between 2 vectors. More... | |
template<index_t DIM, class T > | |
vecng< DIM, T > | normalize (const vecng< DIM, T > &v) |
Normalizes a vector. More... | |
template<index_t DIM, class T > | |
vecng< DIM, T > | mix (const vecng< DIM, T > &v1, const vecng< DIM, T > &v2, T s) |
Computes a weighted barycenter. More... | |
template<class T > | |
T | dot (const vecng< 2, T > &v1, const vecng< 2, T > &v2) |
Computes the dot product of 2 vectors. More... | |
template<class T > | |
T | det (const vecng< 2, T > &v1, const vecng< 2, T > &v2) |
Computes the determinant of 2 vectors. More... | |
template<class T2 , class T > | |
vecng< 2, T > | operator* (T2 s, const vecng< 2, T > &v) |
Multiplies a scalar by a vector. More... | |
template<class T > | |
T | dot (const vecng< 3, T > &v1, const vecng< 3, T > &v2) |
Computes the dot product of 2 vectors. More... | |
template<class T > | |
vecng< 3, T > | cross (const vecng< 3, T > &v1, const vecng< 3, T > &v2) |
Computes the cross product of 2 vectors. More... | |
template<class T2 , class T > | |
vecng< 3, T > | operator* (T2 s, const vecng< 3, T > &v) |
Multiplies a scalar by a vector. More... | |
template<class T > | |
T | dot (const vecng< 4, T > &v1, const vecng< 4, T > &v2) |
Computes the dot product of 2 vectors. More... | |
template<class T2 , class T > | |
vecng< 4, T > | operator* (T2 s, const vecng< 4, T > &v) |
Multiplies a scalar by a vector. More... | |
template<index_t DIM, class T > | |
std::ostream & | operator<< (std::ostream &out, const GEO::vecng< DIM, T > &v) |
Writes a vector to a stream. More... | |
template<index_t DIM, class T > | |
std::istream & | operator>> (std::istream &in, GEO::vecng< DIM, T > &v) |
Reads a vector from a stream. More... | |
Generic maths vector.
Vecng implements a maths vector of dimension DIM
containing coordinates of type T
and provides operations for manipulating it. Type T
is expected to be a numeric type.
DIM | dimension of the vector |
T | type of the vector coordinates. |
|
inline |
|
inlineexplicit |
Constructs a vector by copy.
This copies coordinates of vector v
to this vector. The type T2
of the coordinates in v
must be convertible to the type T
of this vector.
[in] | v | an vector of same dimension with coordinates of type T2 |
T2 | the type of coordinates in vector v |
|
inlineexplicit |
Constructs a vector from an array.
This copies coordinates the first DIM
coordinates of array v
to this vector. The type T2
of the coordinates in v
must be convertible to the type T
of this vector.
[in] | v | an array of values of type T2 |
T2 | the type of coordinates in vector v |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Multiplies a vector by a scalar.
Builds a vector by multipying this vector coordinates by value s
. The type T2
of s
must be convertible to the type T
of this vector coordinates.
[in] | s | a value of type T2 |
T2 | the type of value s |
this
* s
)
|
inline |
Multiplies by a scalar in place.
Multiplies this vector coordinates by value s
. The type T2
of s
must be convertible to the type T
of this vector coordinates.
[in] | s | a value of type T2 |
T2 | the type of value s |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Divides a vector by a scalar.
Builds a vector by dividing this vector coordinates by value s
. The type T2
of s
must be convertible to the type T
of this vector coordinates.
[in] | s | a value of type T2 |
T2 | the type of value s |
this
/ s
)
|
inline |
Divides by a scalar in place.
Divides this vector coordinates by value s
. The type T2
of s
must be convertible to the type T
of this vector coordinates.
[in] | s | a value of type T2 |
T2 | the type of value s |
|
inline |
|
inline |
|
related |
Gets the distance between 2 vectors.
[in] | v1 | the first vector |
[in] | v2 | the second vector |
v1
and v2
.
|
related |
Gets the square distance between 2 vectors.
[in] | v1 | the first vector |
[in] | v2 | the second vector |
v1
and v2
.
|
related |
Gets the norm of a vector.
[in] | v | a vector |
v
|
related |
Gets the square norm of a vector.
[in] | v | a vector |
v
Multiplies a scalar by a vector.
Builds a vector by multipying this vector coordinates by value s
. The type T2
of s
must be convertible to the type T
of this vector coordinates.
[in] | s | a value of type T2 |
[in] | v | the vector to multiply |
T2 | the type of value s |
s
* v
) Multiplies a scalar by a vector.
Builds a vector by multipying this vector coordinates by value s
. The type T2
of s
must be convertible to the type T
of this vector coordinates.
[in] | s | a value of type T2 |
[in] | v | the vector to multiply |
T2 | the type of value s |
s
* v
) Multiplies a scalar by a vector.
Builds a vector by multipying this vector coordinates by value s
. The type T2
of s
must be convertible to the type T
of this vector coordinates.
[in] | s | a value of type T2 |
[in] | v | the vector to multiply |
T2 | the type of value s |
s
* v
)
|
related |
Multiplies a scalar by a vector.
Builds a vector by multipying this vector coordinates by value s
. The type T2
of s
must be convertible to the type T
of this vector coordinates.
[in] | s | a value of type T2 |
[in] | v | the vector to multiply |
T2 | the type of value s |
s
* v
)
|
related |
|
related |
Reads a vector from a stream.
This reads DIM
coordinates from the input stream in
and stores them in vector v
. Understands both "x y z" and "[x, y, z]" formats.
[in] | in | the input stream |
[out] | v | the vector to read |
in