From efe17860dbafcb0a4ce0ada799b00afa80097b3c Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@igpm.rwth-aachen.de>
Date: Thu, 11 Feb 2010 22:02:36 +0000
Subject: [PATCH] implement derivativeOfDistanceSquaredWRTSecondArgument(). 
 Not tested yet

[[Imported from SVN: r5549]]
---
 src/unitvector.hh | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/unitvector.hh b/src/unitvector.hh
index 9826c247..ba3321fc 100644
--- a/src/unitvector.hh
+++ b/src/unitvector.hh
@@ -32,6 +32,16 @@ public:
         return std::acos(a.data_ * b.data_);
     }
 
+    /** \brief Compute the gradient of the squared distance function keeping the first argument fixed
+
+    Unlike the distance itself the squared distance is differentiable at zero
+     */
+    static EmbeddedTangentVector derivativeOfDistanceSquaredWRTSecondArgument(const UnitVector& a, const UnitVector& b) {
+        EmbeddedTangentVector result = a.data_;
+        result *= -2*std::acos(a.data_ * b.data_) / std::sqrt(1-(a.data_*b.data_)*(a.data_*b.data_));
+        return result;
+    }
+
     /** \brief Write LocalKey object to output stream */
     friend std::ostream& operator<< (std::ostream& s, const UnitVector& unitVector)
     {
-- 
GitLab