List of usage examples for java.lang Math asin
public static double asin(double a)
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
/** * Internal implementation to add an image (a world map, though other image data is also fine) to a slide. * Preserves the original image's aspect ratio, leaving blank space below and to the sides of the image. * @param slide the slide to add to.// www. j ava 2 s . c o m * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates. * @param picture the picture data. * @param markers an array of markers to draw over the map. * @param polygons * @return the picture shape object added to the slide. */ private static XSLFPictureShape addMap(final XSLFSlide slide, final Rectangle2D.Double anchor, final XSLFPictureData picture, final Marker[] markers, final MapData.Polygon[] polygons) { double tgtW = anchor.getWidth(), tgtH = anchor.getHeight(); final Dimension size = picture.getImageDimension(); final double ratio = size.getWidth() / size.getHeight(); if (ratio > tgtW / tgtH) { // source image is wider than target, clip fixed width variable height tgtH = tgtW / ratio; } else { tgtW = tgtH * ratio; } final XSLFPictureShape canvas = slide.createPicture(picture); // Vertically align top, horizontally-align center final double offsetX = anchor.getMinX() + 0.5 * (anchor.getWidth() - tgtW), offsetY = anchor.getMinY(); canvas.setAnchor(new Rectangle2D.Double(offsetX, offsetY, tgtW, tgtH)); if (polygons != null) { for (MapData.Polygon polygon : polygons) { final Color color = Color.decode(polygon.getColor()); final double[][] shapes = polygon.getPoints(); // The ESRI spec version 1.2.1 from http://www.opengeospatial.org/standards/sfa has section 6.1.11.1, // which defines polygons as follows: /// A Polygon is a planar Surface defined by 1 exterior boundary and 0 or more interior boundaries. // Each interior boundary defines a hole in the Polygon. A Triangle is a polygon with 3 distinct, // non-collinear vertices and no interior boundary. /// The exterior boundary LinearRing defines the top? of the surface which is the side of the surface // from which the exterior boundary appears to traverse the boundary in a counter clockwise direction. // The interior LinearRings will have the opposite orientation, and appear as clockwise // when viewed from the top? // so it's even-odd winding (whereas the Path2D default is non-zero-winding). final Path2D.Double path = new Path2D.Double(Path2D.WIND_EVEN_ODD); for (final double[] points : shapes) { for (int ii = 0; ii < points.length; ii += 2) { final double x1 = offsetX + points[ii] * tgtW; final double y1 = offsetY + points[ii + 1] * tgtH; if (ii == 0) { path.moveTo(x1, y1); } else { path.lineTo(x1, y1); } } path.closePath(); } final XSLFFreeformShape freeform = slide.createFreeform(); freeform.setPath(path); freeform.setStrokeStyle(0.5); // There's a 0.5 alpha transparency on the stroke, and a 0.2 alpha transparency on the polygon fill. freeform.setLineColor(transparentColor(color, 128)); freeform.setFillColor(transparentColor(color, 51)); if (StringUtils.isNotEmpty(polygon.getText())) { final PackageRelationship rel = freeform.getSheet().getPackagePart().addRelationship( slide.getPackagePart().getPartName(), TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation()); // We create a hyperlink which links back to this slide; so we get hover-over-detail-text on the polygon final CTHyperlink link = ((CTShape) freeform.getXmlObject()).getNvSpPr().getCNvPr() .addNewHlinkClick(); link.setTooltip(polygon.getText()); link.setId(rel.getId()); link.setAction("ppaction://hlinksldjump"); } } } for (Marker marker : markers) { final Color color = Color.decode(marker.getColor()); final double centerX = offsetX + marker.getX() * tgtW; final double centerY = offsetY + marker.getY() * tgtH; if (marker.isCluster()) { final XSLFGroupShape group = slide.createGroup(); double halfMark = 10; double mark = halfMark * 2; double innerHalfMark = 7; double innerMark = innerHalfMark * 2; // align these so the middle is the latlng position final Rectangle2D.Double groupAnchor = new Rectangle2D.Double(centerX - halfMark, centerY - halfMark, mark, mark); group.setAnchor(groupAnchor); group.setInteriorAnchor(groupAnchor); final XSLFAutoShape shape = group.createAutoShape(); shape.setShapeType(ShapeType.ELLIPSE); final boolean fade = marker.isFade(); // There's a 0.3 alpha transparency (255 * 0.3 is 76) when a marker is faded out final int FADE_ALPHA = 76; shape.setFillColor(transparentColor(color, fade ? 47 : 154)); shape.setAnchor(groupAnchor); final XSLFAutoShape inner = group.createAutoShape(); inner.setFillColor(fade ? transparentColor(color, FADE_ALPHA) : color); inner.setLineWidth(0.1); inner.setLineColor(new Color((int) (color.getRed() * 0.9), (int) (color.getGreen() * 0.9), (int) (color.getBlue() * 0.9), fade ? FADE_ALPHA : 255)); inner.setShapeType(ShapeType.ELLIPSE); inner.setHorizontalCentered(true); inner.setWordWrap(false); inner.setVerticalAlignment(VerticalAlignment.MIDDLE); inner.clearText(); final XSLFTextParagraph para = inner.addNewTextParagraph(); para.setTextAlign(TextParagraph.TextAlign.CENTER); final XSLFTextRun text = para.addNewTextRun(); text.setFontSize(6.0); final Color fontColor = Color.decode(StringUtils.defaultString(marker.getFontColor(), "#000000")); text.setFontColor(fade ? transparentColor(fontColor, FADE_ALPHA) : fontColor); text.setText(marker.getText()); inner.setAnchor(new Rectangle2D.Double(centerX - innerHalfMark, centerY - innerHalfMark, innerMark, innerMark)); } else { final XSLFGroupShape group = slide.createGroup(); final XSLFFreeformShape shape = group.createFreeform(); shape.setHorizontalCentered(true); shape.setWordWrap(false); shape.setVerticalAlignment(VerticalAlignment.BOTTOM); shape.setLineWidth(0.5); shape.setLineColor(color.darker()); shape.setFillColor(transparentColor(color, 210)); final double halfMark = 8, mark = halfMark * 2, extension = 0.85, markerHeight = (0.5 + extension) * mark, angle = Math.asin(0.5 / extension) * 180 / Math.PI; // Set group position group.setAnchor( new Rectangle2D.Double(centerX - halfMark, centerY - markerHeight, mark, markerHeight)); group.setInteriorAnchor(new Rectangle2D.Double(0, 0, mark, markerHeight)); // Draw a semicircle and a triangle to represent the marker, pointing at the precise x,y location final Path2D.Double path = new Path2D.Double(); path.moveTo(halfMark, markerHeight); path.append(new Arc2D.Double(0, 0, mark, mark, -angle, 180 + angle + angle, Arc2D.OPEN), true); path.lineTo(halfMark, markerHeight); shape.setPath(path); shape.setAnchor(new Rectangle2D.Double(0, 0, mark, markerHeight)); final XSLFAutoShape disc = group.createAutoShape(); disc.setShapeType(ShapeType.DONUT); final double discRadius = 0.25 * mark; final double discDiameter = 2 * discRadius; disc.setAnchor(new Rectangle2D.Double(halfMark - discRadius, halfMark - discRadius, discDiameter, discDiameter)); disc.setFillColor(Color.WHITE); disc.setLineColor(Color.WHITE); if (StringUtils.isNotEmpty(marker.getText())) { final PackageRelationship rel = shape.getSheet().getPackagePart().addRelationship( slide.getPackagePart().getPartName(), TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation()); // We create a hyperlink which links back to this slide; so we get hover-over-detail-text on the marker // Annoyingly, you can't put a link on the group, just on the individual shapes. for (XSLFShape clickable : group.getShapes()) { final CTHyperlink link = ((CTShape) clickable.getXmlObject()).getNvSpPr().getCNvPr() .addNewHlinkClick(); link.setTooltip(marker.getText()); link.setId(rel.getId()); link.setAction("ppaction://hlinksldjump"); } } } } return canvas; }
From source file:io.doist.datetimepicker.time.RadialTimePickerView.java
private int getDegreesFromXY(float x, float y) { final double hypotenuse = Math.sqrt((y - mYCenter) * (y - mYCenter) + (x - mXCenter) * (x - mXCenter)); // Basic check if we're outside the range of the disk if (hypotenuse > mCircleRadius[HOURS]) { return -1; }//from w w w . jav a 2 s. c o m // Check if (mIs24HourMode && mShowHours) { if (hypotenuse >= mMinHypotenuseForInnerNumber && hypotenuse <= mHalfwayHypotenusePoint) { mIsOnInnerCircle = true; } else if (hypotenuse <= mMaxHypotenuseForOuterNumber && hypotenuse >= mHalfwayHypotenusePoint) { mIsOnInnerCircle = false; } else { return -1; } } else { final int index = (mShowHours) ? HOURS : MINUTES; final float length = (mCircleRadius[index] * mNumbersRadiusMultiplier[index]); final int distanceToNumber = (int) Math.abs(hypotenuse - length); final int maxAllowedDistance = (int) (mCircleRadius[index] * (1 - mNumbersRadiusMultiplier[index])); if (distanceToNumber > maxAllowedDistance) { return -1; } } final float opposite = Math.abs(y - mYCenter); int degrees = (int) (Math.toDegrees(Math.asin(opposite / hypotenuse)) + 0.5); // Now we have to translate to the correct quadrant. final boolean rightSide = (x > mXCenter); final boolean topSide = (y < mYCenter); if (rightSide) { if (topSide) { degrees = 90 - degrees; } else { degrees = 90 + degrees; } } else { if (topSide) { degrees = 270 + degrees; } else { degrees = 270 - degrees; } } return degrees; }
From source file:Rotation.java
/** Get the elevation of the vector. * @return elevation (δ) of the vector, between -π/2 and +π/2 * @see #Vector3D(double, double)// w w w. j av a 2 s.com */ public double getDelta() { return Math.asin(z / getNorm()); }
From source file:TransformExplorer.java
private void updateAxisTransform() { // We need to rotate the axis, which is defined along the y-axis, // to the direction indicated by the rotAxis. // We can do this using a neat trick. To transform a vector to align // with another vector (assuming both vectors have unit length), take // the cross product the the vectors. The direction of the cross // product is the axis, and the length of the cross product is the // the sine of the angle, so the inverse sine of the length gives // us the angle tmpVector.cross(yAxis, rotAxis);/*from www . j av a2s . co m*/ float angle = (float) Math.asin(tmpVector.length()); tmpAxisAngle.set(tmpVector, angle); tmpTrans.set(tmpAxisAngle); tmpTrans.setTranslation(refPt); axisTG.setTransform(tmpTrans); }
From source file:Rotation.java
/** Compute the angular separation between two vectors. * <p>This method computes the angular separation between two * vectors using the dot product for well separated vectors and the * cross product for almost aligned vectors. This allow to have a * good accuracy in all cases, even for vectors very close to each * other.</p>/*from w w w. jav a 2 s . co m*/ * @param v1 first vector * @param v2 second vector * @return angular separation between v1 and v2 * @exception ArithmeticException if either vector has a null norm */ public static double angle(Vector3D v1, Vector3D v2) { double normProduct = v1.getNorm() * v2.getNorm(); if (normProduct == 0) { throw new ArithmeticException("null norm"); } double dot = dotProduct(v1, v2); double threshold = normProduct * 0.9999; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine Vector3D v3 = crossProduct(v1, v2); if (dot >= 0) { return Math.asin(v3.getNorm() / normProduct); } return Math.PI - Math.asin(v3.getNorm() / normProduct); } // the vectors are sufficiently separated to use the cosine return Math.acos(dot / normProduct); }
From source file:com.mitre.holdshort.MainActivity.java
public Point futurePoint(Double lat, Double lon) { // Convert old lat/long to radians double oldLat = lat * Math.PI / 180; double oldLon = lon * Math.PI / 180; /*/*from w w w .j a v a 2 s . co m*/ * Get distance (in radians) based on current speed and Threshold * Distance = Speed * Time Speed is in knots (nm/h) Threshold is in * seconds so it will need to be converted into hours (divide by 3600). */ double distance = (currentSpd * (threshold / 3600)) * (Math.PI / (180 * 60)); // Convert current heading to radians double radial = (360 - currentHdg) * (Math.PI / 180); /* * Get new lat/lon using formula from * http://williams.best.vwh.net/avform.htm */ double newLat = Math.asin( Math.sin(oldLat) * Math.cos(distance) + Math.cos(oldLat) * Math.sin(distance) * Math.cos(radial)); double newLon; if (Math.cos(newLat) == 0) { newLon = oldLon; // endpoint a pole } else { double y = oldLon - Math.asin(Math.sin(radial) * Math.sin(distance) / Math.cos(newLat)) + Math.PI; double x = 2 * Math.PI; newLon = (y - x * Math.floor(y / x)) - Math.PI; } // Convert new lat/lon back to degrees newLat = newLat * 180 / Math.PI; newLon = newLon * 180 / Math.PI; // Create new point Point futurePoint = new Point(newLat, newLon); // Return futurePoint point return futurePoint; }
From source file:com.processing.core.PApplet.java
static public final float asin(float value) { return (float) Math.asin(value); }
From source file:com.example.sensingapp.SensingApp.java
public String calculateRot(String sAccl, String sGravity) { String sResult = "0,0"; String[] sarrAccl = null;/*www .j ava 2 s.co m*/ String[] sarrGravity = null; if ((sAccl.length() > 3) && (sGravity.length() > 3)) { sarrAccl = sAccl.split(","); sarrGravity = sGravity.split(","); double fAcclX = Double.valueOf(sarrAccl[0]).doubleValue(); double fAcclY = Double.valueOf(sarrAccl[1]).doubleValue(); double fGravityX = Double.valueOf(sarrGravity[0]).doubleValue(); double fGravityY = Double.valueOf(sarrGravity[1]).doubleValue(); double alpha, beta; if (fGravityX > 0) { alpha = Math.asin(fAcclX / fGravityX) / Math.PI * 180; } else { alpha = 0; } if (fGravityY > 0) { beta = Math.asin(fAcclY / fGravityY) / Math.PI * 180; } else { beta = 0; } sResult = alpha + " ," + beta; } return sResult; }
From source file:carnero.cgeo.cgBase.java
public static Double getHeading(Double lat1, Double lon1, Double lat2, Double lon2) { Double result = new Double(0); int ilat1 = (int) Math.round(0.5 + lat1 * 360000); int ilon1 = (int) Math.round(0.5 + lon1 * 360000); int ilat2 = (int) Math.round(0.5 + lat2 * 360000); int ilon2 = (int) Math.round(0.5 + lon2 * 360000); lat1 *= deg2rad;//from w w w. ja v a 2 s . c o m lon1 *= deg2rad; lat2 *= deg2rad; lon2 *= deg2rad; if (ilat1 == ilat2 && ilon1 == ilon2) { return new Double(result); } else if (ilat1 == ilat2) { if (ilon1 > ilon2) { result = new Double(270); } else { result = new Double(90); } } else if (ilon1 == ilon2) { if (ilat1 > ilat2) { result = new Double(180); } } else { Double c = Math.acos( Math.sin(lat2) * Math.sin(lat1) + Math.cos(lat2) * Math.cos(lat1) * Math.cos(lon2 - lon1)); Double A = Math.asin(Math.cos(lat2) * Math.sin(lon2 - lon1) / Math.sin(c)); result = new Double(A * rad2deg); if (ilat2 > ilat1 && ilon2 > ilon1) { // result don't need change } else if (ilat2 < ilat1 && ilon2 < ilon1) { result = 180f - result; } else if (ilat2 < ilat1 && ilon2 > ilon1) { result = 180f - result; } else if (ilat2 > ilat1 && ilon2 < ilon1) { result += 360f; } } return result; }
From source file:carnero.cgeo.cgBase.java
public HashMap<String, Double> getRadialDistance(Double latitude, Double longitude, Double bearing, Double distance) {/*from w w w . j av a2s.c o m*/ final Double rlat1 = latitude * deg2rad; final Double rlon1 = longitude * deg2rad; final Double rbearing = bearing * deg2rad; final Double rdistance = distance / erad; final Double rlat = Math.asin( Math.sin(rlat1) * Math.cos(rdistance) + Math.cos(rlat1) * Math.sin(rdistance) * Math.cos(rbearing)); final Double rlon = rlon1 + Math.atan2(Math.sin(rbearing) * Math.sin(rdistance) * Math.cos(rlat1), Math.cos(rdistance) - Math.sin(rlat1) * Math.sin(rlat)); HashMap<String, Double> result = new HashMap<String, Double>(); result.put("latitude", rlat * rad2deg); result.put("longitude", rlon * rad2deg); return result; }