#include <QGLViewer/vec.h>
The Vec class represents 3D positions and 3D vectors. More...
The Vec class represents 3D positions and 3D vectors.
Vec is used as a parameter and return type by many methods of the library. It provides classical algebraic computational methods and is compatible with OpenGL:
This makes of Vec a good candidate for representing positions and vectors in your programs. Since it is part of the qglviewer
namespace, specify qglviewer::Vec
or use the qglviewer namespace:
Vec implements a universal explicit converter, based on the []
operator
. Everywhere a const
Vec&
argument is expected, you can use your own vector type instead, as long as it implements this operator (see the Vec(const C& c) documentation).
See also the Quaternion and the Frame documentations.
Public Attributes | |
union { | |
struct { | |
qreal x | |
qreal y | |
qreal z | |
} | |
qreal v_ [3] | |
}; | |
The internal data representation is public. More... | |
Setting the value | |
Vec () | |
Default constructor. More... | |
Vec (qreal X, qreal Y, qreal Z) | |
Standard constructor with the x, y and z values. More... | |
template<class C > | |
Vec (const C &c) | |
Universal explicit converter from any class to Vec. More... | |
Vec & | operator= (const Vec &v) |
Equal operator. More... | |
void | setValue (qreal X, qreal Y, qreal Z) |
Set the current value. More... | |
Accessing the value | |
qreal | operator[] (int i) const |
Bracket operator, with a constant return value. More... | |
qreal & | operator[] (int i) |
Bracket operator returning an l-value. More... | |
const qreal * | address () const |
This method is deprecated since version 2.0. More... | |
operator const qreal * () const | |
Conversion operator returning the memory address of the vector. More... | |
operator qreal * () | |
Non const conversion operator returning the memory address of the vector. More... | |
operator const float * () const | |
Conversion operator returning the memory address of the vector. More... | |
Algebraic computations | |
Vec & | operator+= (const Vec &a) |
Adds a to the vector. More... | |
Vec & | operator-= (const Vec &a) |
Subtracts a to the vector. More... | |
Vec & | operator*= (qreal k) |
Multiply the vector by a scalar k . More... | |
Vec & | operator/= (qreal k) |
Divides the vector by a scalar k . More... | |
Vec | orthogonalVec () const |
Returns a Vec orthogonal to the Vec. More... | |
Vec | operator+ (const Vec &a, const Vec &b) |
Returns the sum of the two vectors. More... | |
Vec | operator- (const Vec &a, const Vec &b) |
Returns the difference of the two vectors. More... | |
Vec | operator- (const Vec &a) |
Unary minus operator. More... | |
Vec | operator* (const Vec &a, qreal k) |
Returns the product of the vector with a scalar. More... | |
Vec | operator* (qreal k, const Vec &a) |
Returns the product of a scalar with the vector. More... | |
Vec | operator/ (const Vec &a, qreal k) |
Returns the division of the vector with a scalar. More... | |
bool | operator!= (const Vec &a, const Vec &b) |
Returns true only when the two vector are not equal (see operator==()). More... | |
bool | operator== (const Vec &a, const Vec &b) |
Returns true when the squaredNorm() of the difference vector is lower than 1E-10. More... | |
qreal | operator* (const Vec &a, const Vec &b) |
Dot product of the two Vec. More... | |
Vec | operator^ (const Vec &a, const Vec &b) |
Cross product of the two vectors. More... | |
Vec | cross (const Vec &a, const Vec &b) |
Cross product of the two Vec. More... | |
Norm of the vector | |
qreal | sqNorm () const |
This method is deprecated since version 2.0. More... | |
qreal | squaredNorm () const |
Returns the squared norm of the Vec. More... | |
qreal | norm () const |
Returns the norm of the vector. More... | |
qreal | normalize () |
Normalizes the Vec and returns its original norm. More... | |
Vec | unit () const |
Returns a unitary (normalized) representation of the vector. More... | |
Projection | |
void | projectOnAxis (const Vec &direction) |
Projects the Vec on the axis of direction direction that passes through the origin. More... | |
void | projectOnPlane (const Vec &normal) |
Projects the Vec on the plane whose normal is normal that passes through the origin. More... | |
XML representation | |
Vec (const QDomElement &element) | |
Constructs a Vec from a QDomElement representing an XML code of the form. More... | |
QDomElement | domElement (const QString &name, QDomDocument &document) const |
Returns an XML QDomElement that represents the Vec. More... | |
void | initFromDOMElement (const QDomElement &element) |
Restores the Vec state from a QDomElement created by domElement(). More... | |
union { ... } |
The internal data representation is public.
One can use v.x, v.y, v.z. See also operator[]().
qreal qglviewer::Vec::v_[3] |
qreal qglviewer::Vec::x |
qreal qglviewer::Vec::y |
qreal qglviewer::Vec::z |
|
inline |
Default constructor.
Value is set to (0,0,0).
|
inline |
Standard constructor with the x, y and z values.
|
inlineexplicit |
Universal explicit converter from any class to Vec.
You can use your own vector class everywhere a const
Vec&
parameter is required, as long as it implements the operator
[ ]:
Note that standard vector types (STL, qreal
[3], ...) implement this operator and can hence be used in place of Vec. See also operator const qreal*() .
|
explicit |
Constructs a Vec from a QDomElement
representing an XML code of the form.
If one of these attributes is missing or is not a number, a warning is displayed and the associated value is set to 0.0.
See also domElement() and initFromDOMElement().
|
inline |
This method is deprecated since version 2.0.
Use operator const qreal* instead.
QDomElement Vec::domElement | ( | const QString & | name, |
QDomDocument & | document | ||
) | const |
Returns an XML QDomElement
that represents the Vec.
name
is the name of the QDomElement tag. doc
is the QDomDocument
factory used to create QDomElement.
When output to a file, the resulting QDomElement will look like:
Use initFromDOMElement() to restore the Vec state from the resulting QDomElement
. See also the Vec(const QDomElement&) constructor.
Here is complete example that creates a QDomDocument and saves it into a file:
See also Quaternion::domElement(), Frame::domElement(), Camera::domElement()...
void Vec::initFromDOMElement | ( | const QDomElement & | element | ) |
Restores the Vec state from a QDomElement
created by domElement().
The QDomElement
should contain x
, y
and z
attributes. If one of these attributes is missing or is not a number, a warning is displayed and the associated value is set to 0.0.
To restore the Vec state from an xml file, use:
See also the Vec(const QDomElement&) constructor.
|
inline |
Returns the norm of the vector.
|
inline |
Normalizes the Vec and returns its original norm.
Normalizing a null vector will result in NaN
values.
|
inline |
|
inline |
|
inline |
Non const conversion operator returning the memory address of the vector.
Useful to pass a Vec to a method that requires and fills a qreal*
, as provided by certain libraries.
|
inline |
Multiply the vector by a scalar k
.
|
inline |
Divides the vector by a scalar k
.
An absolute k
value lower than 1E-10 will print a warning if the library was compiled with the "debug" Qt CONFIG
flag. Otherwise, no test is performed for efficiency reasons.
|
inline |
Bracket operator returning an l-value.
i
must range in [0..2].
|
inline |
Bracket operator, with a constant return value.
i
must range in [0..2].
Vec Vec::orthogonalVec | ( | ) | const |
void Vec::projectOnAxis | ( | const Vec & | direction | ) |
Projects the Vec on the axis of direction direction
that passes through the origin.
direction
does not need to be normalized (but must be non null).
void Vec::projectOnPlane | ( | const Vec & | normal | ) |
Projects the Vec on the plane whose normal is normal
that passes through the origin.
normal
does not need to be normalized (but must be non null).
|
inline |
Set the current value.
May be faster than using operator=() with a temporary Vec(x,y,z).
|
inline |
This method is deprecated since version 2.0.
Use squaredNorm() instead.
|
inline |
Returns the squared norm of the Vec.
|
inline |
Returns a unitary (normalized) representation of the vector.
The original Vec is not modified.
Returns true
only when the two vector are not equal (see operator==()).
Returns the division of the vector with a scalar.
Too small k
values are not tested (unless the library was compiled with the "debug" Qt CONFIG
flag) and may result in NaN
values.
Returns true
when the squaredNorm() of the difference vector is lower than 1E-10.