From 280b540777a7df5cf4bd05026080efd53a7835a1 Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@igpm.rwth-aachen.de>
Date: Tue, 27 Jan 2015 20:31:54 +0000
Subject: [PATCH] Implement the inverse stereographic projection, and its
 derivative

[[Imported from SVN: r10027]]
---
 src/inverse-stereographic-projection.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 src/inverse-stereographic-projection.py

diff --git a/src/inverse-stereographic-projection.py b/src/inverse-stereographic-projection.py
new file mode 100644
index 00000000..1cb2b25f
--- /dev/null
+++ b/src/inverse-stereographic-projection.py
@@ -0,0 +1,14 @@
+# The inverse stereographic projection through the north pole, and its derivative
+def f(x):
+    normSquared = x[0]*x[0]+x[1]*x[1]
+    return [2*x[0] / (normSquared+1), 2*x[1] / (normSquared+1), (normSquared-1)/ (normSquared+1)]
+
+def df(x):
+    normSquared = x[0]*x[0]+x[1]*x[1]
+    denominator = (1+normSquared)*(1+normSquared)
+
+    return (( (2*(1+normSquared) - 4*x[0]*x[0]) / denominator, (-4*x[0]*x[1]) / denominator),
+            ( (-4*x[1]*x[0]) / denominator, (2*(1+normSquared) - 4*x[1]*x[1]) / denominator),
+            (4*x[0]/denominator,4*x[1]/denominator))
+
+fdf = (f, df)
-- 
GitLab