RVector Class Reference

Represents a 3d vector (x/y/z). More...

`#include <RVector.h>`

Inheritance diagram for RVector:

Classes

class  RVectorAngleSort

class  RVectorDistanceSort

class  RVectorLeftRightTopBottomSort

Public Member Functions

double dot (const RVector &other)

bool equalsFuzzy (const RVector &v, double tol=RS::PointTolerance) const

bool equalsFuzzy2D (const RVector &v, double tol=RS::PointTolerance) const

RVector flipHorizontal ()
Mirrors this vector at the Y-axis. More...

RVector flipVertical ()
Mirrors this vector at the X-axis. More...

RVector get2D () const

double getAngle () const

double getAngleTo (const RVector &v) const

double getAngleToPlaneXY () const

RVector getCeil () const

RVector getClosest (const QList< RVector > &list) const

RVector getClosest2d (const QList< RVector > &list) const

double getClosestDistance (const QList< RVector > &list, int counts)

int getClosestIndex (const QList< RVector > &list, bool ignoreZ=false) const

int getClosestIndex2d (const QList< RVector > &list) const

double getDistanceTo (const RVector &v) const

double getDistanceTo2d (const RVector &v) const

RVector getDividedComponents (const RVector &v) const

RVector getFloor () const

RVector getLerp (const RVector &v, double t) const
Linear interpolation between this and `v` by fraction 't'. More...

double getMagnitude () const

double getMagnitude2d () const

RVector getMultipliedComponents (const RVector &v) const

RVector getNegated () const

RVector getNormalized () const

double getSquaredMagnitude () const

RVector getTransformed (const RMatrix &m) const

RVector getTransformed2d (const QTransform &t) const

RVector getTransformed2dM (const RMatrix &m) const

RVector getUnitVector () const

double getX ()

double getY ()

double getZ ()

bool gteXY (const RVector &v) const

bool isInside (const RBox &b) const

bool isInWindow (const RVector &firstCorner, const RVector &secondCorner)

bool isNaN () const

RVector isoProject (RS::IsoProjectionType type, bool trueScale)
Changes this vector into its isometric projection. More...

bool isSane () const

bool isValid () const

bool lteXY (const RVector &v) const

RVector mirror (const RLine &axis)
Mirrors this vector at the given axis. More...

RVector mirror (const RVector &axis1, const RVector &axis2)

RVector move (const RVector &offset)
Moves this vector by the given offset. More...

RVector normalize ()
Normalizes this vector and returns a reference to this vector. More...

bool operator!= (const RVector &v) const

RVector operator* (double s) const
binary * operator. More...

void operator*= (double s)
*= operator More...

RVector operator+ (const RVector &v) const
binary + operator. More...

void operator+= (const RVector &v)
+= operator. More...

RVector operator- (const RVector &v) const
binary - operator. More...

RVector operator- () const
unary - operator. More...

void operator-= (const RVector &v)
-= operator. More...

RVector operator/ (double s) const
binary / operator. More...

void operator/= (double s)
/= operator More...

bool operator== (const RVector &v) const
== operator More...

RVector rotate (double rotation)
Rotates this vector around 0/0 by the given angle. More...

RVector rotate (double rotation, const RVector &center)
Rotates this vector around the given center by the given angle. More...

RVector rotate3d (const RLine &axis, double rotation)

RVector rotate3d (const QQuaternion &quaternion)

RVector ()
Constructor for a valid vector (0/0/0). More...

RVector (double vx, double vy, double vz=0.0, bool valid_in=true)
Constructor for a point with given valid flag. More...

RVector (const QList< double > &tuples)

RVector scale (double factor, const RVector &center=nullVector)
Scales this vector by the given factor with the given center. More...

RVector scale (const RVector &factors, const RVector &center=nullVector)
Scales this vector by the given factors with the given center. More...

void set (double vx, double vy, double vz=0.0)
Sets new values for the vector and makes the vector valid. More...

void setAngle (double a)

void setMagnitude2d (double m)
Sets the vector magnitude without chaning the direction. More...

void setPolar (double radius, double angle)
Sets a new position for the vector in polar coordinates. More...

void setX (double x)

void setY (double y)

void setZ (double z)

RVector stretch (const RPolyline &area, const RVector &offset)
Moves this vector by offset if it is inside the given area. More...

RVector transform (const RMatrix &m)
Generic 3d transformation. More...

RVector transform2d (const QTransform &t)
Transforms this vector with the given transformation matrix. More...

RVector transform2dM (const RMatrix &m)
Generic 2d transformation. More...

Static Public Member Functions

static bool containsFuzzy (const QList< RVector > &vectors, const RVector &v, double tol=RS::PointTolerance)

static RVector createPolar (double radius, double angle)

static RVector getAverage (const RVector &v1, const RVector &v2)
Convenience function. More...

static RVector getAverage (const QList< RVector > &vectors)

static RVector getCrossProduct (const RVector &v1, const RVector &v2)

static double getDotProduct (const RVector &v1, const RVector &v2)
Scalarproduct (dot product). More...

static RVector getMaximum (const QList< RVector > &vectors)

static RVector getMaximum (const RVector &v1, const RVector &v2)

static RVector getMaximumX (const QList< RVector > &vectors)

static RVector getMaximumY (const QList< RVector > &vectors)

static RVector getMinimum (const QList< RVector > &vectors)

static RVector getMinimum (const RVector &v1, const RVector &v2)

static RVector getMinimumX (const QList< RVector > &vectors)

static RVector getMinimumY (const QList< RVector > &vectors)

static QList< RVectorgetSortedByAngle (const QList< RVector > &list, const RVector &center, double angle)

static QList< RVectorgetSortedByDistance (const QList< RVector > &list, const RVector &v)

static QList< RVectorgetSortedLeftRightTopBottom (const QList< RVector > &list)

static QList< RVectorgetUnion (const QList< RVector > &vectorsA, const QList< RVector > &vectorsB, double tol=RS::PointTolerance)

static QList< double > getXList (const QList< RVector > &vectors)

static QList< double > getYList (const QList< RVector > &vectors)

static QList< double > getZList (const QList< RVector > &vectors)

static bool greaterThanEqualXY (const RVector &v1, const RVector &v2)

static bool greaterThanX (const RVector &v1, const RVector &v2)

static bool greaterThanY (const RVector &v1, const RVector &v2)

static bool lessThanEqualXY (const RVector &v1, const RVector &v2)

static bool lessThanX (const RVector &v1, const RVector &v2)

static bool lessThanY (const RVector &v1, const RVector &v2)

static void moveList (QList< RVector > &list, const RVector &offset)

static void rotateList (QList< RVector > &list, double rotation)

static void rotateList (QList< RVector > &list, double rotation, const RVector &center)

static void scaleList (QList< RVector > &list, double factor, const RVector &center=nullVector)

static void scaleList (QList< RVector > &list, const RVector &factors, const RVector &center=nullVector)

Public Attributes

bool valid
Getter function for this property: isValid. More...

double x
Getter function for this property: getX. More...

double y
Getter function for this property: getY. More...

double z
Getter function for this property: getZ. More...

Static Public Attributes

static const RVector invalid = RVector(0, 0, 0, false)
invalid vector More...

static const RVector nanVector = RVector(RNANDOUBLE, RNANDOUBLE, RNANDOUBLE, true)
NaN vector. More...

static const RVector nullVector = RVector(0, 0, 0, true)
null vector More...

Detailed Description

Represents a 3d vector (x/y/z).

Scriptable:
This class is available in script environments.
Copyable:
Objects are cleaned up automatically by the garbage collector of the script engine.

Constructor & Destructor Documentation

 RVector::RVector ( )
inline

Constructor for a valid vector (0/0/0).

 RVector::RVector ( double vx, double vy, double vz = `0.0`, bool valid_in = `true` )

Constructor for a point with given valid flag.

Parameters
 v true: a valid vector with default coordinates is created. false: an invalid vector is created Constructor for a point with given coordinates.
 RVector::RVector ( const QList< double > & tuples )

Member Function Documentation

 bool RVector::containsFuzzy ( const QList< RVector > & vectors, const RVector & v, double tol = `RS::PointTolerance` )
static
 static RVector RVector::createPolar ( double radius, double angle )
inlinestatic
 double RVector::dot ( const RVector & other )
inline
 bool RVector::equalsFuzzy ( const RVector & v, double tol = `RS::PointTolerance` ) const
Returns
True if this vector and the given vector are almost equal (see RS::PointTolerance).
Parameters
 tol Tolerance in X, Y and Z.
 bool RVector::equalsFuzzy2D ( const RVector & v, double tol = `RS::PointTolerance` ) const
Returns
True if this vector and the given vector are almost equal (see RS::PointTolerance) in 2D space (x,y).
Parameters
 tol Tolerance in X, Y.
 RVector RVector::flipHorizontal ( )

Mirrors this vector at the Y-axis.

 RVector RVector::flipVertical ( )

Mirrors this vector at the X-axis.

 RVector RVector::get2D ( ) const
inline
 double RVector::getAngle ( ) const
Returns
The angle from zero to this vector (in rad).
 double RVector::getAngleTo ( const RVector & v ) const
Returns
The angle from this and the given coordinate (in rad).
 double RVector::getAngleToPlaneXY ( ) const
Returns
Angle between this vector and XY plane (horizontal plane).
 RVector RVector::getAverage ( const RVector & v1, const RVector & v2 )
static

Convenience function.

Returns
(v1 + v2) / 2.0
 RVector RVector::getAverage ( const QList< RVector > & vectors )
static
 RVector RVector::getCeil ( ) const
Returns
Vector with all components ceiled to the next higher integer.
 RVector RVector::getClosest ( const QList< RVector > & list ) const
Returns
The vector in the given vectors that is closest to this vector or an invalid vector if the given vector does not contain any (valid) vectors.
 RVector RVector::getClosest2d ( const QList< RVector > & list ) const
 double RVector::getClosestDistance ( const QList< RVector > & list, int counts )
 int RVector::getClosestIndex ( const QList< RVector > & list, bool ignoreZ = `false` ) const
 int RVector::getClosestIndex2d ( const QList< RVector > & list ) const
inline
 RVector RVector::getCrossProduct ( const RVector & v1, const RVector & v2 )
static
Returns
Cross product of two vectors.
 double RVector::getDistanceTo ( const RVector & v ) const
Returns
The distance between this and the given coordinate.
 double RVector::getDistanceTo2d ( const RVector & v ) const
Returns
The distance between this and the given coordinate on the XY plane.
 RVector RVector::getDividedComponents ( const RVector & v ) const
Returns
A new vector with all components divided by the components given in vector `v`. Note that the division of two vectors is not defined. This is merely a helper function that does what it does.
Todo:
refactor
 double RVector::getDotProduct ( const RVector & v1, const RVector & v2 )
static

Scalarproduct (dot product).

 RVector RVector::getFloor ( ) const
Returns
Vector with all components floored to the next lower integer.
 RVector RVector::getLerp ( const RVector & v, double t ) const

Linear interpolation between this and `v` by fraction 't'.

 double RVector::getMagnitude ( ) const
Returns
Magnitude (length) of the vector.
 double RVector::getMagnitude2d ( ) const
Returns
Magnitude (length) of the vector projected to the x/y plane (2d).
 RVector RVector::getMaximum ( const QList< RVector > & vectors )
static
Returns
A vector with the maximum components from the given vectors. These might be mixed components from all vectors.
 RVector RVector::getMaximum ( const RVector & v1, const RVector & v2 )
static
Returns
A vector with the maximum values from the vectors v1 and v2
 RVector RVector::getMaximumX ( const QList< RVector > & vectors )
static
Returns
That one vector from the given vectors with the largest X coordinate.
 RVector RVector::getMaximumY ( const QList< RVector > & vectors )
static
Returns
That one vector from the given vectors with the largest Y coordinate.
 RVector RVector::getMinimum ( const QList< RVector > & vectors )
static
Returns
A vector with the minimum components from the given vectors. These might be mixed components from all vectors.
 RVector RVector::getMinimum ( const RVector & v1, const RVector & v2 )
static
Returns
A vector with the minimum components from the vectors v1 and v2. These might be mixed components from both vectors.
 RVector RVector::getMinimumX ( const QList< RVector > & vectors )
static
Returns
That one vector from the given vectors with the smallest X coordinate.
 RVector RVector::getMinimumY ( const QList< RVector > & vectors )
static
Returns
That one vector from the given vectors with the smallest Y coordinate.
 RVector RVector::getMultipliedComponents ( const RVector & v ) const
Returns
A new vector with all components multiplied by the components given in vector `v`. Note that the multiplication of two vectors is not defined. This is merely a helper function that does what it does.
Todo:
refactor
 RVector RVector::getNegated ( ) const
Returns
New vector with negated components.
 RVector RVector::getNormalized ( ) const
Returns
A new unit vector with the same direction as this vector.
 QList< RVector > RVector::getSortedByAngle ( const QList< RVector > & list, const RVector & center, double angle )
static
Returns
List of same vectors as given, ordered by shortes angle difference to given reference angle.
 QList< RVector > RVector::getSortedByDistance ( const QList< RVector > & list, const RVector & v )
static
Returns
List of same vectors as given, ordered by shortes distance to given vector v.
 QList< RVector > RVector::getSortedLeftRightTopBottom ( const QList< RVector > & list )
static
Returns
List of same vectors as given, ordered from left to right, top to bottom.
 double RVector::getSquaredMagnitude ( ) const
Returns
Square of magnitude (length).
 RVector RVector::getTransformed ( const RMatrix & m ) const
Returns
A new vector which is the result of this vector transformed by the given matrix.
 RVector RVector::getTransformed2d ( const QTransform & t ) const
Returns
A new vector which is the result of this vector transformed by the given transformation matrix.
 RVector RVector::getTransformed2dM ( const RMatrix & m ) const
Returns
A new vector which is the result of this vector transformed by the given matrix.
 QList< RVector > RVector::getUnion ( const QList< RVector > & vectorsA, const QList< RVector > & vectorsB, double tol = `RS::PointTolerance` )
static
Returns
Union based on fuzzy comparison.
 RVector RVector::getUnitVector ( ) const
Returns
Unit vector for this vector.
 double RVector::getX ( )
 QList< double > RVector::getXList ( const QList< RVector > & vectors )
static
Returns
All X values of the given list of vectors as a new list.
 double RVector::getY ( )
 QList< double > RVector::getYList ( const QList< RVector > & vectors )
static
Returns
All Y values of the given list of vectors as a new list.
 double RVector::getZ ( )
 QList< double > RVector::getZList ( const QList< RVector > & vectors )
static
Returns
All Z values of the given list of vectors as a new list.
 static bool RVector::greaterThanEqualXY ( const RVector & v1, const RVector & v2 )
inlinestatic
 static bool RVector::greaterThanX ( const RVector & v1, const RVector & v2 )
inlinestatic
 static bool RVector::greaterThanY ( const RVector & v1, const RVector & v2 )
inlinestatic
 bool RVector::gteXY ( const RVector & v ) const
inline
 bool RVector::isInside ( const RBox & b ) const
Returns
True if this vector is inside the given box, false otherwise.
 bool RVector::isInWindow ( const RVector & firstCorner, const RVector & secondCorner )
Returns
true if this vector is within the given range (2d).
 bool RVector::isNaN ( ) const
 RVector RVector::isoProject ( RS::IsoProjectionType type, bool trueScale )

Changes this vector into its isometric projection.

Todo:
refactor
 bool RVector::isSane ( ) const
 bool RVector::isValid ( ) const
 static bool RVector::lessThanEqualXY ( const RVector & v1, const RVector & v2 )
inlinestatic
 static bool RVector::lessThanX ( const RVector & v1, const RVector & v2 )
inlinestatic
 static bool RVector::lessThanY ( const RVector & v1, const RVector & v2 )
inlinestatic
 bool RVector::lteXY ( const RVector & v ) const
inline
 RVector RVector::mirror ( const RLine & axis )

Mirrors this vector at the given axis.

 RVector RVector::mirror ( const RVector & axis1, const RVector & axis2 )
 RVector RVector::move ( const RVector & offset )

Moves this vector by the given offset.

Equal to the operator +=.

 void RVector::moveList ( QList< RVector > & list, const RVector & offset )
static
Non-Scriptable:
This function is not available in script environments.
 RVector RVector::normalize ( )

Normalizes this vector and returns a reference to this vector.

 bool RVector::operator!= ( const RVector & v ) const
inline
 RVector RVector::operator* ( double s ) const

binary * operator.

 void RVector::operator*= ( double s )

*= operator

 RVector RVector::operator+ ( const RVector & v ) const

binary + operator.

 void RVector::operator+= ( const RVector & v )

+= operator.

The result is only valid if both vectors are valid.

 RVector RVector::operator- ( const RVector & v ) const

binary - operator.

 RVector RVector::operator- ( ) const

unary - operator.

 void RVector::operator-= ( const RVector & v )

-= operator.

The result is only valid if both vectors are valid.

 RVector RVector::operator/ ( double s ) const

binary / operator.

 void RVector::operator/= ( double s )

/= operator

 bool RVector::operator== ( const RVector & v ) const

== operator

 RVector RVector::rotate ( double rotation )

Rotates this vector around 0/0 by the given angle.

 RVector RVector::rotate ( double rotation, const RVector & center )

Rotates this vector around the given center by the given angle.

 RVector RVector::rotate3d ( const RLine & axis, double rotation )
 RVector RVector::rotate3d ( const QQuaternion & quaternion )
 void RVector::rotateList ( QList< RVector > & list, double rotation )
static
Non-Scriptable:
This function is not available in script environments.
 void RVector::rotateList ( QList< RVector > & list, double rotation, const RVector & center )
static
Non-Scriptable:
This function is not available in script environments.
 RVector RVector::scale ( double factor, const RVector & center = `nullVector` )

Scales this vector by the given factor with the given center.

 RVector RVector::scale ( const RVector & factors, const RVector & center = `nullVector` )

Scales this vector by the given factors with the given center.

 void RVector::scaleList ( QList< RVector > & list, double factor, const RVector & center = `nullVector` )
static
Non-Scriptable:
This function is not available in script environments.
 void RVector::scaleList ( QList< RVector > & list, const RVector & factors, const RVector & center = `nullVector` )
static
Non-Scriptable:
This function is not available in script environments.
 void RVector::set ( double vx, double vy, double vz = `0.0` )
inline

Sets new values for the vector and makes the vector valid.

 void RVector::setAngle ( double a )
 void RVector::setMagnitude2d ( double m )

Sets the vector magnitude without chaning the direction.

 void RVector::setPolar ( double radius, double angle )

Sets a new position for the vector in polar coordinates.

Parameters
 void RVector::setX ( double x )
 void RVector::setY ( double y )
 void RVector::setZ ( double z )
 RVector RVector::stretch ( const RPolyline & area, const RVector & offset )

Moves this vector by offset if it is inside the given area.

 RVector RVector::transform ( const RMatrix & m )

Generic 3d transformation.

`m` must be a 3x3 matrix.

 RVector RVector::transform2d ( const QTransform & t )

Transforms this vector with the given transformation matrix.

 RVector RVector::transform2dM ( const RMatrix & m )

Generic 2d transformation.

`m` must be a 3x2 matrix.

Member Data Documentation

 const RVector RVector::invalid = RVector(0, 0, 0, false)
static

invalid vector

Copyright (c) 2011-2016 by Andrew Mustun.

This file is part of the QCAD project.

QCAD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QCAD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

 const RVector RVector::nanVector = RVector(RNANDOUBLE, RNANDOUBLE, RNANDOUBLE, true)
static

NaN vector.

 const RVector RVector::nullVector = RVector(0, 0, 0, true)
static

null vector

 bool RVector::valid

Getter function for this property: isValid.

 double RVector::x

Getter function for this property: getX.

Setter function for this property: setX

 double RVector::y

Getter function for this property: getY.

Setter function for this property: setY

 double RVector::z

Getter function for this property: getZ.

Setter function for this property: setZ

The documentation for this class was generated from the following files: