From: Shaheen Gandhi Date: Mon, 19 Aug 2013 03:17:28 +0000 (-0700) Subject: [Helix][perf] Rewrite rotatePoint X-Git-Url: https://git.piment-noir.org/?p=SugarCubes.git;a=commitdiff_plain;h=44521cb76a2deb074c9998d12c223efe734d2371 [Helix][perf] Rewrite rotatePoint --- diff --git a/ShaheenGandhi.pde b/ShaheenGandhi.pde index ff6ce2e..a11d9ca 100644 --- a/ShaheenGandhi.pde +++ b/ShaheenGandhi.pde @@ -40,14 +40,14 @@ class HelixPattern extends SCPattern { return getPointAt(getTValue(pt)); } - PVector rotatePoint(final PVector pt, final float rads) { - Vec3D axisVec3D = new Vec3D(vector.x, vector.y, vector.z); - 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); + PVector rotatePoint(final PVector p, final float t) { + final PVector o = origin; + final PVector v = vector; + + float x = (o.x*(v.y*v.y + v.z*v.z) - v.x*(o.y*v.y + o.z*v.z - v.x*p.x - v.y*p.y - v.z*p.z))*(1 - cos(t)) + p.x*cos(t) + (-o.z*v.y + o.y*v.z - v.z*p.y + v.y*p.z)*sin(t); + float y = (o.y*(v.x*v.x + v.z*v.z) - v.y*(o.x*v.x + o.z*v.z - v.x*p.x - v.y*p.y - v.z*p.z))*(1 - cos(t)) + p.y*cos(t) + (o.z*v.x - o.x*v.z + v.z*p.x - v.x*p.z)*sin(t); + float z = (o.z*(v.x*v.x + v.y*v.y) - v.z*(o.x*v.x + o.y*v.y - v.x*p.x - v.y*p.y - v.z*p.z))*(1 - cos(t)) + p.z*cos(t) + (-o.y*v.x + o.x*v.y - v.y*p.x + v.x*p.y)*sin(t); + return new PVector(x, y, z); } }