List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:edu.ucsf.valelab.saim.calculations.TestSaimFitter.java
public void test() throws Exception { double wavelength = 488.0; double nSample = 1.36; double dOx = 500.0; double A = 100.0; double B = 100.0; double h = 16.0; double fractionMaxError = 0.0000001; final int nrTries = 10; // make a collection of "observed" points ArrayList<WeightedObservedPoint> points = new ArrayList<WeightedObservedPoint>(); for (int i = -50; i <= 50; i += 2) { double angle = Math.toRadians(i); double I = A * SaimCalc.fieldStrength(wavelength, angle, nSample, dOx, h) + B; WeightedObservedPoint point = new WeightedObservedPoint(1.0, angle, I); points.add(point);// w w w. j a v a 2s. c o m } // create the fitter SaimFunctionFitter sff = new SaimFunctionFitter(wavelength, dOx, nSample, false); double[] values = new double[] { A, B, h }; // test by varying the input for height for (int i = 0; i < nrTries; i++) { double[] guess = values.clone(); guess[0] = 50.0; guess[1] = 150.0; guess[2] = guess[2] + (guess[2] * (Math.random() - 0.5) * 10); if (guess[2] < 1.0) guess[2] = 1.0; for (int j = 0; j < guess.length; j++) { System.out.println("Guess: " + j + " " + guess[j]); } sff.setGuess(guess); final double[] coefficients = sff.fit(points); for (int j = 0; j < coefficients.length; j++) { System.out .println("coefficient " + j + ", expected: " + values[j] + ", found: " + coefficients[j]); assertEquals(values[j], coefficients[j], values[j] * fractionMaxError); } System.out.println("Value was calculated: " + sff.getCalcCount() + " times"); sff.resetCalcCount(); } // test by adding noise to the input // make a collection of "observed" points final double noiseFactor = 0.1; // 10% noise fractionMaxError = noiseFactor; double[] guess = values.clone(); guess[0] = 50.0; guess[1] = 150.0; guess[2] = 50.0; for (int j = 0; j < guess.length; j++) { System.out.println("Guess: " + j + " " + guess[j]); } for (int i = 0; i < nrTries; i++) { ArrayList<WeightedObservedPoint> noisyPoints = new ArrayList<WeightedObservedPoint>(); for (int j = -50; j <= 50; j += 2) { double angle = Math.toRadians(j); double I = A * SaimCalc.fieldStrength(wavelength, angle, nSample, dOx, h) + B; WeightedObservedPoint noisyPoint = new WeightedObservedPoint(1.0, angle, I + I * (Math.random() - 0.5) * noiseFactor); noisyPoints.add(noisyPoint); } sff.setGuess(guess); final double[] coefficients = sff.fit(noisyPoints); for (int j = 0; j < coefficients.length; j++) { System.out .println("coefficient " + j + ", expected: " + values[j] + ", found: " + coefficients[j]); assertEquals(values[j], coefficients[j], values[j] * fractionMaxError); } System.out.println("Value was calculated: " + sff.getCalcCount() + " times"); sff.resetCalcCount(); } }
From source file:edu.ucsf.valelab.saim.calculations.TestSaimErrorFunction.java
public void test() throws Exception { SaimData data = new SaimData(); data.wavelength_ = 488.0;//from w w w . j a v a 2 s. co m data.nSample_ = 1.36; data.dOx_ = 500.0; data.A_ = 1000.0; data.B_ = 5000.0; data.heights_ = new double[] { 75.0 }; double maxError = 0.0000000001; // make a collection of "observed" points ArrayList<WeightedObservedPoint> points = new ArrayList<WeightedObservedPoint>(); for (int i = -50; i <= 50; i += 1) { double angle = Math.toRadians(i); double I = data.A_ * SaimCalc.fieldStrength(data.wavelength_, angle, data.nSample_, data.dOx_, data.heights_[0]) + data.B_; WeightedObservedPoint point = new WeightedObservedPoint(1.0, angle, I); points.add(point); } // calculate the error with these ideal points (shoudle be 0) SaimErrorFunction sef = new SaimErrorFunction(data, points); double[] parameters = { data.A_, data.B_, data.heights_[0] }; double error = sef.value(parameters); System.out.println("SaimError error: " + error); assertEquals(0.0, error, maxError); // now add 1 to all the data points. Error should be number of data points ArrayList<WeightedObservedPoint> newPoints = new ArrayList<WeightedObservedPoint>(); for (WeightedObservedPoint point : points) { newPoints.add(new WeightedObservedPoint(1.0, point.getX(), point.getY() + 1.0)); } SaimErrorFunction sef2 = new SaimErrorFunction(data, newPoints); error = sef2.value(parameters); System.out.println("SaimError error: " + error); assertEquals(points.size(), error, maxError); }
From source file:edu.ucsf.valelab.saim.calculations.TestSaimErrorFunctionFitter.java
public void test() throws Exception { SaimData data = new SaimData(); data.wavelength_ = 488.0;// www .j a va 2 s. co m data.nSample_ = 1.36; data.dOx_ = 500.0; data.A_ = 1000.0; data.B_ = 5000.0; data.heights_ = new double[] { 75.0 }; double maxError = 0.00000000001; int nrRepeats = 5; // make a collection of "observed" points ArrayList<WeightedObservedPoint> points = new ArrayList<WeightedObservedPoint>(); for (int i = -50; i <= 50; i += 1) { double angle = Math.toRadians(i); double I = data.A_ * SaimCalc.fieldStrength(data.wavelength_, angle, data.nSample_, data.dOx_, data.heights_[0]) + data.B_; WeightedObservedPoint point = new WeightedObservedPoint(1.0, angle, I); points.add(point); } System.out.println("BOBYQA Test results (TestSaimErrorFunctionFitter:"); System.out.println("Goal: " + data.A_ + ", " + data.B_ + ", " + data.heights_[0]); for (int i = 0; i < nrRepeats; i++) { SaimErrorFunctionFitter sef = new SaimErrorFunctionFitter(data); double[] guess = { Math.random() * 4000.0, Math.random() * 10000.0, Math.random() * 300.0 }; sef.setGuess(guess); double[] result = sef.fit(points); System.out.println("Guess: " + guess[0] + ", " + guess[1] + ", " + guess[2]); System.out.println("Result: " + result[0] + ", " + result[1] + ", " + result[2]); } }
From source file:demo.support.NavUtils.java
/** * Returns bearing of position 2 from position 1. * @param pt1//w w w.j a v a 2 s . co m * @param pt2 * @return */ public static double getBearing(Point pt1, Point pt2) { double longitude1 = pt1.getLongitude(); double longitude2 = pt2.getLongitude(); double latitude1 = Math.toRadians(pt1.getLatitude()); double latitude2 = Math.toRadians(pt2.getLatitude()); double longDiff = Math.toRadians(longitude2 - longitude1); double y = Math.sin(longDiff) * Math.cos(latitude2); double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff); return (Math.toDegrees(Math.atan2(y, x)) + 360) % 360; }
From source file:org.spout.vanilla.protocol.msg.PlayerLookMessage.java
public PlayerLookMessage(float yaw, float pitch, boolean onGround) { this.roll = 0.0f; // There is no roll this.yaw = yaw; this.pitch = pitch; this.onGround = onGround; this.lookingAt = SinusHelper.get3DAxis((float) Math.toRadians(yaw), (float) Math.toRadians(pitch)); }
From source file:org.spout.vanilla.protocol.msg.player.pos.PlayerYawMessage.java
public PlayerYawMessage(float yaw, float pitch, boolean onGround) { this.roll = 0.0f; // There is no roll this.yaw = yaw; this.pitch = pitch; this.onGround = onGround; this.lookingAt = SinusHelper.get3DAxis((float) Math.toRadians(yaw), (float) Math.toRadians(pitch)); }
From source file:eu.itesla_project.iidm.ddb.eurostag.model.TransformerModel.java
public StateVariable toSv1(StateVariable sv2) { Complex s2 = new Complex(-sv2.p, -sv2.q); // s2=p2+jq2 Complex u2 = ComplexUtils.polar2Complex(sv2.u, Math.toRadians(sv2.theta)); Complex v2 = u2.divide(SQUARE_3); // v2=u2/sqrt(3) Complex i2 = s2.divide(v2.multiply(3)).conjugate(); // i2=conj(s2/(3*v2)) Complex v1p = v2.add(z.multiply(i2)); // v1'=v2+z*i2 Complex i1p = i2.negate().add(y.multiply(v1p)); // i1'=-i2+v1'*y Complex i1 = i1p.multiply(ratio); // i1=i1p*ration Complex v1 = v1p.divide(ratio); // v1=v1p/ration Complex s1 = v1.multiply(3).multiply(i1.conjugate()); // s1=3*v1*conj(i1) Complex u1 = v1.multiply(SQUARE_3);// w w w . ja va 2 s. c o m return new StateVariable(-s1.getReal(), -s1.getImaginary(), u1.abs(), Math.toDegrees(u1.getArgument())); }
From source file:webservice.ImportantPlacesWorker.java
private String calculateSpeed(long t1, double lat1, double lng1, long t2, double lat2, double lng2) { int R = 6371000; // meters double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lng2 - lng1); lat1 = Math.toRadians(lat1);/*from w w w . jav a 2 s. c om*/ lat2 = Math.toRadians(lat2); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = R * c; double speed = Math.round((distance / (t2 - t1)) * 3.6); if (0 <= speed && speed < 5) { return "0-5"; } else if (5 <= speed && speed < 15) { return "5-15"; } else if (15 <= speed && speed < 50) { return "15-50"; } else if (50 <= speed && speed < 120) { return "50-120"; } else { return "120<=x"; } }
From source file:com.jaeksoft.searchlib.util.ImageUtils.java
public static BufferedImage rotate(BufferedImage image, float degree) throws InterruptedException { Rotation rot = null;// w ww . j av a 2 s . com AffineTransformOp[] xform = null; switch ((int) degree) { case 90: rot = Rotation.CW_90; break; case 180: rot = Rotation.CW_180; break; case 270: rot = Rotation.CW_270; break; default: xform = new AffineTransformOp[1]; xform[0] = new AffineTransformOp(AffineTransform.getRotateInstance(Math.toRadians(degree)), AffineTransformOp.TYPE_BICUBIC); break; } if (rot != null) return Scalr.rotate(image, rot, xform); return Scalr.apply(image, xform); }
From source file:uk.ac.diamond.scisoft.ncd.core.DegreeOfOrientation.java
public Object[] process(Serializable buffer, Serializable axis, final int[] dimensions) { double[] parentaxis = (double[]) ConvertUtils.convert(axis, double[].class); float[] parentdata = (float[]) ConvertUtils.convert(buffer, float[].class); int size = dimensions[dimensions.length - 1]; double[] myaxis = new double[size]; double[] mydata = new double[size]; double[] cos2data = new double[size]; double[] sin2data = new double[size]; double[] sincosdata = new double[size]; for (int i = 0; i < parentaxis.length; i++) { myaxis[i] = Math.toRadians(parentaxis[i]); mydata[i] = parentdata[i];// w w w. j a v a2 s . co m float cos2alpha = (float) Math.cos(2.0 * myaxis[i]); float sin2alpha = (float) Math.sin(2.0 * myaxis[i]); cos2data[i] = (1.0f + cos2alpha) * parentdata[i] / 2.0; sin2data[i] = (1.0f - cos2alpha) * parentdata[i] / 2.0; sincosdata[i] = sin2alpha * parentdata[i] / 2.0; } UnivariateInterpolator interpolator = new SplineInterpolator(); UnivariateFunction function = interpolator.interpolate(myaxis, mydata); UnivariateFunction cos2Function = interpolator.interpolate(myaxis, cos2data); UnivariateFunction sin2Function = interpolator.interpolate(myaxis, sin2data); UnivariateFunction sincosFunction = interpolator.interpolate(myaxis, sincosdata); UnivariateIntegrator integrator = new IterativeLegendreGaussIntegrator(15, BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY, BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY); try { float cos2mean = (float) integrator.integrate(INTEGRATION_POINTS, cos2Function, myaxis[0], myaxis[myaxis.length - 1]); float sin2mean = (float) integrator.integrate(INTEGRATION_POINTS, sin2Function, myaxis[0], myaxis[myaxis.length - 1]); float sincosmean = (float) integrator.integrate(INTEGRATION_POINTS, sincosFunction, myaxis[0], myaxis[myaxis.length - 1]); float norm = (float) integrator.integrate(INTEGRATION_POINTS, function, myaxis[0], myaxis[myaxis.length - 1]); cos2mean /= norm; sin2mean /= norm; sincosmean /= norm; float result = (float) Math.sqrt(Math.pow(cos2mean - sin2mean, 2) - 4.0 * sincosmean * sincosmean); double angle = MathUtils.normalizeAngle(Math.atan2(2.0 * sincosmean, cos2mean - sin2mean) / 2.0, Math.PI); Object[] output = new Object[] { new float[] { result }, new float[] { (float) Math.toDegrees(angle) }, new float[] { (float) (result * Math.cos(angle)), (float) (result * Math.sin(angle)) }, }; return output; } catch (TooManyEvaluationsException e) { return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } }; } catch (MaxCountExceededException e) { return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } }; } }