/** * Get the coordinate-wise mean of the given vectors. */ static public Vector mean (List<? extends Vector> data) { if (data.isEmpty()) throw new IllegalArgumentException("Attempt to take the mean of 0 vectors"); Vector mean = zeroVector(data.get(0).size()); for (Vector datum: data) { mean = mean.add(datum); } mean = mean.scale(1.0/data.size()); return mean; }
/** * {@inheritDoc} */ public Vector mean (List<? extends Vector> data) { if (data.isEmpty()) throw new IllegalArgumentException("Attempt to take the mean of 0 vectors"); Vector mean = zeroVector(data.get(0).size()); for (Vector datum: data) { mean = mean.add(datum); } mean = mean.scale(1.0/data.size()); return mean; }
public Vector getPoint (double relTime) { int n = getNumSegments(); for (int i=0; i<n; ++i) { double t0 = _times.get(i); double t1 = _times.get(i+1); if (t0 <= relTime && relTime <= t1) { // this segment Vector P0 = getControlPoint(i, 0); Vector P1 = getControlPoint(i, 1); Vector P2 = getControlPoint(i, 2); Vector P3 = getControlPoint(i, 3); double t = (relTime-t0)/(t1-t0); double nt = (1-t); return P0.scale(nt*nt*nt) .add(P1.scale(3*nt*nt*t)) .add(P2.scale(3*nt*t*t)) .add(P3.scale(t*t*t)); } } return null; }
public Vector getPoint (double relTime) { int n = getNumSegments(); for (int i=0; i<n; ++i) { double t0 = _times.get(i); double t1 = _times.get(i+1); if (t0 <= relTime && relTime <= t1) { // this segment Vector P0 = getControlPoint(i, 0); Vector P1 = getControlPoint(i, 1); Vector P2 = getControlPoint(i, 2); Vector P3 = getControlPoint(i, 3); double t = (relTime-t0)/(t1-t0); double nt = (1-t); return P0.scale(nt*nt*nt) .add(P1.scale(3*nt*nt*t)) .add(P2.scale(3*nt*t*t)) .add(P3.scale(t*t*t)); } } return null; }
@Override protected Position interpolate (Position start, Position end, double t) { Vector sV = start.getAsCartesian(); Vector eV = end.getAsCartesian(); Vector cartesianResult = sV.scale(1 - t).add(eV.scale(t)); Position p = new Position(cartesianResult.coord(0), cartesianResult.coord(1), cartesianResult.coord(2), !start.hasElevation()); p.setPrecision(start.getPrecision()); return p; }
b[0] = 2; c[0] = 1; r[0] = K.get(0).add(K.get(1).scale(2)); b[i] = 4; c[i] = 1; r[i] = K.get(i).scale(4).add(K.get(i + 1).scale(2)); b[n - 1] = 7; c[n - 1] = 0; r[n - 1] = K.get(n - 1).scale(8).add(K.get(n)); double m = a[i] / b[i - 1]; b[i] = b[i] - m * c[i - 1]; r[i] = r[i].add(r[i - 1].scale(-m)); P1.add(r[n - 1].scale(1.0 / b[n - 1])); for (int i = n - 2; i >= 0; --i) P1.add(0, r[i].add(P1.get(0).scale(-c[i])).scale(1.0 / b[i])); P2.add(K.get(i + 1).scale(2).subtract(P1.get(i + 1))); P2.add(K.get(n).add(P1.get(n - 1)).scale(0.5));
@Override protected Position interpolate (Position start, Position end, double t) { Vector sV = start.getAsCartesian(); Vector eV = end.getAsCartesian(); Vector cartesianResult = sV.scale(1 - t).add(eV.scale(t)); Position p = new Position(cartesianResult.coord(0), cartesianResult.coord(1), cartesianResult.coord(2), !start.hasElevation()); p.setPrecision(start.getPrecision()); return p; }
@Test public void testCrossProduct () { Vector X = new Vector(1, 0, 0); Vector Y = new Vector(0, 1, 0); Vector Z = new Vector(0, 0, 1); Assert.assertEquals(Z, X.cross(Y)); Assert.assertEquals(Y, Z.cross(X)); Assert.assertEquals(X, Y.cross(Z)); Assert.assertEquals(Z.scale(-1.0), Y.cross(X)); Assert.assertEquals(Y.scale(-1.0), X.cross(Z)); Assert.assertEquals(X.scale(-1.0), Z.cross(Y)); } }
@Override protected double getRelativeError (Position a, Position b, Position c) { Vector vA = a.getAsCartesian(); Vector vB = b.getAsCartesian(); Vector vC = c.getAsCartesian(); Vector ac = vC.subtract(vA); Vector ab = vB.subtract(vA); double lac2 = ac.vectorLengthSquared(); Vector bPerp = ab.subtract(ac.scale(ab.dot(ac)/lac2)); double lbPerp = bPerp.vectorLength(); double lac = Math.sqrt(lac2); return lbPerp/lac; }
@Override protected double getRelativeError (Position a, Position b, Position c) { Vector vA = a.getAsCartesian(); Vector vB = b.getAsCartesian(); Vector vC = c.getAsCartesian(); Vector ac = vC.subtract(vA); Vector ab = vB.subtract(vA); double lac2 = ac.vectorLengthSquared(); Vector bPerp = ab.subtract(ac.scale(ab.dot(ac)/lac2)); double lbPerp = bPerp.vectorLength(); double lac = Math.sqrt(lac2); return lbPerp/lac; }
@Override protected double getRelativeError (Position a, Position b, Position c) { Vector vA = new Vector(a.getLongitude(), a.getLatitude()); Vector vB = new Vector(b.getLongitude(), b.getLatitude()); Vector vC = new Vector(c.getLongitude(), c.getLatitude()); // a, b, and c really should be Positions, but we're treating them as // straight vectors anyway. Vector ac = vC.subtract(vA); Vector ab = vB.subtract(vA); double lac2 = ac.vectorLengthSquared(); Vector bPerp = ab.subtract(ac.scale(ab.dot(ac)/lac2)); double lbPerp = bPerp.vectorLength(); double lac = Math.sqrt(lac2); return lbPerp/lac; }
@Override protected double getRelativeError (Position a, Position b, Position c) { Vector vA = new Vector(a.getLongitude(), a.getLatitude()); Vector vB = new Vector(b.getLongitude(), b.getLatitude()); Vector vC = new Vector(c.getLongitude(), c.getLatitude()); // a, b, and c really should be Positions, but we're treating them as // straight vectors anyway. Vector ac = vC.subtract(vA); Vector ab = vB.subtract(vA); double lac2 = ac.vectorLengthSquared(); Vector bPerp = ab.subtract(ac.scale(ab.dot(ac)/lac2)); double lbPerp = bPerp.vectorLength(); double lac = Math.sqrt(lac2); return lbPerp/lac; }