The Vec class represents 3D positions and 3D vectors. More...
Public Attributes | |
union { | |
struct { | |
double x | |
double y | |
double z | |
} | |
double v_ [3] | |
}; | |
Setting the value | |
Vec () | |
Default constructor. | |
Vec (double X, double Y, double Z) | |
Standard constructor with the x, y and z values. | |
template<class C > | |
Vec (const C &c) | |
Universal explicit converter from any class to Vec. | |
Vec & | operator= (const Vec &v) |
Equal operator. | |
void | setValue (double X, double Y, double Z) |
Set the current value. | |
Accessing the value | |
double | operator[] (int i) const |
Bracket operator, with a constant return value. | |
double & | operator[] (int i) |
Bracket operator returning an l-value. | |
const double * | address () const |
This method is deprecated since version 2.0. | |
operator const double * () const | |
Conversion operator returning the memory address of the vector. | |
operator double * () | |
Non const conversion operator returning the memory address of the vector. | |
operator const float * () const | |
Conversion operator returning the memory address of the vector. | |
Algebraic computations | |
Vec & | operator+= (const Vec &a) |
Adds a to the vector. | |
Vec & | operator-= (const Vec &a) |
Subtracts a to the vector. | |
Vec & | operator*= (double k) |
Multiply the vector by a scalar k . | |
Vec & | operator/= (double k) |
Divides the vector by a scalar k . | |
Vec | orthogonalVec () const |
Returns a Vec orthogonal to the Vec. | |
Vec | operator+ (const Vec &a, const Vec &b) |
Returns the sum of the two vectors. | |
Vec | operator- (const Vec &a, const Vec &b) |
Returns the difference of the two vectors. | |
Vec | operator- (const Vec &a) |
Unary minus operator. | |
Vec | operator* (const Vec &a, double k) |
Returns the product of the vector with a scalar. | |
Vec | operator* (double k, const Vec &a) |
Returns the product of a scalar with the vector. | |
Vec | operator/ (const Vec &a, double k) |
Returns the division of the vector with a scalar. | |
bool | operator!= (const Vec &a, const Vec &b) |
Returns true only when the two vector are not equal (see operator==()). | |
bool | operator== (const Vec &a, const Vec &b) |
Returns true when the squaredNorm() of the difference vector is lower than 1E-10. | |
double | operator* (const Vec &a, const Vec &b) |
Dot product of the two Vec. | |
Vec | operator^ (const Vec &a, const Vec &b) |
Cross product of the two vectors. | |
Vec | cross (const Vec &a, const Vec &b) |
Cross product of the two Vec. | |
Norm of the vector | |
double | sqNorm () const |
This method is deprecated since version 2.0. | |
double | squaredNorm () const |
Returns the squared norm of the Vec. | |
double | norm () const |
Returns the norm of the vector. | |
double | normalize () |
Normalizes the Vec and returns its original norm. | |
Vec | unit () const |
Returns a unitary (normalized) representation of the vector. | |
Projection | |
void | projectOnAxis (const Vec &direction) |
Projects the Vec on the axis of direction direction that passes through the origin. | |
void | projectOnPlane (const Vec &normal) |
Projects the Vec on the plane whose normal is normal that passes through the origin. | |
XML representation | |
Vec (const QDomElement &element) | |
Constructs a Vec from a QDomElement representing an XML code of the form. | |
QDomElement | domElement (const QString &name, QDomDocument &document) const |
Returns an XML QDomElement that represents the Vec. | |
void | initFromDOMElement (const QDomElement &element) |
Restores the Vec state from a QDomElement created by domElement(). | |
Detailed Description
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:
Interface with other vector classes
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.
Constructor & Destructor Documentation
|
inline |
|
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, double
[3], ...) implement this operator and can hence be used in place of Vec. See also operator const double*() .
|
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().
Member Function Documentation
|
inline |
QDomElement 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 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.
Definition at line 339 of file vec.h.
Referenced by Frame::alignWithFrame(), Quaternion::axis(), QGLViewer::drawArrow(), Quaternion::getAxisAngle(), Vec::projectOnAxis(), Vec::projectOnPlane(), Quaternion::setAxisAngle(), Quaternion::setFromRotatedBasis(), AxisPlaneConstraint::setRotationConstraintDirection(), and AxisPlaneConstraint::setTranslationConstraintDirection().
|
inline |
Normalizes the Vec and returns its original norm.
Normalizing a null vector will result in NaN
values.
Definition at line 344 of file vec.h.
Referenced by Camera::convertClickToLine(), QGLViewer::drawLight(), Camera::setFromProjectionMatrix(), and Vec::unit().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Vec orthogonalVec | ( | ) | const |
Returns a Vec orthogonal to the Vec.
Its norm() depends on the Vec, but is zero only for a null Vec. Note that the function that associates an orthogonalVec() to a Vec is not continous.
Definition at line 59 of file vec.cpp.
Referenced by Quaternion::Quaternion().
void 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).
Definition at line 34 of file vec.cpp.
References Vec::norm(), and Vec::squaredNorm().
Referenced by LocalConstraint::constrainRotation(), WorldConstraint::constrainRotation(), CameraConstraint::constrainRotation(), LocalConstraint::constrainTranslation(), WorldConstraint::constrainTranslation(), CameraConstraint::constrainTranslation(), and Frame::projectOnLine().
void 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).
Definition at line 47 of file vec.cpp.
References Vec::norm(), and Vec::squaredNorm().
Referenced by LocalConstraint::constrainTranslation(), WorldConstraint::constrainTranslation(), and CameraConstraint::constrainTranslation().
|
inline |
Set the current value.
May be faster than using operator=() with a temporary Vec(x,y,z).
Definition at line 129 of file vec.h.
Referenced by ManipulatedCameraFrame::mouseMoveEvent(), and ManipulatedFrame::mouseMoveEvent().
|
inline |
This method is deprecated since version 2.0.
Use squaredNorm() instead.
|
inline |
Returns the squared norm of the Vec.
Definition at line 336 of file vec.h.
Referenced by ManipulatedFrame::deformedBallQuaternion(), Vec::projectOnAxis(), Vec::projectOnPlane(), Quaternion::Quaternion(), and Camera::setViewDirection().
|
inline |
Returns a unitary (normalized) representation of the vector.
The original Vec is not modified.
Definition at line 356 of file vec.h.
References Vec::normalize().
Friends And Related Function Documentation
Returns true
only when the two vector are not equal (see operator==()).
Returns true
when the squaredNorm() of the difference vector is lower than 1E-10.
The documentation for this class was generated from the following files: