Skip to content

RVector

Class in Math Module
Header: #include <src/core/math/RVector.h>
Inherited by: RRefPoint
Nested classes: RVectorAngleSort, RVectorDistanceSort, RVectorLeftRightTopBottomSort

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.

RVector()
Constructor for a valid null vector (0/0/0).
RVector(const QList< double > &tuples)
Constructor from a list of up to three doubles (x, y, z).
RVector(double vx, double vy, double vz=0.0, bool valid_in=true)
Constructor for a point with given valid flag.
~RVector()
RVector axonometricProjection(RS::IsoProjectionType type)
Axonometric projection (isometric, dimetric, trimetric).
double dot(const RVector &other) const
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.
RVector flipVertical()
Mirrors this vector at the X-axis.
RVector get2D() const
RVector getAbsolute() 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’.
double getMagnitude() const
double getMagnitude2D() const
RVector getMirrored(const RLine &axis) const
RVector getMultipliedComponents(const RVector &v) const
RVector getNegated() const
RVector getNormalized() const
RVector getRotated(double rotation, const RVector &center) const
RVector getScaled(const RVector &factors, const RVector &center) 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() const
double getY() const
double getZ() const
bool gteXY(const RVector &v) const
bool isInside(const RBox &b) const
bool isInWindow(const RVector &firstCorner, const RVector &secondCorner) const
bool isNaN() const
RVector isoProject(RS::IsoProjectionType type)
Changes this vector into its isometric projection.
bool isSane() const
bool isValid() const
bool isZero() const
bool lteXY(const RVector &v) const
RVector mirror(const RLine &axis)
Mirrors this vector at the given axis.
RVector mirror(const RVector &axis1, const RVector &axis2)
Mirrors this vector at the axis defined by two points.
RVector move(const RVector &offset)
Moves this vector by the given offset.
RVector normalize()
Normalizes this vector and returns a reference to this vector.
RVector obliqueProjection(RS::IsoProjectionType type)
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
unary - operator.
RVector operator-(const RVector &v) const
binary - 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 the origin by the given angle (in rad).
RVector rotate(double rotation, const RVector &center)
Rotates this vector around the given center by the given angle.
RVector rotate3D(const QQuaternion &quaternion)
Rotates this vector by the given quaternion.
RVector rotate3D(const RLine &axis, double rotation)
Rotates this vector around the given 3D axis line by the given angle (in rad).
RVector scale(const RVector &factors, const RVector &center=nullVector)
Scales this vector by the given factors with the given center.
RVector scale(double factor, const RVector &center=nullVector)
Scales this vector by the given factor 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)
Sets the direction of this vector to the given angle (in rad), preserving its magnitude.
void setMagnitude2D(double m)
Sets the vector magnitude without changing 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 bool containsFuzzy(const QList< RVector > &vectors, const RVector &v, double tol=RS::PointTolerance)
static RVector createPolar(double radius, double angle)
static int findFirstFuzzy(const QList< RVector > &vectors, const RVector &v, double tol=RS::PointTolerance)
static RVector getAverage(const QList< RVector > &vectors)
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 QList< RVector > getIntersection(const QList< RVector > &vectorsA, const QList< RVector > &vectorsB, double tol=RS::PointTolerance)
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< RVector > getSortedByAngle(const QList< RVector > &list, const RVector &center, double angle)
static QList< RVector > getSortedByDistance(const QList< RVector > &list, const RVector &v)
static QList< RVector > getSortedLeftRightTopBottom(const QList< RVector > &list)
static QList< RVector > getUnique(const QList< RVector > &vectors, 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)
Moves all vectors in the list by the given offset.
static void rotateList(QList< RVector > &list, double rotation)
Rotates all vectors in the list around the origin by the given angle (in rad).
static void rotateList(QList< RVector > &list, double rotation, const RVector &center)
Rotates all vectors in the list around center by the given angle (in rad).
static void scaleList(QList< RVector > &list, const RVector &factors, const RVector &center=nullVector)
Scales all vectors in the list by the given per-axis factors around center.
static void scaleList(QList< RVector > &list, double factor, const RVector &center=nullVector)
Scales all vectors in the list by the given uniform factor around center.
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 const RVector invalid
invalid vector
static const RVector nanVector
NaN vector.
static const RVector nullVector
null vector
static const RVector zAxis
Z axis vector (default extrusion direction).

RVector::RVector()

inline

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

explicit RVector::RVector(const QList< double > &tuples)

explicit

Constructor from a list of up to three doubles (x, y, z).

Missing components default to 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()

RVector RVector::axonometricProjection(RS::IsoProjectionType type)

Axonometric projection (isometric, dimetric, trimetric).

double RVector::dot(const RVector &other) const

inline const

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

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

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 const

RVector RVector::getAbsolute() const

const

Returns: A new vector with all components replaced by their absolute values.

double RVector::getAngle() const

const

Returns: The angle from zero to this vector (in rad), in range [0, 2*PI).

double RVector::getAngleTo(const RVector &v) const

const

Returns: The angle from this and the given coordinate (in rad).

double RVector::getAngleToPlaneXY() const

const

Returns: Elevation angle above the XY plane (in rad). Positive above, negative below. Returns PI/2 for zero-length vectors.

RVector RVector::getCeil() const

const

Returns: Vector with all components ceiled to the next higher integer.

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

const

Returns: The vector in list closest to this vector (3D distance), with Z set to 0, or an invalid vector if the list contains no valid vectors.

RVector RVector::getClosest2D(const QList< RVector > &list) const

const

Returns: The vector in list closest to this vector (2D distance, Z ignored), or an invalid vector if the list contains no valid vectors.

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

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

const

int RVector::getClosestIndex2D(const QList< RVector > &list) const

inline const

double RVector::getDistanceTo(const RVector &v) const

const

Returns: The distance between this and the given coordinate.

double RVector::getDistanceTo2D(const RVector &v) const

const

Returns: The distance between this and the given coordinate on the XY plane.

RVector RVector::getDividedComponents(const RVector &v) const

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.

RVector RVector::getFloor() const

const

Returns: Vector with all components floored to the next lower integer.

RVector RVector::getLerp(const RVector &v, double t) const

const

Linear interpolation between this and v by fraction ‘t’.

double RVector::getMagnitude() const

const

Returns: Magnitude (length) of the vector.

double RVector::getMagnitude2D() const

const

Returns: Magnitude (length) of the vector projected to the x/y plane (2d).

RVector RVector::getMirrored(const RLine &axis) const

const

Returns: A new vector equal to this vector mirrored at the given axis line.

RVector RVector::getMultipliedComponents(const RVector &v) const

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.

RVector RVector::getNegated() const

const

Returns: New vector with negated components.

RVector RVector::getNormalized() const

const

Returns: A new unit vector with the same direction as this vector.

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

const

Returns: A new vector equal to this vector rotated by rotation around center.

RVector RVector::getScaled(const RVector &factors, const RVector &center) const

const

Returns: A new vector equal to this vector scaled by factors around center.

double RVector::getSquaredMagnitude() const

const

Returns: Square of magnitude (length).

RVector RVector::getTransformed(const RMatrix &m) const

const

Returns: A new vector which is the result of this vector transformed by the given matrix.

RVector RVector::getTransformed2D(const QTransform &t) const

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

const

Returns: A new vector which is the result of this vector transformed by the given matrix.

RVector RVector::getUnitVector() const

const

Returns: Unit vector for this vector.

double RVector::getX() const

const

double RVector::getY() const

const

double RVector::getZ() const

const

bool RVector::gteXY(const RVector &v) const

inline const

bool RVector::isInside(const RBox &b) const

const

Returns: True if this vector is inside the given box, false otherwise.

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

const

Returns: true if this vector is within the given range (2d).

bool RVector::isNaN() const

const

Returns: True if any component is NaN.

RVector RVector::isoProject(RS::IsoProjectionType type)

Changes this vector into its isometric projection.

bool RVector::isSane() const

const

Returns: True if this vector is valid and all components are finite (not NaN or Inf).

bool RVector::isValid() const

const

Returns: True if this vector is valid (not explicitly marked invalid).

bool RVector::isZero() const

const

Returns: True if all components are within PointTolerance of zero.

bool RVector::lteXY(const RVector &v) const

inline const

RVector RVector::mirror(const RLine &axis)

Mirrors this vector at the given axis.

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

Mirrors this vector at the axis defined by two points.

RVector RVector::move(const RVector &offset)

Moves this vector by the given offset.

Equal to the operator +=.

RVector RVector::normalize()

Normalizes this vector and returns a reference to this vector.

RVector RVector::obliqueProjection(RS::IsoProjectionType type)

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

inline const

RVector RVector::operator*(double s) const

const

binary * operator.

void RVector::operator*=(double s)

*= operator

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

const

binary + operator.

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

+= operator.

The result is only valid if both vectors are valid.

RVector RVector::operator-() const

const

unary - operator.

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

const

binary - operator.

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

-= operator.

The result is only valid if both vectors are valid.

RVector RVector::operator/(double s) const

const

binary / operator.

void RVector::operator/=(double s)

/= operator

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

const

== operator

RVector RVector::rotate(double rotation)

Rotates this vector around the origin by the given angle (in rad).

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

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

RVector RVector::rotate3D(const QQuaternion &quaternion)

Rotates this vector by the given quaternion.

RVector RVector::rotate3D(const RLine &axis, double rotation)

Rotates this vector around the given 3D axis line by the given angle (in rad).

The axis direction is taken as startPoint - endPoint.

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

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

RVector RVector::scale(double factor, const RVector &center=nullVector)

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

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)

Sets the direction of this vector to the given angle (in rad), preserving its magnitude.

void RVector::setMagnitude2D(double m)

Sets the vector magnitude without changing the direction.

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

Sets a new position for the vector in polar coordinates.

Parameters:

  • radius: the radius or the distance
  • angle: the 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.

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

static

Returns: True if vectors contains a vector approximately equal to v within tol.

static RVector RVector::createPolar(double radius, double angle)

static inline

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

static

Returns: Index of the first vector in vectors approximately equal to v within tol, or -1 if not found.

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

static

Returns: The average (centroid) of the given vectors, or an invalid vector if the list is empty.

static RVector RVector::getAverage(const RVector &v1, const RVector &v2)

static

Convenience function.

Returns: (v1 + v2) / 2.0

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

static

Returns: Cross product of two vectors.

static double RVector::getDotProduct(const RVector &v1, const RVector &v2)

static

Scalarproduct (dot product).

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

static

Returns: Elements of vectorsA that also appear in vectorsB (fuzzy intersection).

static 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.

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

static

Returns: A vector with the maximum values from the vectors v1 and v2

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

static

Returns: That one vector from the given vectors with the largest X coordinate.

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

static

Returns: That one vector from the given vectors with the largest Y coordinate.

static 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.

static 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.

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

static

Returns: That one vector from the given vectors with the smallest X coordinate.

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

static

Returns: That one vector from the given vectors with the smallest Y coordinate.

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

static

Returns: List of same vectors as given, ordered by shortest angle difference to given reference angle.

static 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.

static QList< RVector > RVector::getSortedLeftRightTopBottom(const QList< RVector > &list)

static

Returns: List of same vectors as given, ordered from left to right, top to bottom.

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

static

Returns: A copy of vectors with duplicate entries (within tol) removed, preserving the order of first occurrence.

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

static

Returns: All X values of the given list of vectors as a new list.

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

static

Returns: All Y values of the given list of vectors as a new list.

static 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)

static inline

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

static inline

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

static inline

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

static inline

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

static inline

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

static inline

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

static

Moves all vectors in the list by the given offset.

Non-Scriptable: This function is not available in script environments.

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

static

Rotates all vectors in the list around the origin by the given angle (in rad).

Non-Scriptable: This function is not available in script environments.

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

static

Rotates all vectors in the list around center by the given angle (in rad).

Non-Scriptable: This function is not available in script environments.

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

static

Scales all vectors in the list by the given per-axis factors around center.

Non-Scriptable: This function is not available in script environments.

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

static

Scales all vectors in the list by the given uniform factor around center.

Non-Scriptable: This function is not available in script environments.

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

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

static

invalid vector

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

static

NaN vector.

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

static

null vector

static const RVector RVector::zAxis = RVector(0, 0, 1, true)

static

Z axis vector (default extrusion direction).