Commits

Anonymous committed 1074c75

Added dot() function for quaternions.

Comments (0)

Files changed (2)

neglect/cpplib/include/neglect/quaternion.hpp

         return quaternion<T>(q.w, -q.vec);
     }
 
+    /* calculate the dot product */
+    template <typename T>
+    T dot(const quaternion<T> &lhs,
+          const quaternion<T> &rhs)
+    {
+        return lhs.w * rhs.w + dot(lhs.vec, rhs.vec);
+    }
+
     typedef quaternion<float> quat;
     typedef quaternion<int> quati;
 }

neglect/tests/src/test_quaternion.cpp

         quat q1(1.0f, 1.0f, 2.0f, 3.0f);
         NUT_REQUIRE_EQUAL(inverse(q1), quat(1.0f, -1.0f, -2.0f, -3.0f));
     }
+
+    NUT_TESTCASE(dot_product)
+    {
+        quat q1(1.0f, 2.0f, 3.0f, 4.0f);
+        quat q2(3.0f, 1.0f, 4.0f, 3.0f);
+        NUT_REQUIRE_EQUAL(dot(q1, q2), 29.0f);
+    }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.