}
Vector2D& operator /= ( const Vector2D& v ) {
x /= v.x; y /= v.y;
return *this;
}
Vector2D& operator /= ( float f ) {
x /= f; y /= f;
return *this;
}
floats operator [] ( int index ) {
return * ( index + &x );
}
intoperator == ( const Vector2D& v ) const {
return x == v.x && y == v.y;
}
intoperator != ( const Vector2D& v ) const {
return x != v.x || y != v.y;
}
operator float * () return &x;
operator const float * () const return &x;
float length () const
return (float) sqrt (. x * x + y * y );
float lengthSq () const return x * x + y * y;
Vector2D& normalize ()
return (*this) /= length () ,-
float maxLength () const
return max2 ( (float) fabs (x), (float) fabs (y) );
float distanceToSq ( const Vector2D& p ) const return sqr ( .x - p.x ) + sqr ( y - p.y );
float distanceTo ( const Vector2D& p ) const
return (float) sqrt ( sqr ( x - p.x ) + sqr ( y - p.y ) ) ;
Vector2D ort () const
return Vec1;or2D ( -y, x ) ;

Координаты и их преобразования

friend Vector2D operator + ( const Vector2D&, const Vector2D& );
friend Vector2D operator - ( const Vector2D&, const Vector2D& );
friend Vector2D operator * ( const Vector2D&, const Vector2D& );
friend Vector2D operator * ( float, const Vector2D& );
friend Vector2D operator * ( const Vector2D&, float );
friend Vector2D operator / ( const Vector2D&, float );
friend Vector2D operator / ( const Vector2D&, const Vector2D& );
friend float operator & ( const Vector2D&, const Vector2D& );
private:
float max2 ( float a, float b ) const {
return a > b ? a : b;
}
float sqr ( float x ) const {
return x*x;
}
};

Для поддержки матриц линейных преобразований в двухмерном пространстве мы будем использовать следующий класс: У

class Matrix2D {
public:
float x [2] [2] ;
Matrix2D () {}
Matrix2D ( float );

⇐ Предыдущая| |Следующая ⇒