Definition
An instance of data type real_vector is a vector of variables of type real.
#include < LEDA/numbers/real_vector.h >
Creation
real_vector | v | creates an instance v of type real_vector; v is initialized to the zero-dimensional vector. |
real_vector | v(int d) | creates an instance v of type real_vector; v is initialized to the zero vector of dimension d. |
real_vector | v(real a, real b) | creates an instance v of type real_vector; v is initialized to the two-dimensional vector (a, b). |
real_vector | v(real a, real b, real c) | creates an instance v of type real_vector; v is initialized to the three-dimensional vector (a, b, c). |
real_vector | v(double a, double b) | creates an instance v of type real_vector; v is initialized to the two-dimensional vector (a, b). |
real_vector | v(double a, double b, double c) | |
creates an instance v of type real_vector; v is initialized to the three-dimensional vector (a, b, c). |
Operations
int | v.dim() | returns the dimension of v. |
real& | v[int i] | returns i-th component of v.
Precondition 0 < = i < = v.dim()-1. |
real | v.hcoord(int i) | for compatibility with rat_vector. |
real | v.coord(int i) | for compatibility with rat_vector. |
real | v.sqr_length() | returns the square of the Euclidean length of v. |
real | v.length() | returns the Euclidean length of v. |
real_vector | v.norm() | returns v normalized. |
real_vector | v.rotate90(int i=1) | returns v by an angle of i x 90 degrees. If i > 0 the rotation is counter-clockwise otherwise it is clockwise. Precondition v.dim() = 2 |
real_vector | v + const real_vector& v1 | Addition.
Precondition v.dim() = v1.dim(). |
real_vector | v - const real_vector& v1 | Subtraction.
Precondition v.dim() = v1.dim(). |
real | v * const real_vector& v1 | Scalar multiplication.
Precondition v.dim() = v1.dim(). |
real_vector& | v *= real r | multiplies all coordinates by r. |
real_vector | v * real r | Componentwise multiplication with real r. |
bool | v == const real_vector& w | Test for equality. |
bool | v != const real_vector& w | Test for inequality. |
void | v.print(ostream& O) | prints v componentwise to ostream O. |
void | v.print() | prints v to cout. |
void | v.read(istream& I) | reads d = v.dim() numbers from input stream I and writes them into v[0]...v[d - 1]. |
void | v.read() | reads v from cin. |
ostream& | ostream& O « const real_vector& v | |
writes v componentwise to the output stream O. | ||
istream& | istream& I » real_vector& v | |
reads v componentwise from the input stream I. | ||
vector | v.to_float() | returns a floating point approximation of v. |
Additional Operations for vectors in two and three-dimensional space
real | v.xcoord() | returns the zero-th cartesian coordinate of v. |
real | v.ycoord() | returns the first cartesian coordinate of v. |
real | v.zcoord() | returns the second cartesian coordinate of v. |
int | compare_by_angle(const real_vector& v1, const real_vector& v2) | |
For a non-zero vector v let (v) be the angle by which the positive x-axis has to be turned counter-clockwise until it aligns with v. The function compares the angles defined by v1 and v2, respectively. The zero-vector precedes all non-zero vectors in the angle-order. | ||
real_vector | cross_product(const real_vector& v1, const real_vector& v2) | |
returns the cross product of the three-dimensional vectors v1 and v2. |
Implementation
Vectors are implemented by arrays of real numbers. All operations on a vector v take O(v.dim()) real-number operations, except for dim and [ ] which take constant time. The space requirement depends on the size of the representations of the coordinates.