[Helix] Fix toroidal coil calculation
[SugarCubes.git] / ShaheenGandhi.pde
index c25badd6a262ed99000ba8a86882138d93d89e5f..a842fcf4a343b423a61e813353211e10ae4a0e47 100644 (file)
@@ -42,10 +42,11 @@ class HelixPattern extends SCPattern {
 
     PVector rotatePoint(final PVector pt, final float rads) {
       Vec3D axisVec3D = new Vec3D(vector.x, vector.y, vector.z);
-      Matrix4x4 mat = new Matrix4x4();
-      mat.rotateAroundAxis(axisVec3D, rads);
-      Vec3D ptVec3D = new Vec3D(pt.x, pt.y, pt.z);
-      Vec3D rotatedPt = mat.applyTo(ptVec3D);
+      Vec3D originVec3D = new Vec3D(origin.x, origin.y, origin.z);
+      Matrix4x4 mat = new Matrix4x4().identity()
+        .rotateAroundAxis(axisVec3D, rads);
+      Vec3D ptVec3D = new Vec3D(pt.x, pt.y, pt.z).sub(originVec3D);
+      Vec3D rotatedPt = mat.applyTo(ptVec3D).add(originVec3D);
       return new PVector(rotatedPt.x, rotatedPt.y, rotatedPt.z);
     }
   }