Add of some mathematical functions
Plane: Getters and classic planes Sphere: Getter Vector2: Angle between two vectors Vector3: Same in 3D Former-commit-id: 07e6421def813743e5fd8248fe2e9503cebbb8a8
This commit is contained in:
@@ -60,6 +60,30 @@ inline unsigned int NzVector3<unsigned int>::AbsDotProduct(const NzVector3<unsig
|
||||
return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzVector3<T>::AngleBetween(const NzVector3& vec, bool toDegree) const
|
||||
{
|
||||
T alpha = DotProduct(vec);
|
||||
T divisor = (GetLength() * vec.GetLength());
|
||||
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NzNumberEquals(divisor, F(0.0)))
|
||||
{
|
||||
NzString error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
alpha /= divisor;
|
||||
|
||||
if (toDegree)
|
||||
return NzRadianToDegree(std::acos(NzClamp(alpha, F(-1.0), F(1.0))));
|
||||
else
|
||||
return std::acos(NzClamp(alpha, F(-1.0), F(1.0)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T> NzVector3<T>::CrossProduct(const NzVector3& vec) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user