/** * 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; }
Vector result = A.scale(coeffA).add(B.scale(coeffB)); return new Vector(thetaFromUnitVector(result), phiFromUnitVector(result));
Vector result = A.scale(coeffA).add(B.scale(coeffB)); return new Vector(thetaFromUnitVector(result), phiFromUnitVector(result));
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(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; }
@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; }