1 #ifndef CMU462_VECTOR2D_H
2 #define CMU462_VECTOR2D_H
28 Vector2D(
double x,
double y ) : x( x ), y( y ) { }
37 inline Vector2D operator-(
void )
const {
56 inline Vector2D operator*(
double r )
const {
63 inline Vector2D operator/(
double r )
const {
70 inline void operator+=(
const Vector2D& v ) {
76 inline void operator-=(
const Vector2D& v ) {
82 inline void operator*=(
double r ) {
88 inline void operator/=(
double r ) {
96 inline double norm(
void )
const {
97 return sqrt( x*x + y*y );
111 return *
this / this->
norm();
118 inline Vector2D operator*(
double r,
const Vector2D& v ) {
123 inline double dot(
const Vector2D& v1,
const Vector2D& v2 ) {
124 return v1.x*v2.x + v1.y*v2.y;
128 inline double cross(
const Vector2D& v1,
const Vector2D& v2 ) {
129 return v1.x*v2.y - v1.y*v2.x;
133 std::ostream& operator<<( std::ostream& os,
const Vector2D& v );
137 #endif // CMU462_VECTOR2D_H
Vector2D()
Constructor.
Definition: vector2D.h:22
double norm2(void) const
Returns norm squared.
Definition: vector2D.h:103
double norm(void) const
Returns norm.
Definition: vector2D.h:96
Vector2D(double x, double y)
Constructor.
Definition: vector2D.h:28
Defines 2D vectors.
Definition: vector2D.h:12
Vector2D(const Vector2D &v)
Constructor.
Definition: vector2D.h:34
Vector2D unit(void) const
Returns unit vector parallel to this one.
Definition: vector2D.h:110