6#include <Common/assertion.h>
18 PH_ASSERT_IN_RANGE(unitYAxis.
lengthSquared(),
static_cast<T
>(0.9),
static_cast<T
>(1.1));
25 unitXAxis.
set({-unitYAxis.
z(), T(0), unitYAxis.
x()});
26 unitXAxis.
mulLocal(T(1) / std::sqrt(unitXAxis.
x() * unitXAxis.
x() + unitXAxis.
z() * unitXAxis.
z()));
30 unitXAxis.
set({unitYAxis.
y(), -unitYAxis.
x(), T(0)});
31 unitXAxis.
mulLocal(T(1) / std::sqrt(unitXAxis.
x() * unitXAxis.
x() + unitXAxis.
y() * unitXAxis.
y()));
36 PH_ASSERT_IN_RANGE(unitXAxis.
lengthSquared(),
static_cast<T
>(0.9),
static_cast<T
>(1.1));
37 PH_ASSERT_IN_RANGE(unitZAxis.
lengthSquared(),
static_cast<T
>(0.9),
static_cast<T
>(1.1));
72 PH_ASSERT_IN_RANGE(xAxis.
lengthSquared(),
static_cast<T
>(0.9),
static_cast<T
>(1.1));
73 PH_ASSERT_IN_RANGE(yAxis.
lengthSquared(),
static_cast<T
>(0.9),
static_cast<T
>(1.1));
74 PH_ASSERT_IN_RANGE(zAxis.
lengthSquared(),
static_cast<T
>(0.9),
static_cast<T
>(1.1));
81 m_yAxis.dot(worldVec),
82 m_zAxis.dot(worldVec));
88 return m_xAxis.
mul(localVec.
x()).add(
89 m_yAxis.mul(localVec.
y())).add(
90 m_zAxis.mul(localVec.
z()));
96 const T zProjection = unitVec.
dot(m_zAxis);
97 const T rProjection = sinTheta(unitVec);
98 return math::safe_clamp(zProjection / rProjection,
static_cast<T
>(-1),
static_cast<T
>(1));
104 const T xProjection = unitVec.
dot(m_xAxis);
105 const T rProjection = sinTheta(unitVec);
106 return math::safe_clamp(xProjection / rProjection,
static_cast<T
>(-1),
static_cast<T
>(1));
112 const T zProjection = unitVec.
dot(m_zAxis);
113 const T xProjection = unitVec.
dot(m_xAxis);
114 const T tanP = xProjection / zProjection;
115 return std::isfinite(tanP) ? tanP :
static_cast<T
>(0);
133 const T cos2P = cos2Phi(unitVec);
134 const T sin2P = 1 - cos2P;
135 const T tan2P = sin2P / cos2P;
136 PH_ASSERT(tan2P >=
static_cast<T
>(0) || !std::isfinite(tan2P));
137 return std::isfinite(tan2P) ? tan2P :
static_cast<T
>(0);
143 return math::clamp(m_yAxis.dot(unitVec),
static_cast<T
>(-1),
static_cast<T
>(1));
149 return std::sqrt(sin2Theta(unitVec));
155 const T cosT = cosTheta(unitVec);
156 const T tanT = sinTheta(unitVec) / cosT;
157 return std::isfinite(tanT) ? tanT :
static_cast<T
>(0);
163 return std::abs(cosTheta(unitVec));
169 return std::abs(sinTheta(unitVec));
181 return 1 - cos2Theta(unitVec);
187 const T cos2T = cos2Theta(unitVec);
188 const T sin2T = 1 - cos2T;
189 const T tan2T = sin2T / cos2T;
190 PH_ASSERT(tan2T >=
static_cast<T
>(0) || !std::isfinite(tan2T));
191 return std::isfinite(tan2T) ? tan2T :
static_cast<T
>(0);
207 m_xAxis.normalizeLocal();
215 m_yAxis.normalizeLocal();
223 m_zAxis.normalizeLocal();
Represents a set of orthonormal basis vectors in 3-D space.
Definition TOrthonormalBasis3.h:13
T absCosTheta(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:161
TVector3< T > worldToLocal(const TVector3< T > &worldVec) const
Definition TOrthonormalBasis3.ipp:78
TVector3< T > getYAxis() const
Definition TOrthonormalBasis3.ipp:272
TVector3< T > getZAxis() const
Definition TOrthonormalBasis3.ipp:278
TOrthonormalBasis3 & set(const TVector3< T > &xAxis, const TVector3< T > &yAxis, const TVector3< T > &zAxis)
Definition TOrthonormalBasis3.ipp:253
static TOrthonormalBasis3 makeFromUnitY(const TVector3< T > &unitYAxis)
Definition TOrthonormalBasis3.ipp:16
TOrthonormalBasis3 & renormalize()
Definition TOrthonormalBasis3.ipp:195
TVector3< T > getXAxis() const
Definition TOrthonormalBasis3.ipp:266
T tanTheta(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:153
T tanPhi(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:110
TOrthonormalBasis3 & setXAxis(const TVector3< T > &axis)
Definition TOrthonormalBasis3.ipp:229
T sin2Theta(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:179
T tan2Theta(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:185
T sinTheta(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:147
T absSinTheta(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:167
T sinPhi(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:102
TOrthonormalBasis3 & setZAxis(const TVector3< T > &axis)
Definition TOrthonormalBasis3.ipp:245
TOrthonormalBasis3 & renormalizeZAxis()
Definition TOrthonormalBasis3.ipp:221
TOrthonormalBasis3 & renormalizeXAxis()
Definition TOrthonormalBasis3.ipp:205
T cosTheta(const TVector3< T > &unitVec) const
Calculates trigonometries for the angle in spherical coordinates.
Definition TOrthonormalBasis3.ipp:141
T sin2Phi(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:125
T cos2Phi(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:119
TOrthonormalBasis3 & renormalizeYAxis()
Definition TOrthonormalBasis3.ipp:213
T tan2Phi(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:131
T cos2Theta(const TVector3< T > &unitVec) const
Definition TOrthonormalBasis3.ipp:173
T cosPhi(const TVector3< T > &unitVec) const
Calculates trigonometries for the angle in spherical coordinates.
Definition TOrthonormalBasis3.ipp:94
TOrthonormalBasis3 & setYAxis(const TVector3< T > &axis)
Definition TOrthonormalBasis3.ipp:237
TOrthonormalBasis3()
Creates basis with unit x, y and z axes.
Definition TOrthonormalBasis3.ipp:56
TVector3< T > localToWorld(const TVector3< T > &localVec) const
Definition TOrthonormalBasis3.ipp:86
Represents a 3-D vector.
Definition TVector3.h:17
T & y()
Definition TVector3.ipp:189
T & z()
Definition TVector3.ipp:195
T & x()
Definition TVector3.ipp:183
TVector3 cross(const TVector3 &rhs) const
Definition TVector3.ipp:75
Derived mul(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:98
Derived & set(T value)
Definition TArithmeticArrayBase.ipp:604
T dot(const Derived &rhs) const
Definition TVectorNBase.ipp:14
Derived & mulLocal(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:112
T lengthSquared() const
Definition TVectorNBase.ipp:44
Miscellaneous math utilities.
constexpr T rcp_sqrt_2
Value of .
Definition constant.h:63
Math functions and utilities.
Definition TransformInfo.h:10
T safe_clamp(const T value, const T lowerBound, const T upperBound)
Clamps a value to [lowerBound, upperBound], fallback to lowerBound. If a floating-point value is non-...
Definition math.h:98
T squared(const T value)
Definition math.h:59
T clamp(const T value, const T lowerBound, const T upperBound)
Clamps a value to [lowerBound, upperBound]. None of value, lowerBound and upperBound can be NaN,...
Definition math.h:77