SimpleVector SimpleVector:: cross(const SimpleVector& rhs) const { double newX = y * rhs.z - z * rhs.y; double newY = z * rhs.x - x * rhs.z; double newZ = x * rhs.y - y * rhs.x; return SimpleVector(newX, newY, newZ); }
void testSimpleMatrixMultiplyRight() { SimpleVector v = SimpleVector(3); SimpleMatrix m = createSimpleMatrix(2, 3); v.setElement(0, 3); v.setElement(1, 2); v.setElement(2, 1); // [0,1,2] * [3] = [4] // [0,1,2] [2] [4] // [1] Vector* res = m.multiplyRight(v); BOOST_CHECK( res->size() == 2 ); BOOST_CHECK( res->getElement(0) == 4 ); BOOST_CHECK( res->getElement(1) == 4 ); delete res; }
void testSimpleMatrixMultiplyLeft() { SimpleVector v = SimpleVector(3); SimpleMatrix m = createSimpleMatrix(3, 2); v.setElement(0, 3); v.setElement(1, 2); v.setElement(2, 1); // [3,2,1] * [0,1] = [0,6] // [0,1] // [0,1] Vector* res = m.multiplyLeft(v); BOOST_CHECK( res->size() == 2 ); BOOST_CHECK( res->getElement(0) == 0 ); BOOST_CHECK( res->getElement(1) == 6 ); delete res; }
SimpleVector SimpleVector:: operator*(const double rhs) const { return SimpleVector(x * rhs, y * rhs, z * rhs); }
SimpleVector SimpleVector:: operator/(const double rhs) const { return SimpleVector(x / rhs, y / rhs, z / rhs); }
SimpleVector SimpleVector:: operator+(const SimpleVector& rhs) const { return SimpleVector(x + rhs.x, y + rhs.y, z + rhs.z); }
SimpleVector SimpleVector:: operator-(const SimpleVector& rhs) const { return SimpleVector(x - rhs.x, y - rhs.y, z - rhs.z); }