VectorR3 Matrix3x3::Solve(const VectorR3& u) const // Returns solution { // based on Cramer's rule double sd11 = m22 * m33 - m23 * m32; double sd21 = m32 * m13 - m12 * m33; double sd31 = m12 * m23 - m22 * m13; double sd12 = m31 * m23 - m21 * m33; double sd22 = m11 * m33 - m31 * m13; double sd32 = m21 * m13 - m11 * m23; double sd13 = m21 * m32 - m31 * m22; double sd23 = m31 * m12 - m11 * m32; double sd33 = m11 * m22 - m21 * m12; double detInv = 1.0 / (m11 * sd11 + m12 * sd12 + m13 * sd13); double rx = (u.x * sd11 + u.y * sd21 + u.z * sd31) * detInv; double ry = (u.x * sd12 + u.y * sd22 + u.z * sd32) * detInv; double rz = (u.x * sd13 + u.y * sd23 + u.z * sd33) * detInv; return (VectorR3(rx, ry, rz)); }
VectorR3 operator *(VectorR3 u, double c) { return VectorR3(u.X * c, u.Y * c, u.Z * c); }
VectorR3 operator +(VectorR3 u, VectorR3 v) { return VectorR3(u.X + v.X, u.Y + v.Y, u.Z + v.Z); }
VectorR3 operator -(VectorR3 u, VectorR3 v) { return VectorR3(u.X - v.X, u.Y - v.Y, u.Z - v.Z); }
VectorR3 VectorR3::CrossProduct(VectorR3 rhs) { return VectorR3((Y * rhs.Z) - (Z * rhs.Y), -((X * rhs.Z) - (Z * rhs.X)), (X * rhs.Y) - (Y * rhs.X)); }