QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RVector Class Reference

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

#include <RVector.h>

List of all members.

Classes

class  RVectorAngleSort
class  RVectorDistanceSort

Public Member Functions

bool equalsFuzzy (const RVector &v, double tol=RS::PointTolerance) const
RVector flipHorizontal ()
 Mirrors this vector at the Y-axis.
RVector flipVertical ()
 Mirrors this vector at the X-axis.
double getAngle () const
double getAngleTo (const RVector &v) const
double getAngleToPlaneXY () const
RVector getCeil () const
RVector getClosest (const QList< RVector > &list) const
double getClosestDistance (const QList< RVector > &list, int counts)
int getClosestIndex (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'.
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 isInside (const RBox &b) const
bool isInWindow (const RVector &firstCorner, const RVector &secondCorner)
RVector isoProject (RS::IsoProjectionType type, bool trueScale)
 Changes this vector into its isometric projection.
bool isValid () const
RVector mirror (const RLine &axis)
 Mirrors this vector at the given axis.
RVector mirror (const RVector &axis1, const RVector &axis2)
RVector move (const RVector &offset)
 Moves this vector by the given offset.
RVector normalize ()
 Normalizes this vector and returns a reference to this vector.
bool operator!= (const RVector &v) const
RVector operator* (double s) const
 binary * operator.
void operator*= (double s)
 *= operator
RVector operator+ (const RVector &v) const
 binary + operator.
void operator+= (const RVector &v)
 += operator.
RVector operator- (const RVector &v) const
 binary - operator.
RVector operator- () const
 unary - operator.
void operator-= (const RVector &v)
 -= operator.
RVector operator/ (double s) const
 binary / operator.
void operator/= (double s)
 /= operator
bool operator== (const RVector &v) const
 == operator
RVector rotate (double rotation)
 Rotates this vector around 0/0 by the given angle.
RVector rotate (double rotation, const RVector &center)
 Rotates this vector around the given center by the given angle.
RVector rotate3d (const RLine &axis, double rotation)
RVector rotate3d (const QQuaternion &quaternion)
 RVector ()
 Constructor for a valid vector (0/0/0).
 RVector (double vx, double vy, double vz=0.0, bool valid_in=true)
 Constructor for a point with given valid flag.
RVector scale (double factor, const RVector &center=nullVector)
 Scales this vector by the given factor with the given center.
RVector scale (const RVector &factors, const RVector &center=nullVector)
 Scales this vector by the given factors with the given center.
void set (double vx, double vy, double vz=0.0)
 Sets new values for the vector and makes the vector valid.
void setAngle (double a)
void setMagnitude2d (double m)
 Sets the vector magnitude without chaning the direction.
void setPolar (double radius, double angle)
 Sets a new position for the vector in polar coordinates.
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.
RVector transform (const RMatrix &m)
 Generic 3d transformation.
RVector transform2d (const QTransform &t)
 Transforms this vector with the given transformation matrix.
RVector transform2dM (const RMatrix &m)
 Generic 2d transformation.

Static Public Member Functions

static RVector createPolar (double radius, double angle)
static RVector getAverage (const RVector &v1, const RVector &v2)
 Convenience function.
static RVector getCrossProduct (const RVector &v1, const RVector &v2)
static double getDotProduct (const RVector &v1, const RVector &v2)
 Scalarproduct (dot product).
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< double > getXList (const QList< RVector > &vectors)
static QList< double > getYList (const QList< RVector > &vectors)
static QList< double > getZList (const QList< RVector > &vectors)
static bool greaterThanX (const RVector &v1, const RVector &v2)
static bool greaterThanY (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.
double x
 Getter function for this property: getX.
double y
 Getter function for this property: getY.
double z
 Getter function for this property: getZ.

Static Public Attributes

static const RVector invalid = RVector(0, 0, 0, false)
 invalid vector
static const RVector nullVector = RVector(0, 0, 0, true)
 null vector

Detailed Description

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

Scriptable:
This class is wrapped for script environments.
Copyable:
Script wrappers of this class should pass objects by reference.

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:
vtrue: a valid vector with default coordinates is created. false: an invalid vector is created Constructor for a point with given coordinates.

Member Function Documentation

static RVector RVector::createPolar ( double  radius,
double  angle 
)
inlinestatic
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:
tolTolerance in X, Y and Z.
RVector RVector::flipHorizontal ( )

Mirrors this vector at the Y-axis.

RVector RVector::flipVertical ( )

Mirrors this vector at the X-axis.

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::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.
double RVector::getClosestDistance ( const QList< RVector > &  list,
int  counts 
)
int RVector::getClosestIndex ( const QList< RVector > &  list) const
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.
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.
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::greaterThanX ( const RVector v1,
const RVector v2 
)
inlinestatic
static bool RVector::greaterThanY ( const RVector v1,
const RVector v2 
)
inlinestatic
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).
RVector RVector::isoProject ( RS::IsoProjectionType  type,
bool  trueScale 
)

Changes this vector into its isometric projection.

Todo:
refactor
bool RVector::isValid ( ) const
static bool RVector::lessThanX ( const RVector v1,
const RVector v2 
)
inlinestatic
static bool RVector::lessThanY ( const RVector v1,
const RVector v2 
)
inlinestatic
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
   \par 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
   \par Non-Scriptable:

This function is not available in script environments.

void RVector::rotateList ( QList< RVector > &  list,
double  rotation,
const RVector center 
)
static
   \par 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
   \par Non-Scriptable:

This function is not available in script environments.

void RVector::scaleList ( QList< RVector > &  list,
const RVector factors,
const RVector center = nullVector 
)
static
   \par 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:
radiusthe radius or the distance
anglethe angle in rad
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-2013 by Andrew Mustun.

All rights reserved.

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.

You should have received a copy of the GNU General Public License along with QCAD.

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: