Scanline::Scanline(const vector3& origin, const vector3& direction, const vector3& lateral_dir, float timestamp) : origin(origin), direction(direction), lateral_dir(lateral_dir), timestamp(timestamp) { elevational_dir = lateral_dir.cross(direction); // TODO: Should all vectors be normalized here? if (!is_orthogonal()) throw std::runtime_error("Invalid Scanline: Not orthogonal unit vectors"); if (!is_normalized()) throw std::runtime_error("Invalid Scanline: Not unit length vectors"); }
bool mat44::invert() { if (is_orthogonal()) { transpose(); return true; } float det = determinant(); if (!fequal(det, 0.0f)) { det = 1.0f / det; mat44 copy(*this); //to-do det_impl is calculated above in determinant(). //try to gcd m[0][0] = +determinant_impl(copy._11, copy._12, copy._13, copy._21, copy._22, copy._23, copy._31, copy._32, copy._33) * det; m[1][0] = -determinant_impl(copy._10, copy._12, copy._13, copy._20, copy._22, copy._23, copy._30, copy._32, copy._33) * det; m[2][0] = +determinant_impl(copy._10, copy._11, copy._13, copy._20, copy._21, copy._23, copy._30, copy._31, copy._33) * det; m[3][0] = -determinant_impl(copy._10, copy._11, copy._12, copy._20, copy._21, copy._22, copy._30, copy._31, copy._32) * det; m[0][1] = -determinant_impl(copy._01, copy._02, copy._03, copy._21, copy._22, copy._23, copy._31, copy._32, copy._33) * det; m[1][1] = +determinant_impl(copy._00, copy._02, copy._03, copy._20, copy._22, copy._23, copy._30, copy._32, copy._33) * det; m[2][1] = -determinant_impl(copy._00, copy._01, copy._03, copy._20, copy._21, copy._23, copy._30, copy._31, copy._33) * det; m[3][1] = +determinant_impl(copy._00, copy._01, copy._02, copy._20, copy._21, copy._22, copy._30, copy._31, copy._32) * det; m[0][2] = +determinant_impl(copy._01, copy._02, copy._03, copy._11, copy._12, copy._13, copy._31, copy._32, copy._33) * det; m[1][2] = -determinant_impl(copy._00, copy._02, copy._03, copy._10, copy._12, copy._13, copy._30, copy._32, copy._33) * det; m[2][2] = +determinant_impl(copy._00, copy._01, copy._03, copy._10, copy._11, copy._13, copy._30, copy._31, copy._33) * det; m[3][2] = -determinant_impl(copy._00, copy._01, copy._02, copy._10, copy._11, copy._12, copy._30, copy._31, copy._32) * det; m[0][3] = -determinant_impl(copy._01, copy._02, copy._03, copy._11, copy._12, copy._13, copy._21, copy._22, copy._23) * det; m[1][3] = +determinant_impl(copy._00, copy._02, copy._03, copy._10, copy._12, copy._13, copy._20, copy._22, copy._23) * det; m[2][3] = -determinant_impl(copy._00, copy._01, copy._03, copy._10, copy._11, copy._13, copy._20, copy._21, copy._23) * det; m[3][3] = +determinant_impl(copy._00, copy._01, copy._02, copy._10, copy._11, copy._12, copy._20, copy._21, copy._22) * det; return true; } return false; }
bool mat22::invert() { if (is_orthogonal()) { transpose(); return true; } float det = determinant(); if (!fequal(det, 0.0f)) { //calc adjoint matrix swap(this->m[0][0], this->m[1][1]); this->m[0][1] = -this->m[0][1]; this->m[1][0] = -this->m[1][0]; *this *= 1.0f / det; return true; } return false; }
bool Basis::is_rotation() const { return Math::isequal_approx(determinant(), 1) && is_orthogonal(); }
bool Basis::is_rotation() const { return Math::is_equal_approx(determinant(), 1, UNIT_EPSILON) && is_orthogonal(); }
bool is_orthogonal( const matrix<T,N,A>& m ) { return is_orthogonal( m, [](const T v){ return v == T(0); } ); }
bool Scanline::is_valid() const { return (is_orthogonal() && is_normalized()); }