123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #pragma once
- #include <Mathematics/Matrix.h>
- #include <Mathematics/SingularValueDecomposition.h>
- namespace WwiseGTE
- {
- template <int N, typename Real>
- class Hyperplane
- {
- public:
-
-
- Hyperplane()
- :
- constant((Real)0)
- {
- normal.MakeUnit(N - 1);
- }
-
- Hyperplane(Vector<N, Real> const& inNormal, Real inConstant)
- :
- normal(inNormal),
- constant(inConstant)
- {
- }
-
- Hyperplane(Vector<N, Real> const& inNormal, Vector<N, Real> const& p)
- :
- normal(inNormal),
- constant(Dot(inNormal, p))
- {
- }
-
-
-
- Hyperplane(std::array<Vector<N, Real>, N> const& p)
- {
- Matrix<N, N - 1, Real> edge;
- for (int i = 0; i < N - 1; ++i)
- {
- edge.SetCol(i, p[i + 1] - p[0]);
- }
-
-
- SingularValueDecomposition<Real> svd(N, N - 1, 32);
- svd.Solve(&edge[0], -1);
- svd.GetUColumn(N - 1, &normal[0]);
- constant = Dot(normal, p[0]);
- }
-
- Vector<N, Real> normal;
- Real constant;
- public:
-
- bool operator==(Hyperplane const& hyperplane) const
- {
- return normal == hyperplane.normal && constant == hyperplane.constant;
- }
- bool operator!=(Hyperplane const& hyperplane) const
- {
- return !operator==(hyperplane);
- }
- bool operator< (Hyperplane const& hyperplane) const
- {
- if (normal < hyperplane.normal)
- {
- return true;
- }
- if (normal > hyperplane.normal)
- {
- return false;
- }
- return constant < hyperplane.constant;
- }
- bool operator<=(Hyperplane const& hyperplane) const
- {
- return !hyperplane.operator<(*this);
- }
- bool operator> (Hyperplane const& hyperplane) const
- {
- return hyperplane.operator<(*this);
- }
- bool operator>=(Hyperplane const& hyperplane) const
- {
- return !operator<(hyperplane);
- }
- };
-
- template <typename Real>
- using Plane3 = Hyperplane<3, Real>;
- }
|