RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
rz::Point Class Reference

Immutable 2D point / vector with unit-safe Cartesian coordinates. More...

#include <Point.hpp>

Public Member Functions

constexpr Point () noexcept=default
 Constructs the origin (0 m, 0 m).
 Point (Length x, Length y) noexcept
 Constructs a point from Cartesian components.
 Point (Length magnitude, const Rotation &rotation) noexcept
 Constructs a point from polar form.
Length X () const noexcept
 X coordinate.
Length Y () const noexcept
 Y coordinate.
Point operator+ (const Point &rhs) const noexcept
 Vector addition.
Point operator- (const Point &rhs) const noexcept
 Vector subtraction.
Point operator- () const noexcept
 Unary negation.
Point operator* (double scalar) const noexcept
 Scales both components by a unitless scalar.
Point operator/ (double scalar) const noexcept
 Divides both components by a unitless scalar.
Angle theta () const noexcept
 Direction (heading) of the vector in radians.
Length mag () const noexcept
 Magnitude (Euclidean norm).
Length distTo (const Point &rhs) const noexcept
 Euclidean distance to another point.
Angle angleTo (const Point &rhs) const noexcept
 Signed smallest-angle direction from this point’s heading to another’s.
Area dot (const Point &rhs) const noexcept
 Dot (inner) product.
Area wedge (const Point &rhs) const noexcept
 2D wedge (scalar cross) product.
Point project (const Point &rhs) const noexcept
 Projection of this vector onto another.
Point rotateBy (const Rotation &rhs) const noexcept
 Rotates this point by a Rotation about the origin.
bool isApprox (const Point &rhs) const noexcept
 Approximate equality in Euclidean metric.

Detailed Description

Immutable 2D point / vector with unit-safe Cartesian coordinates.

Point stores an (x, y) position in meters and provides common vector operations (addition, subtraction, scaling, dot / wedge products, projection), geometric queries (magnitude, direction, distance, angles), and rotation by a Rotation.

All operations preserve units via au quantities. Overloads that take double scalars are unitless multipliers/divisors applied to the coordinates.

Constructor & Destructor Documentation

◆ Point() [1/3]

rz::Point::Point ( )
constexprdefaultnoexcept

Constructs the origin (0 m, 0 m).

◆ Point() [2/3]

rz::Point::Point ( Length x,
Length y )
noexcept

Constructs a point from Cartesian components.

Parameters
xX component (length units, e.g., meters).
yY component (length units, e.g., meters).

◆ Point() [3/3]

rz::Point::Point ( Length magnitude,
const Rotation & rotation )
noexcept

Constructs a point from polar form.

Forms the vector with magnitude magnitude and direction rotation: x = magnitude * cos(rotation), y = magnitude * sin(rotation).

Parameters
magnitudeVector length (meters).
rotationHeading as a Rotation.

Member Function Documentation

◆ angleTo()

Angle rz::Point::angleTo ( const Point & rhs) const
noexcept

Signed smallest-angle direction from this point’s heading to another’s.

Computes wrap_to_(-π,π](rhs.theta() - theta()).

Parameters
rhsOther point.
Returns
Angle difference in radians.

◆ distTo()

Length rz::Point::distTo ( const Point & rhs) const
noexcept

Euclidean distance to another point.

Parameters
rhsOther point.
Returns
Distance in meters.

◆ dot()

Area rz::Point::dot ( const Point & rhs) const
noexcept

Dot (inner) product.

Parameters
rhsOther vector.
Returns
x*rhs.x + y*rhs.y (units: m²).

◆ isApprox()

bool rz::Point::isApprox ( const Point & rhs) const
noexcept

Approximate equality in Euclidean metric.

Parameters
rhsOther point.
Returns
true if distTo(rhs) ≤ 1e-9 m, otherwise false.

◆ mag()

Length rz::Point::mag ( ) const
noexcept

Magnitude (Euclidean norm).

Returns
hypot(x, y) in meters.

◆ operator*()

Point rz::Point::operator* ( double scalar) const
noexcept

Scales both components by a unitless scalar.

Parameters
scalarMultiplier.
Returns
(x * scalar, y * scalar).

◆ operator+()

Point rz::Point::operator+ ( const Point & rhs) const
noexcept

Vector addition.

Parameters
rhsPoint to add.
Returns
(x + rhs.x, y + rhs.y).

◆ operator-() [1/2]

Point rz::Point::operator- ( ) const
noexcept

Unary negation.

Returns
(-x, -y).

◆ operator-() [2/2]

Point rz::Point::operator- ( const Point & rhs) const
noexcept

Vector subtraction.

Parameters
rhsPoint to subtract.
Returns
(x - rhs.x, y - rhs.y).

◆ operator/()

Point rz::Point::operator/ ( double scalar) const
noexcept

Divides both components by a unitless scalar.

Equivalent to multiplying by 1.0 / scalar.

Parameters
scalarDivisor.
Returns
(x / scalar, y / scalar).

◆ project()

Point rz::Point::project ( const Point & rhs) const
noexcept

Projection of this vector onto another.

Returns the component of *this along rhs: proj = rhs * (dot(rhs) / rhs.dot(rhs)).

@requires rhs.mag() > 0

Parameters
rhsDirection to project onto.
Returns
Projection vector in meters.

◆ rotateBy()

Point rz::Point::rotateBy ( const Rotation & rhs) const
noexcept

Rotates this point by a Rotation about the origin.

Applies the standard 2×2 rotation matrix:

Parameters
rhsRotation to apply.
Returns
Rotated point.

◆ theta()

Angle rz::Point::theta ( ) const
noexcept

Direction (heading) of the vector in radians.

Returns atan2(y, x). If the point is the origin, returns 0 rad.

Returns
Angle in radians.

◆ wedge()

Area rz::Point::wedge ( const Point & rhs) const
noexcept

2D wedge (scalar cross) product.

Equivalent to the signed z-component of the 3D cross product of (x, y, 0) × (rhs.x, rhs.y, 0): x*rhs.y - y*rhs.x.

Positive if rhs is counter-clockwise from this vector.

Parameters
rhsOther vector.
Returns
Signed area (units: m²).

◆ X()

Length rz::Point::X ( ) const
noexcept

X coordinate.

Returns
X component (meters).

◆ Y()

Length rz::Point::Y ( ) const
noexcept

Y coordinate.

Returns
Y component (meters).

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