Skip to content
Snippets Groups Projects

Kschuster

Merged Kersten Schuster requested to merge kschuster into develop
3 unresolved threads

Merge request reports

Approval is optional

Merged by Philip TrettnerPhilip Trettner 6 years ago (Apr 28, 2019 3:26pm UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
5 #include <typed-geometry/functions/normal.hh>
6 #include <typed-geometry/functions/normalize.hh>
7 #include <typed-geometry/tests/vec_tests.hh>
8 #include <typed-geometry/types/angle.hh>
9 #include <typed-geometry/types/objects/triangle.hh>
10 #include <typed-geometry/types/vec.hh>
11
12 namespace tg
13 {
14 // returns the (smaller) angle between two vectors, i.e. the result is in 0..pi (0°..180°)
15 template <int D, class ScalarT>
16 TG_NODISCARD constexpr angle<fractional_result<ScalarT>> angle_between(vec<D, ScalarT> const& a, vec<D, ScalarT> const& b)
17 {
18 auto a_unit = normalize_safe(a);
19 auto b_unit = normalize_safe(b);
20 return acos(clamp(dot(a_unit, b_unit), fractional_result<ScalarT>(0), fractional_result<ScalarT>(1)));
  • 20 return acos(clamp(dot(a_unit, b_unit), fractional_result<ScalarT>(0), fractional_result<ScalarT>(1)));
    21 }
    22
    23 // returns the angle between any two objects with unambiguous normals. The result is in 0..pi (0°..180°)
    24 template <class A, class B>
    25 TG_NODISCARD constexpr auto angle_between(A const& a, B const& b) -> decltype(acos(dot(normal(a), normal(b))))
    26 {
    27 return acos(clamp(dot(normal(a), normal(b)), decltype(dot(normal(a), normal(b)))(0), decltype(dot(normal(a), normal(b)))(1)));
    28 }
    29
    30 // Returns the angle of a rotation of a towards b about the orthogonal_axis
    31 // The orthogonal axis is important to determine the direction of orientation (axb vs -axb)
    32 template <class ScalarT>
    33 TG_NODISCARD constexpr angle<fractional_result<ScalarT>> angle_towards(vec<3, ScalarT> const& a, vec<3, ScalarT> const& b, vec<3, ScalarT> const& orthogonal_axis)
    34 {
    35 TG_ASSERT(are_orthogonal(a, orthogonal_axis));
  • 41 41 template <class T>
    42 42 TG_NODISCARD constexpr mat<4, 4, T> rotation(angle<T> angle, dir<3, T> const& axis)
  • added 1 commit

    • 6619ac69 - proper rotation naming, saturate instead of clamp(...,0,1).

    Compare with previous version

  • added 1 commit

    • 46d27409 - Use TG_CONTRACT instead of asserts where reasonable.

    Compare with previous version

  • Philip Trettner mentioned in commit 37e1414e

    mentioned in commit 37e1414e

  • Please register or sign in to reply
    Loading