};
inline Vector2D operator * ( const Matrix2D& m,
const Vector2D& v)
{
return Vector2D ( m.a [0][0]*v.x + m.a [0][1]*v.y,
m.a [1][0]*v.x + m.a [1][1]Vy);
}
#endif
2! // File matrix2d.cpp
#include ,,matrix2d.h"
Matrix2D :: Matrix2D (float v ) {
a[0][1] = a[1][0] = 0.0; a[0][0] = a[1][1] = v;
}
Matrix2D :: Matrix2D ( const Matrix2D& m ) {
a [0][0] = m.a [0][0]; a[0][1] = m.a [0][1]; a[1][0] = m.a[1JI0]; a[1][1] = m.a [1][1J;
}
Matrix2D& Matrix2D :: operator = ( const Matrix2D& m ) {
a [0][0] = m.a [0][0]; a[0][1] = m.a [0][1]; a[1][0] = m.a [1][0]; a[1][1] = m.a [1][1];
return *this;
}
Matrix2D& Matrix2D :: operator = (float x ) {
a[0][1] = a[1][0] = 0.0; a[0][0] = a[1][1] = x;
7. Преобразования на плоское
return *this;
}
Matrix2D& Matrix2D :: operator += ( const Matrix2D& m ) {
a [0][0] += m.a [0][0]; a [0][1] += m.a [0][1]; a[1][0]+=m.a[1][0]; a[1][1]+= m.a [1][1];
return *this;
}
Matrix2D& Matrix2D :: operator -= (const Matrix2D& m ) {
a [0][0] -= m.a [0][0]; a [0][1] -= m.a [0][1]; a[1][0] -=m.a [1][0]; a[1][1]-=m.a [1][1];
return *this;
}
Matrix2D& Matrix2D :: operator *= ( const Matrix2D& m ) {
Matrix2D c (*this );
a [0][0] =$.a [0][0]*m.a [0][0] + c.a [0][1]*m.a [1][0]; a [0][1] = c.a [0][0]*m.a [0][1] + c.a [0][1]*m.a a [1][0] = c.a [1][0]*m.a [0][0] + c.a [1][1]*m.a [1][0]: a [1][1] = c.a [1][0]*m.a [0][1] + c.a [1][1]*m.a [1][1]:
return *this;
}
Matrix2D& Matrix2D :: operator *= (float f) {
a [0][0] *= f; a[0][1]*=f; a[1][0] *=f; a[1][1]*=f; return *this;
}
Matrix2D& Matrix2D :: operator /= (float f) {
a [0][0] /= f; a [0][1] /= f; a(1][0]/=f; a[1][1]/=f;
return 'this;
};
void Matrix2D :: invert () {
float det = a [0][0]*a [1][1] - a [0][1]*a [1][0]; Matrix2D m;
Компьютерная графика. Полигональные модели
m.a[0][0]= a[1][1]/det; m.a [0][1] = -a [0][1]/det; m.a [1][0] = -a [1][0]/det; m.a[1][1]= a[0][0]/det;
*this = m;
}
void Matrix2D :: transpose () {
Matrix2D m;
m.a [0][0] = a [0][0]; m.a[0][1] = a[1][0]; m.a I1][0] = a[0][1]; m.a [1][1] = a[1][1];
*this = m;