List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:org.scilla.converter.JAIConverter.java
/** * Rotate image./*from www .j a v a 2s .co m*/ * @param img source image * @param val rotation description; format: <tt>D+X+Y</tt> * @return result image */ PlanarImage rotate(PlanarImage img, String val) { // determine degrees double d = 0; int p1 = val.indexOf('+'); if (p1 == -1) { d = Double.parseDouble(val); } else { d = Double.parseDouble(val.substring(0, p1)); } // determine rotation point float x = 0; float y = 0; int p2 = val.indexOf('+', p1 + 1); if (p1 == -1) { x = img.getWidth() / 2; y = img.getHeight() / 2; } else if (p2 == -1) { x = Float.parseFloat(val.substring(p1 + 1)); y = x; } else { x = Float.parseFloat(val.substring(p1 + 1, p2)); y = Float.parseFloat(val.substring(p2 + 1)); } if (log.isDebugEnabled()) { log.debug("rotate " + d + "+" + x + "+" + y); } ParameterBlock pars = new ParameterBlock(); pars.addSource(img); pars.add(x); pars.add(y); pars.add((float) Math.toRadians(d)); return JAI.create("rotate", pars); }
From source file:org.kalypsodeegree_impl.graphics.displayelements.LabelFactory.java
private Label[] createSurfaceLabels(final Feature feature, final String caption, final GM_Object geometry, final Font font, final Color color, final LineMetrics metrics, final Dimension bounds) throws GM_Exception, FilterEvaluationException { // use placement information from SLD final PointPlacement pPlacement = getPointPlacement(); final GM_Object geometryForLabel = adjustSurfaceGeometry(pPlacement, geometry); // get screen coordinates final int[] coords = LabelUtils.calcScreenCoordinates(m_projection, geometryForLabel); final int x = coords[0]; final int y = coords[1]; final double rotation = getRotation(pPlacement, feature); final double[] anchorPoint = getAnchor(pPlacement, feature, DEFAULT_LINE_ANCHOR); final double[] displacement = getDisplacement(pPlacement, feature); final Label label = createLabel(caption, font, color, metrics, feature, x, y, bounds, Math.toRadians(rotation), anchorPoint, displacement); return new Label[] { label }; }
From source file:com.ctsim.dmi.MainFrame.java
private void drawPin() { //double speed = 100 * (double) x / 1013; String speedShow = df.format(App.speed); int strWidth; AffineTransform restore = g2.getTransform(); AffineTransform trans = new AffineTransform(); trans.translate(266, 90);/*from w w w . ja va 2s .c o m*/ trans.rotate(Math.toRadians(getPinAngle(App.speed)), 40, 165); g2.setTransform(trans); g2.drawImage(speedoPinWhite, 0, 0, this); g2.setTransform(restore); // Draw actual speed g2.setFont(new Font("Loma", Font.BOLD, 30)); g2.setColor(Color.BLACK); FontMetrics metrics = g2.getFontMetrics(); strWidth = metrics.stringWidth(speedShow); g2.drawString(String.valueOf(speedShow), 306 - strWidth / 2, 265); }
From source file:VASSAL.counters.Labeler.java
public void draw(Graphics g, int x, int y, Component obs, double zoom) { updateCachedImage();/* www .j a v a2 s .c o m*/ piece.draw(g, x, y, obs, zoom); // FIXME: We should be drawing the text at the right size, not scaling it! final Point p = getLabelPosition(); final int labelX = x + (int) (zoom * p.x); final int labelY = y + (int) (zoom * p.y); AffineTransform saveXForm = null; final Graphics2D g2d = (Graphics2D) g; if (rotateDegrees != 0) { saveXForm = g2d.getTransform(); final AffineTransform newXForm = AffineTransform.getRotateInstance(Math.toRadians(rotateDegrees), x, y); g2d.transform(newXForm); } imagePainter.draw(g, labelX, labelY, zoom, obs); if (rotateDegrees != 0) { g2d.setTransform(saveXForm); } }
From source file:Matrix.java
/** * Create a vertical rotation matrix (vertical rotation is around a (1, 0, 0) axis). * @param angle the angle of the rotation * @return the matrix//from w w w. j a v a 2s. c o m */ public static float[] matrixRotateVertical(float angle) { if (angle == 0f) return matrixIdentity(); angle = (float) Math.toRadians(angle); float cos = (float) java.lang.Math.cos(angle); float sin = (float) java.lang.Math.sin(angle); float[] m2 = { 1f, 0f, 0f, 0f, 0f, cos, sin, 0f, 0f, -sin, cos, 0f, 0f, 0f, 0f, 1f }; return m2; }
From source file:TransformExplorer.java
void updateConeAxisAngle() { coneRotateAxisAngle.set(coneRotateNAxis, (float) Math.toRadians(coneRotateAngle)); }
From source file:com.seekret.data.flickr.FlickrRequestHandler.java
/** * This method generates satelites around a given spot. Attention, using * this method for requests to flickr, we can get problems with write/read * operations and problems with the spot size ( > 1MB) concerning memcache. * /*from w ww .j av a2 s. com*/ * @param spot * given Spot. * @param allPoints * Map of Points with spotradius. */ @SuppressWarnings("unused") private void createSatelitesArroundGivenSpot(Spot spot, HashMap<LatLng, Double> allPoints) { for (int degree = 0; degree < 316; degree += 45) { double d = spot.getSpotRadiusInKm() + (spot.getSpotRadiusInKm() / 2.0); System.out.println("Distance = " + d); double dist = d / 6371.0; double brng = Math.toRadians(degree); double lat1 = Math.toRadians(spot.getLatitude()); double lon1 = Math.toRadians(spot.getLongitude()); double lat2 = Math .asin(Math.sin(lat1) * Math.cos(dist) + Math.cos(lat1) * Math.sin(dist) * Math.cos(brng)); double a = Math.atan2(Math.sin(brng) * Math.sin(dist) * Math.cos(lat1), Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2)); System.out.println("a = " + a); double lon2 = lon1 + a; lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI; double latitude2 = Math.toDegrees(lat2); double longitude2 = Math.toDegrees(lon2); System.out.println("Latitude = " + latitude2 + "\nLongitude = " + longitude2); LatLng origin = new LatLng(spot.getLatitude(), spot.getLongitude()); LatLng newPoint = new LatLng(latitude2, longitude2); log.log(Level.INFO, "DISTANCE TO CENTER " + (LatLngTool.distance(origin, newPoint, LengthUnit.KILOMETER))); allPoints.put(newPoint, Double.valueOf(spot.getSpotRadiusInKm() / 2.0)); } }
From source file:Matrix.java
/** * Vertically rotate a matrix (vertical rotation is around a (1, 0, 0) axis). * @param angle the angle of the rotation * @param m the matrix to rotate//from w w w . j av a 2 s . co m * @return the resulting matrix */ public static float[] matrixRotateVertical(float[] m, float angle) { if (angle == 0f) return matrixIdentity(); angle = (float) Math.toRadians(angle); float cos = (float) java.lang.Math.cos(angle); float sin = (float) java.lang.Math.sin(angle); float r[] = new float[16]; r[0] = m[0]; r[4] = m[4]; r[8] = m[8]; r[12] = m[12]; r[1] = m[1] * cos - m[2] * sin; r[5] = m[5] * cos - m[6] * sin; r[9] = m[9] * cos - m[10] * sin; r[13] = m[13] * cos - m[14] * sin; r[2] = m[1] * sin + m[2] * cos; r[6] = m[5] * sin + m[6] * cos; r[10] = m[9] * sin + m[10] * cos; r[14] = m[13] * sin + m[14] * cos; r[3] = 0; r[7] = 0; r[11] = 0; r[15] = 1; return r; // return matrixMultiply(matrixRotateVertical(angle), m); }
From source file:io.github.malapert.jwcs.JWcs.java
/** * Computes CD matrix from CDELT[] and CROTA. * * * The computation is realized as follows: * <pre>/*from ww w . j a va 2 s . co m*/ * cos0 = cos(crota) * sin0 = sin(crota) * cd11 = cdelt1 * cos0 * cd12 = abs(cdelt2) * signum(cdelt1) * sin0 * cd21 = -abs(cdelt1) * signum(cdelt2) * sin0; * cd22 = cdelt2 * cos0; * </pre> * * @param cdelt increment of position * @param crota rotation * @return the cd matrix as array */ protected static final double[][] computeCdFromCdelt(double[] cdelt, double crota) { final double cos0 = Math.cos(Math.toRadians(crota)); final double sin0 = Math.sin(Math.toRadians(crota)); double cd11 = cdelt[0] * cos0; double cd12 = Math.abs(cdelt[1]) * Math.signum(cdelt[0]) * sin0; double cd21 = -Math.abs(cdelt[0]) * Math.signum(cdelt[1]) * sin0; double cd22 = cdelt[1] * cos0; double[][] array = { { cd11, cd12 }, { cd21, cd22 } }; return array; }
From source file:com.google.example.maps.roadsapi.MainActivity.java
private double distance(SnappedPoint sp1, SnappedPoint sp2) { final int R = 6371; double lat1, lat2, lon1, lon2; LatLng p1 = sp1.location;//w w w . jav a 2s .c o m LatLng p2 = sp2.location; lat1 = p1.lat; lat2 = p2.lng; lon1 = p1.lat; lon2 = p2.lng; Double latDistance = Math.toRadians(lat2 - lat1); Double lonDistance = Math.toRadians(lon2 - lon1); Double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2); Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = R * c * 1000; // convert to meters return distance; }