List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:ro.nextreports.designer.util.ImageUtil.java
private static Dimension computeShadowPosition(double angle, int distance) { double angleRadians = Math.toRadians(angle); int distance_x = (int) (Math.cos(angleRadians) * distance); int distance_y = (int) (Math.sin(angleRadians) * distance); return new Dimension(distance_x, distance_y); }
From source file:Matrix.java
/** * Create a lateral rotation matrix (lateral rotation is around a (0, 1, 0) axis). * @param angle the angle of the rotation * @return the matrix/*w w w .j a v a2 s. c o m*/ */ public static float[] matrixRotateLateral(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 = { cos, 0f, -sin, 0f, 0f, 1f, 0f, 0f, sin, 0f, cos, 0f, 0f, 0f, 0f, 1f }; return m2; }
From source file:com.net2plan.libraries.GraphUtils.java
/** Computes the Haversine distance between two points, that is, the shortest distance over the Earth's surface. * /*w ww . j av a 2s. co m*/ * <p><b>Important</b>: It is assumed an Earth's radius equal to {@link com.net2plan.utils.Constants#EARTH_RADIUS_IN_KM Constants.EARTH_RADIUS_IN_KM }</p> * * <p><b>Important</b>: Coordinates are assumed to be given in degress, conversions to radians are made internally.</p> * * @param point1 Point 1 (x-coord is equal to longitude, y-coord is equal to latitude) * @param point2 Point 2 (x-coord is equal to longitude, y-coord is equal to latitude) * @return Haversine distance between two points * @see <a href="http://www.movable-type.co.uk/scripts/latlong.html">Calculate distance, bearing and more between Latitude/Longitude points</a> */ public static double computeHaversineDistanceInKm(Point2D point1, Point2D point2) { double lon1 = point1.getX(); double lat1 = point1.getY(); double lon2 = point2.getX(); double lat2 = point2.getY(); double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); double sindLat = Math.sin(dLat / 2); double sindLon = Math.sin(dLon / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLon, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return Constants.EARTH_RADIUS_IN_KM * c; }
From source file:com.xfzbd.cqi.widget.srl.ShyaringanProgressDrawable.java
float getMinProgressArc(Shyaringan ring) { return (float) Math.toRadians(ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius())); }
From source file:net.mceoin.cominghome.LocationService.java
/** * Calculate distance in meters between two points. * * @param lat1 Latitude for point 1//from w ww .j a va 2 s.com * @param lng1 Longitude for point 1 * @param lat2 Latitude for point 2 * @param lng2 Longitude for point 2 * @return distance in meters */ public static float distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; int meterConversion = 1609; return (float) (dist * meterConversion); }
From source file:magma.agent.worldmodel.impl.GlobalMap.java
/** * @param perception the object containing the result from parsing * //from w ww . jav a 2 s .c o m */ private void calculatePosition(IPerception perception) { HashMap<String, ILocalizationFlag> flags = new HashMap<String, ILocalizationFlag>(); IHingeJointPerceptor neckYaw = perception.getHingeJointPerceptor(HINGEJOINT_PERCEPTORS[0]); IHingeJointPerceptor neckPitch = perception.getHingeJointPerceptor(HINGEJOINT_PERCEPTORS[1]); Vector3D gyroVector = perception.getGyroRatePerceptor(GYRORATE_PERCEPTORS[0]).getGyro(); float neckYawAngle = 0.0f; if (neckYaw != null) { neckYawAngle = neckYaw.getAxis(); } neckYawAngle = (float) Math.toRadians(neckYawAngle); float neckPitchAngle = 0.0f; if (neckPitch != null) { neckPitchAngle = neckPitch.getAxis(); } neckPitchAngle = (float) Math.toRadians(neckPitchAngle); int i = 0; for (String name : LANDMARK_NAMES) { IVisibleObjectPerceptor landmarkSeen = perception.getObject(name); if (landmarkSeen != null) { Landmark landmark = (Landmark) landmarks.get(name); // add the new flag into the array flags.put(name, landmark); } i++; } PositionOrientation localizeInfo; try { localizeInfo = localizer.localize(flags, neckYawAngle, neckPitchAngle, gyroVector); } catch (RuntimeException e) { logger.log(Level.SEVERE, "Localization problem {0}", e); return; } if (localizeInfo != null) { // TODO may be we want to filter once sensors have noise thisPlayer.setPosition(localizeInfo.getPosition()); // TODO add view angle direction(s) thisPlayer.setHorizontalAngle(localizeInfo.getOrientationX()); } }
From source file:org.geolatte.maprenderer.sld.graphics.ExternalGraphicsRepository.java
private BufferedImage rotate(BufferedImage img, float rotation) { AffineTransform tx = new AffineTransform(); //determine center point of image int sx = img.getMinX() + img.getWidth() / 2; int sy = img.getMinY() + img.getHeight() / 2; double theta = Math.toRadians(rotation); tx.rotate(theta, sx, sy);/* w w w. ja v a 2s . co m*/ AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); return op.filter(img, null); }
From source file:com.eyekabob.util.EyekabobHelper.java
/** * Gets distance from current location to given lat/lon. * @param lat// www. j av a 2s. com * @param lon * @param context * @return */ public static long getDistance(double lat, double lon, Context context) { Location location = EyekabobHelper.getLocation(context); if (location == null) { return -1; } double currentLat = location.getLatitude(); double currentLon = location.getLongitude(); int R = 3959; // Earth radius in miles. double dLat = Math.toRadians(currentLat - lat); double dLon = Math.toRadians(currentLon - lon); lat = Math.toRadians(lat); currentLat = Math.toRadians(currentLat); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat) * Math.cos(currentLat); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return Math.round(R * c); }
From source file:com.buzz.buzzdata.MongoBuzz.java
public double haversine(double lat1, double lng1, double lat2, double lng2) { double r = 6371 / 1.6; // average radius of the earth in miles double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lng2 - lng1); 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)); double d = r * c; return round(d, 1); }
From source file:com.kadavelil.jossy.mapalarm.SeekArc.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec); final int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec); final int min = Math.min(width, height); float top = 0; float left = 0; int arcDiameter = 0; mTranslateX = (int) (width * 0.5f); mTranslateY = (int) (height * 0.5f); arcDiameter = min - getPaddingLeft(); mArcRadius = arcDiameter / 2;//from w w w . j a v a 2 s. c o m top = height / 2 - (arcDiameter / 2); left = width / 2 - (arcDiameter / 2); mArcRect.set(left, top, left + arcDiameter, top + arcDiameter); int arcStart = (int) mProgressSweep + mStartAngle + mRotation + 90; mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(arcStart))); mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(arcStart))); setTouchInSide(mTouchInside); super.onMeasure(widthMeasureSpec, heightMeasureSpec); }