List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:com.dianping.imcaptcha.strategy.WaveFilter.java
protected void transformInverse(int x, int y, float[] out, float radius) { out[0] = (float) (x - factor * Math.sin(y / radius)); out[1] = y;//ww w .j a va 2 s . c o m }
From source file:jat.core.cm.TwoBodyAPL.java
public void propagate(double t0, double tf, Printable pr, boolean print_switch, double steps) { double[] temp = new double[6]; // double ta_save = this.ta; this.steps = steps; // Determine step size double n = this.meanMotion(); double period = this.period(); double dt = period / steps; if ((t0 + dt) > tf) // check to see if we're going past tf {/*from ww w .j av a2 s.c o m*/ dt = tf - t0; } // determine initial E and M double sqrome2 = Math.sqrt(1.0 - this.e * this.e); double cta = Math.cos(this.ta); double sta = Math.sin(this.ta); double sine0 = (sqrome2 * sta) / (1.0 + this.e * cta); double cose0 = (this.e + cta) / (1.0 + this.e * cta); double e0 = Math.atan2(sine0, cose0); double ma = e0 - this.e * Math.sin(e0); // initialize t double t = t0; if (print_switch) { temp = this.randv(); pr.print(t, temp); } while (t < tf) { ma = ma + n * dt; double ea = solveKepler(ma, this.e); double sinE = Math.sin(ea); double cosE = Math.cos(ea); double den = 1.0 - this.e * cosE; double sinv = (sqrome2 * sinE) / den; double cosv = (cosE - this.e) / den; this.ta = Math.atan2(sinv, cosv); if (this.ta < 0.0) { this.ta = this.ta + 2.0 * Constants.pi; } t = t + dt; temp = this.randv(); this.rv = new VectorN(temp); if (print_switch) { pr.print(t, temp); } if ((t + dt) > tf) { dt = tf - t; } } // Reset everything to before this.ta = initial_ta; }
From source file:com.grayfox.server.service.PoiService.java
private double distanceBetween(Location location1, Location location2) { double fi1 = Math.toRadians(location1.getLatitude()); double fi2 = Math.toRadians(location2.getLatitude()); double deltaLambda = Math.toRadians(location2.getLongitude() - location1.getLongitude()); return Math.acos(Math.sin(fi1) * Math.sin(fi2) + Math.cos(fi1) * Math.cos(fi2) * Math.cos(deltaLambda)) * Constants.Ints.EARTH_RADIUS; }
From source file:edu.jhuapl.graphs.jfreechart.utils.RotatedTickDateAxis.java
@Override protected double findMaximumTickLabelHeight(List ticks, Graphics2D g2, Rectangle2D drawArea, boolean vertical) { double heightScalingFactor = Math.abs(Math.sin(Math.toRadians(tickLabelAngle))); return super.findMaximumTickLabelHeight(ticks, g2, drawArea, vertical) * heightScalingFactor; }
From source file:StatFunctions.java
public static double qt(double p, double ndf, boolean lower_tail) { // Algorithm 396: Student's t-quantiles by // G.W. Hill CACM 13(10), 619-620, October 1970 if (p <= 0 || p >= 1 || ndf < 1) throw new IllegalArgumentException("Invalid p or df in call to qt(double,double,boolean)."); double eps = 1e-12; double M_PI_2 = 1.570796326794896619231321691640; // pi/2 boolean neg;/*from w ww.j ava 2 s . c o m*/ double P, q, prob, a, b, c, d, y, x; if ((lower_tail && p > 0.5) || (!lower_tail && p < 0.5)) { neg = false; P = 2 * (lower_tail ? (1 - p) : p); } else { neg = true; P = 2 * (lower_tail ? p : (1 - p)); } if (Math.abs(ndf - 2) < eps) { /* df ~= 2 */ q = Math.sqrt(2 / (P * (2 - P)) - 2); } else if (ndf < 1 + eps) { /* df ~= 1 */ prob = P * M_PI_2; q = Math.cos(prob) / Math.sin(prob); } else { /*-- usual case; including, e.g., df = 1.1 */ a = 1 / (ndf - 0.5); b = 48 / (a * a); c = ((20700 * a / b - 98) * a - 16) * a + 96.36; d = ((94.5 / (b + c) - 3) / b + 1) * Math.sqrt(a * M_PI_2) * ndf; y = Math.pow(d * P, 2 / ndf); if (y > 0.05 + a) { /* Asymptotic inverse expansion about normal */ x = qnorm(0.5 * P, false); y = x * x; if (ndf < 5) c += 0.3 * (ndf - 4.5) * (x + 0.6); c = (((0.05 * d * x - 5) * x - 7) * x - 2) * x + b + c; y = (((((0.4 * y + 6.3) * y + 36) * y + 94.5) / c - y - 3) / b + 1) * x; y = a * y * y; if (y > 0.002)/* FIXME: This cutoff is machine-precision dependent */ y = Math.exp(y) - 1; else { /* Taylor of e^y -1 : */ y = (0.5 * y + 1) * y; } } else { y = ((1 / (((ndf + 6) / (ndf * y) - 0.089 * d - 0.822) * (ndf + 2) * 3) + 0.5 / (ndf + 4)) * y - 1) * (ndf + 1) / (ndf + 2) + 1 / y; } q = Math.sqrt(ndf * y); } if (neg) q = -q; return q; }
From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.GyroscopeOrientation.java
/** * Create an angle-axis vector, in this case a unit quaternion, from the * provided Euler angle's (presumably from SensorManager.getOrientation()). * /* w w w.j a v a 2 s.com*/ * Equation from * http://www.euclideanspace.com/maths/geometry/rotations/conversions * /eulerToQuaternion/ * * @param orientation */ private void getRotationVectorFromAccelMag() { // Assuming the angles are in radians. // getOrientation() values: // values[0]: azimuth, rotation around the Z axis. // values[1]: pitch, rotation around the X axis. // values[2]: roll, rotation around the Y axis. // Heading, Azimuth, Yaw double c1 = Math.cos(vOrientationAccelMag[0] / 2); double s1 = Math.sin(vOrientationAccelMag[0] / 2); // Pitch, Attitude // The equation assumes the pitch is pointed in the opposite direction // of the orientation vector provided by Android, so we invert it. double c2 = Math.cos(-vOrientationAccelMag[1] / 2); double s2 = Math.sin(-vOrientationAccelMag[1] / 2); // Roll, Bank double c3 = Math.cos(vOrientationAccelMag[2] / 2); double s3 = Math.sin(vOrientationAccelMag[2] / 2); double c1c2 = c1 * c2; double s1s2 = s1 * s2; double w = c1c2 * c3 - s1s2 * s3; double x = c1c2 * s3 + s1s2 * c3; double y = s1 * c2 * c3 + c1 * s2 * s3; double z = c1 * s2 * c3 - s1 * c2 * s3; // The quaternion in the equation does not share the same coordinate // system as the Android gyroscope quaternion we are using. We reorder // it here. // Android X (pitch) = Equation Z (pitch) // Android Y (roll) = Equation X (roll) // Android Z (azimuth) = Equation Y (azimuth) qGyroscope = new Quaternion(w, z, x, y); }
From source file:dz.alkhwarizmix.winrak.java.model.vo.WinrakPosition.java
/** * http://www.movable-type.co.uk/scripts/latlong.html *///w ww . j a va2 s . c o m @Override public int distanceTo(final IWinrakPosition pos2) { final WinrakPosition pos1 = this; final Double R = 6371000.0; // metres final Double radLat1 = Math.toRadians(pos1.getLat()); final Double radLat2 = Math.toRadians(pos2.getLat()); final Double deltaLat = Math.toRadians(pos2.getLat() - pos1.getLat()); final Double deltaLng = Math.toRadians(pos2.getLng() - pos1.getLng()); final Double a = (Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2)) + (Math.cos(radLat1) * Math.cos(radLat2) * Math.sin(deltaLng / 2) * Math.sin(deltaLng / 2)); final Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); final Double d = R * c; return (d.intValue()); }
From source file:chiliad.parser.pdf.extractor.vectorgraphics.operator.Invoke.java
/** * process : Do : Paint the specified XObject (section 4.7). * * @param operator The operator that is being executed. * @param arguments List//w ww.j a va 2 s . co m * @throws IOException If there is an error invoking the sub object. */ @Override public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context; PDPage page = extractor.getPage(); COSName objectName = (COSName) arguments.get(0); Map<String, PDXObject> xobjects = extractor.getResources().getXObjects(); PDXObject xobject = (PDXObject) xobjects.get(objectName.getName()); if (xobject == null) { LOG.warn("Can't find the XObject for '" + objectName.getName() + "'"); } else if (xobject instanceof PDXObjectImage) { PDXObjectImage image = (PDXObjectImage) xobject; try { if (image.getImageMask()) { // set the current non stroking colorstate, so that it can // be used to create a stencil masked image image.setStencilColor(extractor.getGraphicsState().getNonStrokingColor()); } BufferedImage awtImage = image.getRGBImage(); if (awtImage == null) { LOG.warn("getRGBImage returned NULL"); return;//TODO PKOCH } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = extractor.getPageSize().getHeight(); LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight); Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix(); float yScaling = ctm.getYScale(); float angle = (float) Math.acos(ctm.getValue(0, 0) / ctm.getXScale()); if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0) { angle = (-1) * angle; } ctm.setValue(2, 1, (float) (pageHeight - ctm.getYPosition() - Math.cos(angle) * yScaling)); ctm.setValue(2, 0, (float) (ctm.getXPosition() - Math.sin(angle) * yScaling)); // because of the moved 0,0-reference, we have to shear in the opposite direction ctm.setValue(0, 1, (-1) * ctm.getValue(0, 1)); ctm.setValue(1, 0, (-1) * ctm.getValue(1, 0)); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); extractor.drawImage(awtImage, ctmAT); } catch (Exception e) { LOG.error(e, e); } } else if (xobject instanceof PDXObjectForm) { // save the graphics state context.getGraphicsStack().push((PDGraphicsState) context.getGraphicsState().clone()); PDXObjectForm form = (PDXObjectForm) xobject; COSStream formContentstream = form.getCOSStream(); // find some optional resources, instead of using the current resources PDResources pdResources = form.getResources(); // if there is an optional form matrix, we have to map the form space to the user space Matrix matrix = form.getMatrix(); if (matrix != null) { Matrix xobjectCTM = matrix.multiply(context.getGraphicsState().getCurrentTransformationMatrix()); context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM); } if (form.getBBox() != null) { PDGraphicsState graphicsState = context.getGraphicsState(); PDRectangle bBox = form.getBBox(); float x1 = bBox.getLowerLeftX(); float y1 = bBox.getLowerLeftY(); float x2 = bBox.getUpperRightX(); float y2 = bBox.getUpperRightY(); Point2D p0 = extractor.transformedPoint(x1, y1); Point2D p1 = extractor.transformedPoint(x2, y1); Point2D p2 = extractor.transformedPoint(x2, y2); Point2D p3 = extractor.transformedPoint(x1, y2); GeneralPath bboxPath = new GeneralPath(); bboxPath.moveTo((float) p0.getX(), (float) p0.getY()); bboxPath.lineTo((float) p1.getX(), (float) p1.getY()); bboxPath.lineTo((float) p2.getX(), (float) p2.getY()); bboxPath.lineTo((float) p3.getX(), (float) p3.getY()); bboxPath.closePath(); Area resultClippingArea = new Area(graphicsState.getCurrentClippingPath()); Area newArea = new Area(bboxPath); resultClippingArea.intersect(newArea); graphicsState.setCurrentClippingPath(resultClippingArea); } getContext().processSubStream(page, pdResources, formContentstream); // restore the graphics state context.setGraphicsState((PDGraphicsState) context.getGraphicsStack().pop()); } }
From source file:com.github.mfpdev.marketing.StoreCategorySegmentResolverResource.java
private double distance(double lon1, double lat1, double lon2, double lat2) { double dLat = Math.toRadians(lat2 - lat1); // Javascript functions in radians double dLon = Math.toRadians(lon2 - lon1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return EARTH_RADIUS * c; // Distance in km }
From source file:com.alvermont.terraj.planet.project.SquareProjection.java
/** * Carry out the projection//from w w w. j av a2s . c o m */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); depth = (3 * ((int) (log2(scale * height)))) + 6; cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; double y; double scale1; double theta1; double cos2; int k; int i; int j; k = (int) ((lat * width * scale) / Math.PI); progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); y = ((2.0 * (j - k)) - height) / width / scale * Math.PI; if (Math.abs(y) >= (0.5 * Math.PI)) { for (i = 0; i < width; ++i) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } } else { cos2 = Math.cos(y); if (cos2 > 0.0) { scale1 = (scale * width) / height / cos2 / Math.PI; depth = (3 * ((int) (log2(scale1 * height)))) + 3; for (i = 0; i < width; ++i) { theta1 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * i) - width)) / width / scale); colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, Math.sin(y), -Math.sin(theta1) * cos2); if (doShade) { shades[i][j] = shade; } } } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.toRadians(theta1); j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k; if ((j >= 0) && (j < height)) { for (i = 0; i < width; ++i) colours[i][j] = BLACK; } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid) ; for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) { i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI))); if ((i >= 0) && (i < width)) { for (j = Math.max(0, (height / 2) - (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); j < Math.min( height, (height / 2) + (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); ++j) { colours[i][j] = BLACK; } } } } if (doShade) { smoothshades(); } doOutlining(); }