mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-16 22:19:51 +07:00
qua: distance func
This commit is contained in:
@@ -244,6 +244,12 @@ namespace vmath_hpp
|
||||
return length2(vec{xs});
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] T distance(const qua<T>& xs, const qua<T>& ys) {
|
||||
const qua zs = xs * conjugate(ys);
|
||||
return T(2) * atan2(length(zs.v), abs(zs.s));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr qua<T> normalize(const qua<T>& xs) {
|
||||
return qua(normalize(vec{xs}));
|
||||
|
||||
@@ -154,6 +154,13 @@ TEST_CASE("vmath/qua_fun") {
|
||||
STATIC_REQUIRE(length2(fqua(10.f,0.f,0.f,0.f)) == uapprox(100.f));
|
||||
STATIC_REQUIRE(length2(fqua(-10.f,0.f,0.f,0.f)) == uapprox(100.f));
|
||||
|
||||
REQUIRE(distance(qrotate_z(radians(0.f)) * 2.f, qrotate_z(radians(0.f)) * 1.5f) == uapprox(radians(0.f)));
|
||||
REQUIRE(distance(qrotate_z(radians(0.f)) * 3.f, qrotate_z(radians(360.f)) * 2.5f) == uapprox(radians(0.f)));
|
||||
REQUIRE(distance(qrotate_z(radians(0.f)) * 4.f, qrotate_z(radians(180.f)) * 3.5f) == uapprox(radians(180.f)));
|
||||
REQUIRE(distance(qrotate_z(radians(180.f)) * 5.f, qrotate_z(radians(0.f)) * 4.5f) == uapprox(radians(180.f)));
|
||||
REQUIRE(distance(qrotate_z(radians(15.f)) * 6.f, qrotate_z(radians(350.f)) * 5.5f) == uapprox(radians(25.f)));
|
||||
REQUIRE(distance(qrotate_z(radians(350.f)) * 7.f, qrotate_z(radians(15.f)) * 6.5f) == uapprox(radians(25.f)));
|
||||
|
||||
REQUIRE(normalize(fqua(0.5f,0.f,0.f,0.f)).v == uapprox3(1.f,0.f,0.f));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user