List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:AvatarTest.java
public TransformGroup addBehaviors(Group bgRoot) { // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D zAxis = new Transform3D(); zAxis.rotY(Math.toRadians(90.0)); Alpha zoomAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 20000, 0, 0, 0, 0, 0); PositionInterpolator posInt = new PositionInterpolator(zoomAlpha, objTrans, zAxis, 0, -160); posInt.setSchedulingBounds(getBoundingSphere()); objTrans.addChild(posInt);// w ww. j a v a 2s. co m bgRoot.addChild(objTrans); return objTrans; }
From source file:org.specvis.logic.Functions.java
/** * Calculate opposite of the angle.// www .j av a 2s. c om * @param a: angle in degrees; * @param r: * @return: Opposite of the angle; */ public double calculateOppositeAngle(double a, double r) { /** * Calculation note: * * |\ * |a\ * | \ * r| \ * | \ * | \ * |______\ * x * * In order to calculate "x" (opposite of the angle "a") one must do: * * x = r / cot(a), * * where "a" is in radians. Function "cot" can be also * described as "1/tan". */ double x; a = Math.toRadians(a); x = r / (1 / Math.tan(a)); return x; }
From source file:org.netxilia.functions.MathFunctions.java
public double RADIANS(double number) { return Math.toRadians(number); }
From source file:nz.co.fortytwo.signalk.handler.AISHandler.java
/** * Converts an AIS NMEA string to a signalK JSON object * See https://github.com/dma-ais/AisLib * /*from w w w . ja va2 s .co m*/ * HD-SF. Free raw AIS data feed for non-commercial use. * hd-sf.com:9009 * * @param bodyStr * @param device - the serial or other device the data was recieved over. * @return * @throws Exception */ public SignalKModel handle(String bodyStr, String device) throws Exception { if (logger.isDebugEnabled()) logger.debug("Processing AIS:" + bodyStr); if (StringUtils.isBlank(bodyStr) || !bodyStr.startsWith("!AIVDM")) { return null; } try { List<AisPacket> packets = handleLine(bodyStr); AisVesselInfo vInfo = null; SignalKModel model = SignalKModelFactory.getCleanInstance(); for (AisPacket packet : packets) { if (packet != null && packet.isValidMessage()) { // process message here AisMessage message = packet.getAisMessage(); if (logger.isDebugEnabled()) logger.debug("AisMessage:" + message.getClass() + ":" + message.toString()); // 1,2,3 if (message instanceof AisPositionMessage) { vInfo = new AisVesselInfo((AisPositionMessage) message); } // 5,19,24 if (message instanceof AisStaticCommon) { vInfo = new AisVesselInfo((AisStaticCommon) message); } if (message instanceof AisMessage18) { vInfo = new AisVesselInfo((AisMessage18) message); } if (vInfo != null) { if (StringUtils.isBlank(device)) device = "unknown"; String ts = Util.getIsoTimeString(packet.getBestTimestamp()); String aisVessel = vessels + dot + String.valueOf(vInfo.getUserId()) + dot; String sourceRef = aisVessel + "sources.ais"; //create ais source entry model.put(sourceRef + dot + value, packet.getStringMessage()); model.put(sourceRef + dot + timestamp, ts); model.put(sourceRef + dot + source, device); model.put(aisVessel + name, vInfo.getName()); model.put(aisVessel + mmsi, String.valueOf(vInfo.getUserId()), sourceRef, ts); model.put(aisVessel + nav_state, navStatusMap.get(vInfo.getNavStatus()), sourceRef, ts); if (vInfo.getPosition() != null) { model.put(aisVessel + nav_position + dot + timestamp, ts); model.put(aisVessel + nav_position + dot + source, sourceRef); model.put(aisVessel + nav_position_latitude, vInfo.getPosition().getLatitude()); model.put(aisVessel + nav_position_longitude, vInfo.getPosition().getLongitude()); } model.put(aisVessel + nav_courseOverGroundTrue, Math.toRadians(((double) vInfo.getCog()) / 10), sourceRef, ts); model.put(aisVessel + nav_speedOverGround, Util.kntToMs(((double) vInfo.getSog()) / 10), sourceRef, ts); model.put(aisVessel + nav_headingTrue, Math.toRadians(((double) vInfo.getTrueHeading()) / 10), sourceRef); if (vInfo.getCallsign() != null) model.put(aisVessel + communication_callsignVhf, vInfo.getCallsign(), sourceRef, ts); } } } return model; } catch (Exception e) { logger.debug(e.getMessage(), e); logger.error(e.getMessage() + " : " + bodyStr); throw e; } }
From source file:org.nuxeo.pdf.service.PDFTransformationServiceImpl.java
public Point2D computeTranslationVector(double pageWidth, double watermarkWidth, double pageHeight, double watermarkHeight, WatermarkProperties properties) { double xTranslation; double yTranslation; double xRotationOffset = 0; double yRotationOffset = 0; if (properties.getTextRotation() != 0) { Rectangle2D rectangle2D = new Rectangle2D.Double(0, -watermarkHeight, watermarkWidth, watermarkHeight); AffineTransform at = AffineTransform.getRotateInstance(-Math.toRadians(properties.getTextRotation()), 0, 0);/*from ww w . ja v a2 s . c o m*/ Shape shape = at.createTransformedShape(rectangle2D); Rectangle2D rotated = shape.getBounds2D(); watermarkWidth = rotated.getWidth(); if (!properties.isInvertX() || properties.isRelativeCoordinates()) { xRotationOffset = -rotated.getX(); } else { xRotationOffset = rotated.getX(); } watermarkHeight = rotated.getHeight(); if (!properties.isInvertY() || properties.isRelativeCoordinates()) { yRotationOffset = rotated.getY() + rotated.getHeight(); } else { yRotationOffset = -(rotated.getY() + rotated.getHeight()); } } if (properties.isRelativeCoordinates()) { xTranslation = (pageWidth - watermarkWidth) * properties.getxPosition() + xRotationOffset; yTranslation = (pageHeight - watermarkHeight) * properties.getyPosition() + yRotationOffset; } else { xTranslation = properties.getxPosition() + xRotationOffset; yTranslation = properties.getyPosition() + yRotationOffset; if (properties.isInvertX()) xTranslation = pageWidth - watermarkWidth - xTranslation; if (properties.isInvertY()) yTranslation = pageHeight - watermarkHeight - yTranslation; } return new Point2D.Double(xTranslation, yTranslation); }
From source file:pl.dp.bz.poid.fouriertest.FourierProc.java
public void computeEdgeDetectionFilter(int radiusExternal, int radiusInternal, int circleCenterX, int circleCenterY, double alpha1, double alpha2) { fourierImage = FourierProc.changeImageQuadrants(fourierImage); if (isCircleInImage(radiusExternal, circleCenterX, circleCenterY) && isCircleInImage(radiusInternal, circleCenterX, circleCenterY)) { for (int x = 0; x < imageWidth; x++) { for (int y = 0; y < imageHeight; y++) { if (x == imageWidth / 2 && y == imageHeight / 2) { continue; }/*w w w . ja va 2 s . c o m*/ if (computeDistance(circleCenterX, circleCenterY, x, y) > radiusExternal) { fourierImage[x][y] = new Complex(0, 0); } else if (computeDistance(circleCenterX, circleCenterY, x, y) < radiusInternal) { fourierImage[x][y] = new Complex(0, 0); } else { //Tutaj wycinanie tych kawakw //obliczamy x do ktrego trzeba double px = x - imageWidth / 2; double py = y - imageHeight / 2; double d = Math.sqrt(px * px + py * py); px /= d; py /= d; double aRad1 = Math.toRadians(alpha1); double aRad2 = Math.toRadians(alpha2); double a = Math.atan2(-py, -px) + Math.PI; double a2 = Math.atan2(py, px) + Math.PI; if ((aRad1 <= a && a <= aRad2) || (aRad1 <= a2 && a2 <= aRad2)) { fourierImage[x][y] = new Complex(0, 0); } } } } } fourierImage = FourierProc.changeImageQuadrants(fourierImage); }
From source file:TexCoordTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objPosition = new TransformGroup(); objPosition.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); TransformGroup objRotate = new TransformGroup(); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D axisTranslate = new Transform3D(); axisTranslate.rotZ(Math.toRadians(90)); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 6000, 0, 0, 0, 0, 0); m_PositionInterpolator = new PositionInterpolator(rotationAlpha, objPosition, axisTranslate, 0, 70); m_PositionInterpolator.setSchedulingBounds(createApplicationBounds()); objPosition.addChild(m_PositionInterpolator); m_PositionInterpolator.setEnable(false); m_RotationInterpolator = new RotationInterpolator(rotationAlpha, objRotate, new Transform3D(), 0.0f, (float) Math.PI * 2.0f); m_RotationInterpolator.setSchedulingBounds(getApplicationBounds()); objRotate.addChild(m_RotationInterpolator); m_RotationInterpolator.setEnable(true); TransformGroup tgLand = new TransformGroup(); Transform3D t3dLand = new Transform3D(); t3dLand.setTranslation(new Vector3d(0, -30, 0)); tgLand.setTransform(t3dLand);//www . ja v a 2s . c om tgLand.addChild(createDemLandscape()); objRotate.addChild(tgLand); objPosition.addChild(objRotate); objRoot.addChild(objPosition); // create some lights for the scene Color3f lColor1 = new Color3f(0.3f, 0.3f, 0.3f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(getApplicationBounds()); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(getApplicationBounds()); // add the lights to the parent BranchGroup objRoot.addChild(aLgt); objRoot.addChild(lgt1); return objRoot; }
From source file:com.alvermont.terraj.planet.project.MollweideProjection.java
/** * Carry out the projection// w w w.ja v a 2 s. 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(); cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; depth = (3 * ((int) (log2(scale * height)))) + 6; log.debug("MollweideProjection starting with depth set to " + depth); progress.progressStart(height, "Generating Terrain"); double x; double y; double y1; double zz; double scale1; double cos2; double theta1; double theta2; int i; int j; int i1 = 1; int k; for (j = 0; j < height; ++j) { progress.progressStep(j); y1 = (2 * ((2.0 * j) - height)) / width / scale; if (Math.abs(y1) >= 1.0) { for (i = 0; i < width; ++i) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } } else { zz = Math.sqrt(1.0 - (y1 * y1)); y = 2.0 / Math.PI * ((y1 * zz) + Math.asin(y1)); cos2 = Math.sqrt(1.0 - (y * 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 = (Math.PI / zz * ((2.0 * i) - width)) / width / scale; if (Math.abs(theta1) > Math.PI) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } else { theta1 += (lon - (0.5 * Math.PI)); colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2); if (doShade) { shades[i][j] = shade; } } } } } } progress.progressComplete("Terrain Generated"); log.debug("MollweideProjection complete"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -ProjectionConstants.RIGHT_ANGLE_DEGREES; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < ProjectionConstants.RIGHT_ANGLE_DEGREES; theta1 += hgrid) { theta2 = Math.abs(theta1); x = Math.floor(theta2 / 5.0); y = (theta2 / 5.0) - x; y = ((1.0 - y) * mollTable[(int) x]) + (y * mollTable[(int) x + 1]); if (theta1 < 0.0) { y = -y; } j = (height / 2) + (int) (0.25 * y * width * scale); if ((j >= 0) && (j < height)) { for (i = Math.max(0, (width / 2) - (int) (0.5 * width * scale * Math.sqrt(1.0 - (y * y)))); i < Math.min( width, (width / 2) + (int) (0.5 * width * scale * Math.sqrt(1.0 - (y * y)))); ++i) colours[i][j] = BLACK; } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = 0.0; theta1 > -ProjectionConstants.CIRCLE_DEGREES; theta1 -= vgrid) ; for (theta1 = theta1; theta1 < ProjectionConstants.CIRCLE_DEGREES; theta1 += vgrid) { if (((Math.toRadians(theta1) - lon + (0.5 * Math.PI)) > -Math.PI) && ((Math.toRadians(theta1) - lon + (0.5 * Math.PI)) <= Math.PI)) { x = (0.5 * (Math.toRadians(theta1) - lon + (0.5 * Math.PI)) * width * scale) / Math.PI; j = Math.max(0, (height / 2) - (int) (0.25 * width * scale)); y = (2 * ((2.0 * j) - height)) / width / scale; i = (int) ((width / 2) + (x * Math.sqrt(1.0 - (y * y)))); for (; j <= Math.min(height, (height / 2) + (int) (0.25 * width * scale)); ++j) { y1 = (2 * ((2.0 * j) - height)) / width / scale; if (Math.abs(y1) <= 1.0) { i1 = (int) ((width / 2) + (x * Math.sqrt(1.0 - (y1 * y1)))); if ((i1 >= 0) && (i1 < width)) { colours[i1][j] = BLACK; } } if (Math.abs(y) <= 1.0) { if (i < i1) { for (k = i + 1; k < i1; ++k) { if ((k > 00) && (k < width)) { colours[k][j] = BLACK; } } } else if (i > i1) { for (k = i - 1; k > i1; --k) { if ((k >= 0) && (k < width)) { colours[k][j] = BLACK; } } } } y = y1; i = i1; } } } } if (doShade) { smoothshades(); } doOutlining(); }
From source file:com.piusvelte.mosaic.android.MosaicMap.java
private double getOffsetLongitude(double lat, double lng, double offset) { return lng + Math.toDegrees(offset / (Mosaic.EARTH_RADIUS * Math.cos(Math.toRadians(lat)))); }
From source file:fr.certu.chouette.validation.checkpoint.AbstractValidation.java
/** * @see http://mathforum.org/library/drmath/view/51879.html *///from www .j a v a 2 s . c o m private double computeHaversineFormula(NeptuneLocalizedObject obj1, NeptuneLocalizedObject obj2) { double lon1 = Math.toRadians(obj1.getLongitude().doubleValue()); double lat1 = Math.toRadians(obj1.getLatitude().doubleValue()); double lon2 = Math.toRadians(obj2.getLongitude().doubleValue()); double lat2 = Math.toRadians(obj2.getLatitude().doubleValue()); final double R = 6371008.8; double dlon = lon2 - lon1; double dlat = lat2 - lat1; double a = Math.pow((Math.sin(dlat / 2)), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double d = R * c; return d; }