List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:Hexagon.java
public Hexagon(Point2D center, int size) { super();// w w w . ja va 2 s. c om this.center = center; this.size = size; /** * MATH: * With the hexagon points={TOP, UPPER-RIGHT, LOWER-RIGHT, BOTTOM, LOWER-LEFT, UPPER-RIGHT} * size = length of each actual segment of the hexagon * width = bounding rectangle width * height = bounding rectangle height * each inner angle is 120 degrees * outside angles are 30-60-90 triangles with 30 near TOP and BOTTOM and 60 near sides * hOffset = height difference between 'size' edge and bounding rectangle corners * wOffset = width difference between TOP/BOTTOM points and bounding rectangle corners */ double thirtyDegrees = Math.toRadians(30); hOffset = Math.sin(thirtyDegrees) * size; wOffset = Math.cos(thirtyDegrees) * size; height = (2 * hOffset) + size; width = (2 * wOffset); double left = center.getX() - (width / 2); double right = center.getX() + (width / 2); double top = center.getY() - (height / 2); double bottom = center.getY() + (height / 2); boundingBox = new Rectangle2D.Double(left, top, width, height); boundingCorners = new HashMap<BoundingCorner, Point2D>(); boundingCorners.put(BoundingCorner.TopRight, new Point2D.Double(right, top)); boundingCorners.put(BoundingCorner.TopLeft, new Point2D.Double(left, top)); boundingCorners.put(BoundingCorner.BottomRight, new Point2D.Double(right, bottom)); boundingCorners.put(BoundingCorner.BottomLeft, new Point2D.Double(left, bottom)); corners = new HashMap<Corner, Point2D>(); corners.put(Corner.Top, new Point2D.Double(center.getX(), top)); corners.put(Corner.UpperRight, new Point2D.Double(right, (top + hOffset))); corners.put(Corner.LowerRight, new Point2D.Double(right, (bottom - hOffset))); corners.put(Corner.Bottom, new Point2D.Double(center.getX(), bottom)); corners.put(Corner.LowerLeft, new Point2D.Double(left, (bottom - hOffset))); corners.put(Corner.UpperLeft, new Point2D.Double(left, (top + hOffset))); for (Corner corner : Corner.values()) { Point2D p2d = corners.get(corner); addPoint((int) p2d.getX(), (int) p2d.getY()); } }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.loc.Geolocation.java
/** * Returns the great circle distance in kilometers between this {@link Geolocation} and the * specified location//from ww w .j a v a2 s . co m * * @param other * @return the great circle distance in km */ public double getDistanceFrom(final Geolocation other) { if (other != null) { final double dLat = Math.toRadians(getLatitude() - other.getLatitude()); final double dLon = Math.toRadians(getLongitude() - other.getLongitude()); final double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) + (Math.cos(Math.toRadians(getLatitude())) * Math.cos(Math.toRadians(other.getLatitude())) * Math.sin(dLon / 2) * Math.sin(dLon / 2)); final double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return MEAN_EARTH_RADIUS * c; } else { return Double.POSITIVE_INFINITY; } }
From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.Invoke.java
/** * process : Do : Paint the specified XObject (section 4.7). * @param operator The operator that is being executed. * @param arguments List//from w w w. j a v a 2s . c o m * @throws java.io.IOException If there is an error invoking the sub object. */ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context; PDPage page = drawer.getPage(); COSName objectName = (COSName) arguments.get(0); Map xobjects = drawer.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 { image.setGraphicsState(drawer.getGraphicsState()); 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 = drawer.getPageSize().getHeight(); log.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight); Matrix ctm = drawer.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); drawer.drawImage(awtImage, ctmAT); } catch (Exception e) { e.printStackTrace(); 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 invoke = (COSStream) form.getCOSObject(); PDResources pdResources = form.getResources(); if (pdResources == null) { pdResources = page.findResources(); } // 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); } getContext().processSubStream(page, pdResources, invoke); // restore the graphics state context.setGraphicsState((PDGraphicsState) context.getGraphicsStack().pop()); } }
From source file:com.crs4.roodin.moduletester.CustomView.java
/** * @param canvas// w ww . j a va 2 s.c om */ private void drawRadar(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.RED); paint.setAlpha(100); float rotation = currentRotation; //gRotationZ_deg + initialMapRotation; for (int i = -35; i < 35; i = i + 2) { float arrowX1 = (float) (translateX - Math.sin(Math.toRadians(rotation + i)) * 45); float arrowY1 = (float) (translateY - Math.cos(Math.toRadians(rotation + i)) * 45); canvas.drawLine(translateX, translateY, arrowX1, arrowY1, paint); } paint.setAlpha(100); paint.setColor(Color.RED); canvas.drawCircle(translateX, translateY, 7, paint); paint.setColor(Color.YELLOW); canvas.drawCircle(translateX, translateY, 6, paint); paint.setColor(Color.RED); canvas.drawCircle(translateX, translateY, 1, paint); }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static double[] calculateReferenceArc(double angle) { double a = (angle / 180 * Math.PI) / 2.0; double x0 = Math.cos(a); double y0 = Math.sin(a); double x1 = (4 - x0) / 3; double y1 = (1 - x0) * (3 - x0) / (3 * y0); double x2 = x1; double y2 = -y1; double x3 = x0; double y3 = -y0; return new double[] { x0, y0, x1, y1, x2, y2, x3, y3 }; }
From source file:io.github.malapert.jwcs.coordsystem.Utility.java
/** * Calculates the matrix that represents a 3d rotation around the Y axis. * * Reference: //from ww w . j av a 2s. c om * ---------- * 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 Y axis. */ public final static RealMatrix rotY(double angle) { double angleRadians = Math.toRadians(angle); double[][] array = { { Math.cos(angleRadians), 0.d, -1 * Math.sin(angleRadians) }, { 0.d, 1.d, 0.d }, { Math.sin(angleRadians), 0.d, Math.cos(angleRadians) } }; return MatrixUtils.createRealMatrix(array); }
From source file:com.ccxt.whl.utils.CommonUtils.java
/** * ??(?)?/* w ww . j av a 2 s .co m*/ * * @param long1 * ? * @param lat1 * * @param long2 * ? * @param lat2 * * @return ? ?? */ public static double Distance(double long1, double lat1, double long2, double lat2) { double a, b, R; R = 6378137; // ?? lat1 = lat1 * Math.PI / 180.0; lat2 = lat2 * Math.PI / 180.0; a = lat1 - lat2; b = (long1 - long2) * Math.PI / 180.0; double d; double sa2, sb2; sa2 = Math.sin(a / 2.0); sb2 = Math.sin(b / 2.0); d = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2)); return d; }
From source file:de.mfo.jsurf.grid.RotationGrid.java
protected static void setOptimalCameraDistance(Camera c) { float cameraDistance; switch (c.getCameraType()) { case ORTHOGRAPHIC_CAMERA: cameraDistance = 1.0f;/*from w ww . j a va 2 s .co m*/ break; case PERSPECTIVE_CAMERA: cameraDistance = (float) (1.0 / Math.sin((Math.PI / 180.0) * (c.getFoVY() / 2.0))); break; default: throw new RuntimeException(); } c.lookAt(new Point3d(0, 0, cameraDistance), new Point3d(0, 0, -1), new Vector3d(0, 1, 0)); }
From source file:org.jfree.chart.demo.SampleXYDataset.java
/** * Returns the y-value for the specified series and item. Series are numbered 0, 1, ... * * @param series the index (zero-based) of the series. * @param item the index (zero-based) of the required item. * * @return the y-value for the specified series and item. *//*w ww .ja v a 2s .co m*/ public double getYValue(final int series, final int item) { if (series == 0) { return new Double(Math.cos(-10.0 + this.translate + (item / 10.0))).doubleValue(); } else { return new Double(2 * (Math.sin(-10.0 + this.translate + (item / 10.0)))).doubleValue(); } }
From source file:gedi.util.math.stat.distributions.PoissonBinomial.java
private void preprocess() { int n = pp.length; m = n + 1;//from w ww. j av a 2s . co m int nextPowerOf2 = Integer.highestOneBit(m); if (nextPowerOf2 != m) nextPowerOf2 <<= 1; m = nextPowerOf2; n = m - 1; int ins = 0; int start = 0; for (int i = 1; i < pp.length; i++) { if (Math.abs(pp[i] - pp[start]) > 1E-10) { if (i - start > 1) { double p = pp[start]; pp[ins++] = -(i - start); pp[ins++] = p; } else { pp[ins++] = pp[i - 1]; } start = i; } } if (pp.length - start > 1) { double p = pp[start]; pp[ins++] = -(pp.length - start); pp[ins++] = p; } else { pp[ins++] = pp[pp.length - 1]; } double delta = 2 * Math.PI / m; z = new Complex[m]; z[0] = new Complex(1, 0); for (int i = 1; i <= Math.ceil(n / 2.0); i++) { double tt = i * delta; // for(int j=0;j<pp.length;j++) // { // double pj=j<opp.length?opp[j]:0; // double ax=1-pj+pj*Math.cos(tt); // double bx=pj*Math.sin(tt); // double tmp1=Math.sqrt(ax*ax+bx*bx); // double tmp2=Math.atan2(bx,ax); //atan2(x,y) // c1o+=Math.log(tmp1); // c2o+=tmp2; // } double c1 = 0.00; double c2 = 0.00; for (int j = 0; j < ins; j++) { double pj = pp[j]; double f = 1; if (pj < 0) { f = -pj; pj = pp[++j]; } double ax = 1 - pj + pj * Math.cos(tt); double bx = pj * Math.sin(tt); double tmp1 = Math.sqrt(ax * ax + bx * bx); double tmp2 = Math.atan2(bx, ax); //atan2(x,y) c1 += Math.log(tmp1) * f; c2 += tmp2 * f; } z[i] = new Complex(Math.exp(c1) * Math.cos(c2), Math.exp(c1) * Math.sin(c2)); z[z.length - i] = z[i].conjugate(); } FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD); z = fft.transform(z, TransformType.FORWARD); }