commit 216c55269d7dc44701ac24a584f653b49c6b9df8
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Jan 24 12:53:31 2020 +0000

    RubikCube: fix dragging.

diff --git a/src/main/java/org/distorted/magic/RubikSurfaceView.java b/src/main/java/org/distorted/magic/RubikSurfaceView.java
index b495520e..7ffbcebb 100644
--- a/src/main/java/org/distorted/magic/RubikSurfaceView.java
+++ b/src/main/java/org/distorted/magic/RubikSurfaceView.java
@@ -354,8 +354,8 @@ class RubikSurfaceView extends GLSurfaceView
 
     private Static4D quatFromDrag(float dragX, float dragY)
       {
-      float axisX = dragY;  // inverted X and Y - rotation axis is
-      float axisY = dragX;  // perpendicular to (dragX,dragY)   Why not (-dragY, dragX) ? because Y axis is also inverted!
+      float axisX = dragY;  // inverted X and Y - rotation axis is perpendicular to (dragX,dragY)
+      float axisY = dragX;  // Why not (-dragY, dragX) ? because Y axis is also inverted!
       float axisZ = 0;
       float axisL = (float)Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
 
@@ -365,7 +365,10 @@ class RubikSurfaceView extends GLSurfaceView
         axisY /= axisL;
         axisZ /= axisL;
 
-        float cosA = (float)Math.cos(axisL*Math.PI/mScreenMin);
+        float ratio = axisL/mScreenMin;
+        ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
+
+        float cosA = (float)Math.cos(Math.PI*ratio);
         float sinA = (float)Math.sqrt(1-cosA*cosA);
 
         return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
