A 2D vector with common geometric operations. More...
#include <yoda.hpp>
Public Member Functions | |
| Vec2 (T x=T{}, T y=T{}) | |
| Construct a new Vec2. | |
| T | dot (const Vec2 &other) const |
| Compute the dot product of two vectors. | |
| double | magnitude () const |
| Compute the Euclidean magnitude. | |
| Vec2< double > | normalized () const |
| Return a normalized (unit-length) copy of this vector. | |
| Vec2 | operator* (T scalar) const |
| Scalar multiplication. | |
| Vec2 | operator+ (const Vec2 &rhs) const |
| Vector addition. | |
Public Attributes | |
| T | x |
| X component. | |
| T | y |
| Y component. | |
A 2D vector with common geometric operations.
Demonstrates template classes, operator overloading, and mathematical documentation with MathJax.
The magnitude of a vector \((x, y)\) is computed as:
\[ \| \mathbf{v} \| = \sqrt{x^2 + y^2} \]
| T | Numeric type (must support arithmetic operators). |
|
inline |
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscard |
Return a normalized (unit-length) copy of this vector.
magnitude() == 0.
|
inline |
|
inline |
| T yoda::Vec2< T >::x |
X component.
Definition at line 84 of file yoda.hpp.
Referenced by yoda::Vec2< double >::dot(), and yoda::Vec2< double >::operator+().
| T yoda::Vec2< T >::y |
Y component.
Definition at line 85 of file yoda.hpp.
Referenced by yoda::Vec2< double >::dot(), and yoda::Vec2< double >::operator+().