Brick
Loading...
Searching...
No Matches
LinearVector2d< Q > Class Template Reference

#include <translation2d.h>

Description

template<LinearKinematicQuantity Q>
class LinearVector2d< Q >

Class representing a 2d vector. Depending on unit this could be a Translation2d, Velocity2d, Acceleration2d, Jerk2d, or other

Assumes conventional cartesian coordinate system: Looking down at the coordinate plane, +X is right +Y is up +Theta is counterclockwise

Public Member Functions

constexpr LinearVector2d ()
 Default Constructor for LinearVector2d valued (0, 0).
constexpr LinearVector2d (Q x, Q y)
constexpr LinearVector2d (Q r, Rotation2d theta)
constexpr LinearVector2d (Eigen::Vector2d vector, Q unit)
constexpr Q x () const
 Gets the x component.
constexpr double x (Q unit) const
 Gets x in the supplied unit.
constexpr void set_x (Q val)
 Sets the x component.
constexpr Q y () const
 Gets the y component.
constexpr double y (Q unit) const
 Gets y in the supplied unit.
constexpr void set_y (Q val)
 Sets the y component.
constexpr Rotation2d theta () const
 Gets the angle of the vector from the x axis.
constexpr Eigen::Vector2d as_vector (Q unit) const
constexpr Q norm () const
 Gets the norm of the vector.
constexpr LinearVector2d normalize (Q magnitude=Q(1.0)) const
constexpr Q distance (LinearVector2d other) const
 Gets the distance between two vectors.
constexpr LinearVector2d interpolate (LinearVector2d end, double fraction) const
constexpr LinearVector2d rotate_by (Rotation2d rotation) const
constexpr LinearVector2d rotate_around (LinearVector2d other, Rotation2d rotation) const
constexpr LinearVector2d inverse () const
constexpr units::Multiplied< Q, Q > dot (LinearVector2d other) const
constexpr LinearVector2d operator+ (LinearVector2d other) const
 Adds another vector to this vector component wise.
constexpr LinearVector2d & operator+= (LinearVector2d other)
 Adds another vector to this vector component wise.
constexpr LinearVector2d operator- (LinearVector2d other) const
 Subtracts another vector from this vector component wise.
constexpr LinearVector2d & operator-= (LinearVector2d other)
 Subtracts another vector from this vector component wise.
constexpr LinearVector2d operator- () const
 Inverts this vector (flipped across origin).
constexpr LinearVector2d operator* (double scalar) const
 Multiplies this vector by a scalar.
template<units::IsQuantity S>
requires LinearKinematicQuantity<units::Multiplied<Q, S>>
constexpr LinearVector2d< units::Multiplied< Q, S > > operator* (S scalar) const
constexpr units::Multiplied< Q, Q > operator* (LinearVector2d other) const
constexpr LinearVector2d & operator*= (double scalar)
 Multiplies this vector by a scalar.
constexpr LinearVector2d operator/ (double scalar) const
 Divides this vector by a scalar.
template<units::IsQuantity S>
requires LinearKinematicQuantity<units::Divided<Q, S>>
constexpr LinearVector2d< units::Divided< Q, S > > operator/ (S scalar) const
constexpr LinearVector2d & operator/= (double scalar)
 Divides this vector by a scalar.
constexpr bool operator== (LinearVector2d other) const
 Checks exact equality between this and another vector.
constexpr bool is_near (LinearVector2d other, Q tolerance=Q(1e-6)) const

Static Public Member Functions

static constexpr LinearVector2d mean (const std::vector< LinearVector2d > &list)

Friends

constexpr LinearVector2d operator* (double scalar, LinearVector2d vector)
 Multiplies a scalar by this vector.
template<units::IsQuantity S>
requires LinearKinematicQuantity<units::Multiplied<Q, S>>
constexpr auto operator* (S scalar, LinearVector2d vector)

Constructor & Destructor Documentation

◆ LinearVector2d() [1/3]

LinearVector2d< Q >::LinearVector2d ( Q x,
Q y )
inlineconstexpr

Constructs a vector with the given x and y values.

Parameters
xThe x component of the vector.
yThe y component of the vector.

◆ LinearVector2d() [2/3]

LinearVector2d< Q >::LinearVector2d ( Q r,
Rotation2d theta )
inlineconstexpr

Constructs a vector given polar coordinates of the form (r, theta).

Parameters
rThe magnitude of the vector.
thetaThe angle of the vector.

◆ LinearVector2d() [3/3]

LinearVector2d< Q >::LinearVector2d ( Eigen::Vector2d vector,
Q unit )
inlineconstexpr

Constructs a vector with the values from the given Eigen::Vector.

Parameters
vectorThe vector whose values will be used.
unitThe unit to use when assigning x and y (e.g. units::inches)

Member Function Documentation

◆ as_vector()

Eigen::Vector2d LinearVector2d< Q >::as_vector ( Q unit) const
inlineconstexpr

Returns the vector as an Eigen::Vector2d.

Parameters
unitThe unit to get the x and y components as (e.g. units::inches)
Returns
Eigen::Vector2d with the same values as the vector.

◆ dot()

units::Multiplied< Q, Q > LinearVector2d< Q >::dot ( LinearVector2d< Q > other) const
inlineconstexpr

Returns the dot product of two vectors. The result has the product of the two component units.

[scalar] = [x][otherx] + [y][othery]

Parameters
otherthe other vector to dot with.
Returns
The dot product of this and other.

◆ interpolate()

LinearVector2d LinearVector2d< Q >::interpolate ( LinearVector2d< Q > end,
double fraction ) const
inlineconstexpr

Interpolates along a straight line to another vector. Fractions outside [0, 1] return the nearest endpoint.

Parameters
endendpoint
fractionpercent of the way between the points
Returns
interpolated vector

◆ inverse()

LinearVector2d LinearVector2d< Q >::inverse ( ) const
inlineconstexpr

Returns the inverse of this vector, or mirrors it across the origin. [x] = [-x] [y] = [-y]

Returns
The inverse of this vector.

◆ is_near()

bool LinearVector2d< Q >::is_near ( LinearVector2d< Q > other,
Q tolerance = Q(1e-6) ) const
inlineconstexpr

Checks the distance between vectors against a tolerance. Defaults to 1um for translations, 1um/s for velocities, etc.

◆ mean()

constexpr LinearVector2d LinearVector2d< Q >::mean ( const std::vector< LinearVector2d< Q > > & list)
inlinestaticconstexpr

Calculates the mean of a list of vectors.

Parameters
liststd::vector containing a list of vectors.
Returns
the single vector mean of the list of vectors.

◆ normalize()

LinearVector2d LinearVector2d< Q >::normalize ( Q magnitude = Q(1.0)) const
inlineconstexpr

Returns a vector of the same angle, but specific magnitude (default 1 base unit)

Parameters
magnitudemagnitude of the vector (default 1 base unit).
Returns
The normalized vector.

◆ operator*() [1/2]

units::Multiplied< Q, Q > LinearVector2d< Q >::operator* ( LinearVector2d< Q > other) const
inlineconstexpr

Returns the dot product of two vectors. The result has the product of the two component units.

[scalar] = [x][otherx] + [y][othery]

Parameters
otherthe other vector to dot with.
Returns
The dot product of this and other.

◆ operator*() [2/2]

LinearVector2d< units::Multiplied< Q, S > > LinearVector2d< Q >::operator* ( S scalar) const
inlineconstexpr

Multiplies this vector by a scalar with a unit of time. e.g. Velocity2d * Time = Translation2d

◆ rotate_around()

LinearVector2d LinearVector2d< Q >::rotate_around ( LinearVector2d< Q > other,
Rotation2d rotation ) const
inlineconstexpr

Applies a rotation to this vector around another given vector.

[x] = [cos, -sin][x - otherx] + [otherx] [y] = [sin, cos][y - othery] + [othery]

Parameters
otherthe center of rotation.
rotationthe angle amount the vector will be rotated.
Returns
The vector that has been rotated.

◆ rotate_by()

LinearVector2d LinearVector2d< Q >::rotate_by ( Rotation2d rotation) const
inlineconstexpr

Rotates this vector around the origin by the provided rotation.

Equivalent to multiplying a vector by a rotation matrix: x = [cos, -sin][x] y = [sin, cos][y]

Parameters
rotationthe angle amount to rotate.
Returns
The new vector that has been rotated around the origin.

◆ operator*

auto operator* ( S scalar,
LinearVector2d< Q > vector )
friend

Multiplies a scalar with a unit of time by this vector. e.g. Time * Velocity2d = Translation2d


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