ASL
Loading...
Searching...
No Matches
Vec2_< T > Class Template Reference

Detailed Description

template<class T>
class asl::Vec2_< T >

A Vec2 represents a vector in 2D space.

This class allows operating with vectors as with primitive types via operators.

Vec2 a (10, 10);
Vec2 b (-5, 1.5);
Vec2 c = -a.rotate(PI/4) + 2.0f * (b - a).normalized();
Vec2_ rotate(T a) const
Returns this vector rotated an angle a.
Definition Vec2.h:54
Vec2_ normalized() const
Returns this vector normalized.
Definition Vec2.h:56

The angle between two vectors can be computed with:

T angle = acos(a.normalized() * b.normalized());
T angle() const
Returns the angle between this vector and the +X axis in the [-PI, PI] range.
Definition Vec2.h:58

#include <asl/Vec2.h>

Public Member Functions

 Vec2_ (T x, T y)
 Constructs a vector with the given (x, y) coordinates.
Vec2_ perpend () const
 Returns this vector rotated 90 degrees counterclockwise.
Vec2_ rotate (T a) const
 Returns this vector rotated an angle a.
Vec2_ normalized () const
 Returns this vector normalized.
T angle () const
 Returns the angle between this vector and the +X axis in the [-PI, PI] range.
T angle (const Vec2_ &b) const
 Returns the angle between this vector and b.
T length () const
 Returns the length of this vector.
T length2 () const
 Returns the length of this vector squared.
T norm1 () const
 Returns the 1-norm of this vector.
T normInf () const
 Returns the infinity-norm of this vector.
Vec2_ abs () const
 Returns this vector with absolute coordinates.
Vec2_ operator+ (const Vec2_ &b) const
 Returns this vector plus b.
Vec2_ operator- (const Vec2_ &b) const
 Returns this vector minus b.
T operator* (const Vec2_ &b) const
 Returns the dot product of this vector and b.
Vec2_ operator* (T r) const
 Returns this vector multiplied by scalar r.
T operator^ (const Vec2_ &b) const
 Returns the z-component of the cross product of this vector and b.
Vec2_ operator/ (T r) const
 Returns this vector divided by scalar r.
Vec2_ operator% (const Vec2_ &b) const
 Returns a vector that is a component-wise product of this vector and b.
bool operator== (const Vec2_ &b) const
 Compares this vector and b (warning: test equality of floats with care).
bool operator!= (const Vec2_ &b) const
 Compares this vector and b (warning: test equality of floats with care).
void operator+= (const Vec2_ &b)
 Adds b to this vector.
void operator-= (const Vec2_ &b)
 Subtracts b from this vector.
void operator*= (T r)
 Multiplies this vector by scalar r.
void operator/= (T r)
 Divides this vector by scalar r.
void operator%= (const Vec2_ &b)
 Multiplies this vector by another, component-wise.
Vec2_ operator- () const
 Returns this vector negated.

Static Public Member Functions

static Vec2_ polar (T r, T a)
 Returns a vector constructed from polar coordinates.

Friends

Vec2_ operator* (T r, const Vec2_ &b)
 Returns vector b multiplied by scalar r.

The documentation for this class was generated from the following file:
  • Vec2.h