List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:edu.ucsf.valelab.saim.calculations.SaimFunction.java
/** * Constructor that includes angle. /*from ww w. ja v a 2s .com*/ * Stores several constants needed during calculations. * @param wavelength - excitation wavelength in nm * @param dOx - thickness of the oxide layer in nm * @param nSample - refractive index of the sample (likely 1.36 or so) * @param angle - angle with respect to the normal in the medium in degrees */ public SaimFunction(double wavelength, double dOx, double nSample, double angle) { this(wavelength, dOx, nSample, false); angle_ = Math.toRadians(angle); }
From source file:org.dawnsci.boofcv.internal.BoofCVImageTransformImpl.java
@Override public IDataset rotate(IDataset data, double angle, boolean keepShape) throws Exception { if (data.getShape().length != 2) throw new Exception("Data shape is not 2D"); ImageFloat32 image = ConvertIDataset.convertFrom(data, ImageFloat32.class, 1); int width = 0, height = 0; if (keepShape) { width = image.width;/*from ww w . ja va 2 s . c om*/ height = image.height; } else { // calculate resulting bounding box double cos = Math.abs(Math.cos(Math.toRadians(angle))); double sin = Math.abs(Math.sin(Math.toRadians(angle))); width = (int) (image.width * cos + image.height * sin); height = (int) (image.height * cos + image.width * sin); } ImageFloat32 rotated = new ImageFloat32(width, height); DistortImageOps.rotate(image, rotated, TypeInterpolate.BILINEAR, (float) Math.toRadians(angle)); return ConvertIDataset.convertTo(rotated, true); }
From source file:io.github.malapert.jwcs.coordsystem.Utility.java
/** * Calculates the matrix that represents a 3d rotation around the X axis. * /*from w w w . j a va2 s . c o m*/ * Reference: * ---------- * Diebel, J. 2006, Stanford University, Representing Attitude: * Euler angles, Unit Quaternions and Rotation Vectors. * http://ai.stanford.edu/~diebel/attitude.html * * Notes: * ------ * Return the rotation matrix for a rotation around the X axis. * This is a rotation in the YZ plane. Note that we construct * a new vector with: xnew = R1.x * In the literature, this rotation is usually called R1 * * @param angle Rotation angle in degrees * @return A 3x3 matrix representing the rotation about angle around X axis. */ public final static RealMatrix rotX(final double angle) { double angleRadians = Math.toRadians(angle); double[][] array = { { 1.d, 0.d, 0.d }, { 0.d, Math.cos(angleRadians), Math.sin(angleRadians) }, { 0.d, -1 * Math.sin(angleRadians), Math.cos(angleRadians) } }; return MatrixUtils.createRealMatrix(array); }
From source file:io.github.malapert.jwcs.coordsystem.FK4.java
/** * Compute the E-terms (elliptic terms of aberration) for a given epoch. * /* w w w. j a v a 2s .c o m*/ * Reference: * ---------- * Seidelman, P.K., 1992. Explanatory Supplement to the Astronomical * Almanac. University Science Books, Mill Valley * * Notes: * ------- * The method is described on page 170/171 of the ES. * One needs to process the e-terms for the appropriate * epoch This routine returns the e-term vector for arbitrary epoch. * * @param epoch A Besselian epoch * @return A tuple containing the e-terms vector (DeltaD,DeltaC,DeltaC.tan(e0)) */ public final static RealMatrix getEterms(float epoch) { //Julian centuries since B1950 double T = (epoch - 1950.0d) * 1.00002135903d / 100.0d; //Eccentricity of the Earth's orbit double ec = 0.01673011d - (0.00004193d + 0.000000126d * T) * T; //Mean obliquity of the ecliptic. Method is different compared to //functions for the obliquity defined earlier. This function depends //on time wrt. epoch 1950 not epoch 2000. double ob = (84404.836d - (46.8495d + (0.00319d + 0.00181d * T) * T) * T); ob = Math.toRadians(ob / 3600.0d); //Mean longitude of perihelion of the solar orbit double p = (1015489.951d + (6190.67d + (1.65d + 0.012d * T) * T) * T); p = Math.toRadians(p / 3600.0d); //Calculate the E-terms vector double ek = ec * Math.toRadians(20.49522d / 3600.0d); // 20.49552 is constant of aberration at J2000 double cp = Math.cos(p); // -DeltaD DeltaC DeltaC.tan(e0) double[][] array = { { ek * Math.sin(p), -1 * ek * cp * Math.cos(ob), -1 * ek * cp * Math.sin(ob) } }; return MatrixUtils.createRealMatrix(array); }
From source file:org.getspout.commons.util.MutableLocation.java
public Vector getDirection() { Vector vector = new MutableVector(); double rotX = this.getYaw(); double rotY = this.getPitch(); vector.setY(-Math.sin(Math.toRadians(rotY))); double h = Math.cos(Math.toRadians(rotY)); vector.setX(-h * Math.sin(Math.toRadians(rotX))); vector.setZ(h * Math.cos(Math.toRadians(rotX))); return vector; }
From source file:org.sample.whiteboardapp.MyWhiteboard.java
static double Distance(double[] point1, double[] point2) { double x1 = Math.toRadians(point1[0]); double x2 = Math.toRadians(point2[0]); double y1 = Math.toRadians(point1[1]); double y2 = Math.toRadians(point2[1]); double x = (y2 - y1) * Math.cos((x1 + x2) / 2); double y = x2 - x1; double D = Math.sqrt((x * x) + (y * y)) * 6371000; // meters return D;// w ww . j a v a2 s . c o m }
From source file:org.getspout.unchecked.api.util.Location.java
public Vector3 getDirection() { Vector3m vector = new Vector3m(0, 0, 0); double rotX = getYaw(); double rotY = getPitch(); vector.setY(-Math.sin(Math.toRadians(rotY))); double h = Math.cos(Math.toRadians(rotY)); vector.setX(-h * Math.sin(Math.toRadians(rotX))); vector.setZ(h * Math.cos(Math.toRadians(rotX))); return vector; }
From source file:Main.java
public static double eval(final String str) { return new Object() { private int pos = -1, ch; void nextChar() { ch = (++pos < str.length()) ? str.charAt(pos) : -1; }// w w w.j a v a2 s. c om boolean eat(int charToEat) { while (ch == ' ') { nextChar(); } if (ch == charToEat) { nextChar(); return true; } return false; } double parse() { nextChar(); double x = parseExpression(); if (pos < str.length()) { throw new IllegalArgumentException("Unexpected: " + (char) ch); } return x; } // Grammar: // expression = term | expression `+` term | expression `-` term // term = factor | term `*` factor | term `/` factor // factor = `+` factor | `-` factor | `(` expression `)` // | number | functionName factor | factor `^` factor double parseExpression() { double x = parseTerm(); for (;;) { if (eat('+')) { x += parseTerm(); // addition } else { if (eat('-')) { x -= parseTerm(); // subtraction } else { return x; } } } } double parseTerm() { double x = parseFactor(); for (;;) { if (eat('*')) { x *= parseFactor(); // multiplication } else { if (eat('/')) { x /= parseFactor(); // division } else { return x; } } } } double parseFactor() { if (eat('+')) { return parseFactor(); // unary plus } if (eat('-')) { return -parseFactor(); // unary minus } double x; int startPos = this.pos; if (eat('(')) { // parentheses x = parseExpression(); eat(')'); } else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers while ((ch >= '0' && ch <= '9') || ch == '.') { nextChar(); } x = Double.parseDouble(str.substring(startPos, this.pos)); } else if (ch >= 'a' && ch <= 'z') { // functions while (ch >= 'a' && ch <= 'z') { nextChar(); } String func = str.substring(startPos, this.pos); x = parseFactor(); switch (func) { case "sqrt": x = Math.sqrt(x); break; case "sin": x = Math.sin(Math.toRadians(x)); break; case "cos": x = Math.cos(Math.toRadians(x)); break; case "tan": x = Math.tan(Math.toRadians(x)); break; default: throw new IllegalArgumentException("Unknown function: " + func); } } else { throw new IllegalArgumentException("Unexpected: " + (char) ch); } if (eat('^')) { x = Math.pow(x, parseFactor()); // exponentiation } return x; } }.parse(); }
From source file:org.spout.math.Quaternion.java
/** * Constructs a new Quaternion that represents a given rotation around an * arbitrary axis/*from w w w . j av a 2 s . co m*/ * @param angle Angle, in Degrees, to rotate the axis about by * @param x-axis * @param y-axis * @param z-axis */ public Quaternion(float angle, float x, float y, float z) { double halfAngle = Math.toRadians(angle) / 2; double q = Math.sin(halfAngle) / Math.sqrt(x * x + y * y + z * z); this.x = (float) (x * q); this.y = (float) (y * q); this.z = (float) (z * q); this.w = (float) Math.cos(halfAngle); }
From source file:org.opentripplanner.common.geometry.SphericalDistanceLibrary.java
@Override public final double fastDistance(Coordinate point, LineString lineString) { // Transform in equirectangular projection on sphere of radius 1, // centered at point double lat = Math.toRadians(point.y); double cosLat = FastMath.cos(lat); double lon = Math.toRadians(point.x) * cosLat; Point point2 = GeometryUtils.getGeometryFactory().createPoint(new Coordinate(lon, lat)); LineString lineString2 = equirectangularProject(lineString, cosLat); return lineString2.distance(point2) * RADIUS_OF_EARTH_IN_M; }