Class Vector2

Class Documentation

class Vector2

A class representing a 2D vector or 2D point.

This class mimics the tf2::Vector3 class to the extent possible.

Public Types

enum Axis

Axis constants.

Values:

enumerator X

X axis.

enumerator Y

Y axis.

Public Functions

inline Vector2()

No initialization constructor.

inline Vector2(const tf2Scalar x, const tf2Scalar y)

Constructor from scalars.

Parameters:
  • x – X value

  • y – Y value

inline Vector2 operator-() const

Return the negative of the vector.

inline Vector2 &operator+=(const Vector2 &rhs)

Add a vector to this one.

Parameters:

rhs – The vector to add to this one

inline Vector2 &operator-=(const Vector2 &rhs)

Subtract a vector from this one.

Parameters:

rhs – The vector to subtract

inline Vector2 &operator*=(const tf2Scalar rhs)

Scale the vector.

Parameters:

rhs – Scale factor

inline Vector2 &operator*=(const Vector2 &rhs)

Element-wise multiply this vector by the other.

Parameters:

v – The other vector

inline Vector2 &operator/=(const tf2Scalar rhs)

Inversely scale the vector.

Parameters:

rhs – Scale factor to divide by

inline Vector2 &operator/=(const Vector2 &rhs)

Element-wise divide this vector by the other.

Parameters:

rhs – The other vector

inline bool operator==(const Vector2 &other) const

Check if two vectors are equal.

inline bool operator!=(const Vector2 &other) const

Check if two vectors are not equal.

inline tf2Scalar dot(const Vector2 &other) const

Return the dot product.

Parameters:

v – The other vector in the dot product

inline tf2Scalar length2() const

Return the length of the vector squared.

inline tf2Scalar length() const

Return the length of the vector.

inline tf2Scalar distance2(const Vector2 &other) const

Return the distance squared between the ends of this and another vector.

This is semantically treating the vector like a point

inline tf2Scalar distance(const Vector2 &other) const

Return the distance between the ends of this and another vector.

This is semantically treating the vector like a point

inline Vector2 &normalize()

Normalize this vector.

x^2 + y^2 = 1

inline Vector2 normalized() const

Return a normalized version of this vector.

inline tf2Scalar angle(const Vector2 &other) const

Return the angle between this and another vector.

Parameters:

other – The other vector

inline Vector2 absolute() const

Return a vector with the absolute values of each element.

inline Axis minAxis() const

Return the axis with the smallest value.

Note return values are 0,1 for x or y

inline Axis maxAxis() const

Return the axis with the largest value.

Note return values are 0,1 for x or y

inline Axis furthestAxis() const

Returns the axis with the smallest absolute value.

Note return values are 0,1 for x or y Seems like a poorly named function, but mimicking the tf2::Vector3 class

inline Axis closestAxis() const

Returns the axis with the largest absolute value.

Note return values are 0,1 for x or y Seems like a poorly named function, but mimicking the tf2::Vector3 class

inline Vector2 lerp(const Vector2 &other, const tf2Scalar ratio) const

Return the linear interpolation between this and another vector.

Parameters:
  • other – The other vector

  • ratio – The ratio of this to other (ratio=0 => return this, ratio=1 => return other)

inline const tf2Scalar &getX() const

Return the x value.

inline const tf2Scalar &x() const
inline const tf2Scalar &getY() const

Return the y value.

inline const tf2Scalar &y() const
inline void setX(const tf2Scalar x)

Set the x value.

inline void setY(const tf2Scalar y)

Set the y value.

inline void setMax(const Vector2 &other)

Set each element to the max of the current values and the values of another Vector3.

Parameters:

other – The other Vector3 to compare with

inline void setMin(const Vector2 &other)

Set each element to the min of the current values and the values of another Vector3.

Parameters:

other – The other Vector3 to compare with

inline void setValue(const tf2Scalar x, const tf2Scalar y)

Set each element to the provided value.

Parameters:
  • x – The X value

  • y – The Y value

inline void setZero()

Set all elements of this vector to zero

inline bool isZero() const

Check if all the elements of this vector are zero

inline bool fuzzyZero() const

Check if all the elements of this vector close to zero

inline Eigen::Vector2d getVector() const

Get an Eigen vector representation.

inline Eigen::Matrix3d getHomogeneousMatrix() const

Get a 3x3 homogeneous transformation matrix with just the translation portion populated.