From b5dd88803374c586e165c77ac1dbf96c0d0f6ee7 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Tue, 3 Apr 2012 17:11:35 +0200 Subject: Use quaternions instead of 3*3 matrices to represent rotations. --- org/madore/ephem/Frames.java | 82 ++++++++++++++++++---------------------- org/madore/ephem/Nutation.java | 8 ++-- org/madore/ephem/Precession.java | 10 ++--- 3 files changed, 46 insertions(+), 54 deletions(-) (limited to 'org/madore/ephem') diff --git a/org/madore/ephem/Frames.java b/org/madore/ephem/Frames.java index e85412c..a8a4667 100644 --- a/org/madore/ephem/Frames.java +++ b/org/madore/ephem/Frames.java @@ -10,75 +10,67 @@ public final class Frames { } public static final class Vector { - double[] crd; - public Vector(double... crd) { - if ( crd.length != 3 ) + final double[] v; // v.length == 3 + public Vector(double... v) { + if ( v.length != 3 ) throw new IllegalArgumentException("Vector constructor expects 3 coordinates"); - this.crd = crd; + this.v = v; } - public Vector(Double... crd) { - this(unboxDoubleArray(crd)); + public Vector(Double... v) { + this(unboxDoubleArray(v)); } - public double dotprod(Vector v) { + public double dotprod(Vector w) { double res = 0; for ( int i=0 ; i<3 ; i++ ) - res += crd[i]*v.crd[i]; + res += v[i]*w.v[i]; return res; } public double sqnorm() { double res = 0; for ( int i=0 ; i<3 ; i++ ) - res += crd[i]*crd[i]; + res += v[i]*v[i]; return res; } } - public static final class RotationMatrix { - double[][] mat; - public RotationMatrix(double[][] mat) { - if ( mat.length != 3 ) - throw new IllegalArgumentException("RotationMatrix constructor expects 3 lines"); - for ( int i=0 ; i<3 ; i++ ) - if ( mat[i].length != 3 ) - throw new IllegalArgumentException("RotationMatrix constructor expects 3 columns"); - this.mat = mat; - } - private static double[][] matOfVectors(Vector[] vecs) { - double[][] mat = new double[vecs.length][]; - for ( int i=0 ; i