1 #ifndef CMU462_VECTOR2D_H
2 #define CMU462_VECTOR2D_H
30 Vector2D(
double x,
double y ) : x( x ), y( y ) { }
39 inline Vector2D operator-(
void )
const {
58 inline Vector2D operator*(
double r )
const {
65 inline Vector2D operator/(
double r )
const {
72 inline void operator+=(
const Vector2D& v ) {
78 inline void operator-=(
const Vector2D& v ) {
84 inline void operator*=(
double r ) {
90 inline void operator/=(
double r ) {
98 inline double norm(
void )
const {
99 return sqrt( x*x + y*y );
113 return *
this / this->
norm();
120 inline Vector2D operator*(
double r,
const Vector2D& v ) {
125 inline double dot(
const Vector2D& v1,
const Vector2D& v2 ) {
126 return v1.x*v2.x + v1.y*v2.y;
130 inline double cross(
const Vector2D& v1,
const Vector2D& v2 ) {
131 return v1.x*v2.y - v1.y*v2.x;
135 std::ostream& operator<<( std::ostream& os,
const Vector2D& v );
139 #endif // CMU462_VECTOR2D_H
Vector2D()
Constructor.
Definition: vector2D.h:24
double norm2(void) const
Returns norm squared.
Definition: vector2D.h:105
double norm(void) const
Returns norm.
Definition: vector2D.h:98
Vector2D(double x, double y)
Constructor.
Definition: vector2D.h:30
Defines 2D vectors.
Definition: vector2D.h:14
Vector2D(const Vector2D &v)
Constructor.
Definition: vector2D.h:36
Vector2D unit(void) const
Returns unit vector parallel to this one.
Definition: vector2D.h:112