List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:Main.java
public static void transformBaidu(double wgLat, double wgLon, double[] latlng) { double d[] = new double[2]; transform(wgLat, wgLon, d);//from w w w .j a v a 2s . c o m double x = d[1], y = d[0]; double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); latlng[1] = z * Math.cos(theta) + 0.0065; latlng[0] = z * Math.sin(theta) + 0.006; }
From source file:Main.java
/** * Calculates the position around a center point, depending on the distance * from the center, and the angle of the position around the center. * * @param center/*from w w w . j a v a 2 s. co m*/ * @param dist * @param angle in degrees, converted to radians internally * @return */ public static PointF getPosition(PointF center, float dist, float angle) { PointF p = new PointF((float) (center.x + dist * Math.cos(Math.toRadians(angle))), (float) (center.y + dist * Math.sin(Math.toRadians(angle)))); return p; }
From source file:Main.java
/** * generate a CW signal with the given properties * @param frequency the frequency//from w ww . j a v a 2 s. c o m * @param length sample length * @param amplitude maximum amplitude * @param sampleRate sample rate to use * @return data as double[] */ public static double[] generateSignal(double frequency, int length, double amplitude, double sampleRate) { double[] signal = new double[length]; for (int i = 0; i < length; i++) { signal[i] = amplitude * Math.sin(frequency * 2.0 * Math.PI * (i / sampleRate)); } return signal; }
From source file:Main.java
public static double gps2km(final double lat_a, final double lng_a, final double lat_b, final double lng_b) { if (!isGpsValid(lng_a, lat_a) || !isGpsValid(lng_b, lat_b)) { return -1; }//from w w w .ja v a 2 s. c om final double radLat1 = (lat_a * Math.PI / 180.0); final double radLat2 = (lat_b * Math.PI / 180.0); final double a = radLat1 - radLat2; final double b = (lng_a - lng_b) * Math.PI / 180.0; final double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); return s * EARTH_RADIUS; }
From source file:Main.java
public static double bearingBetween(Location startLocation, Location endLocation) { double lat1 = DegreesToRadians(startLocation.getLatitude()); double lon1 = DegreesToRadians(startLocation.getLongitude()); double lat2 = DegreesToRadians(endLocation.getLatitude()); double lon2 = DegreesToRadians(endLocation.getLongitude()); double dLon = lon2 - lon1; double y = Math.sin(dLon) * Math.cos(lat2); double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon); double radiansBearing = Math.atan2(y, x); return RadiansToDegrees(radiansBearing); }
From source file:Main.java
/** * Rotate a set of coordinates by a given angle * @param c_x//from w ww .ja v a2s .c o m * @param c_y * @param thetab * @param x * @param y * @return */ public static double[] rotateCoord(double c_x, double c_y, double thetab, double x, double y) { double prc_x = x - c_x; double prc_y = y - c_y; double r = Math.sqrt(prc_x * prc_x + prc_y * prc_y); double theta = Math.atan2(prc_y, prc_x); theta = theta + thetab * Math.PI / 180.0; double pc_x = r * Math.cos(theta); double pc_y = r * Math.sin(theta); double p[] = new double[2]; p[0] = pc_x + c_x; p[1] = pc_y + c_y; return p; }
From source file:Main.java
/** * Receives the Euler angles in radians and returns the components of the quaternion. * //from w w w . j a va 2 s . co m * @param x The x or phi axis in radians. * @param y The y axis or theta in radians. * @param z The z axis or psi in radians * @return A 4 positions array which contains the x, y, z and w in this order. */ public static final float[] eulerToQuaternion(float x, float y, float z) { float[] quaternion = new float[4]; quaternion[0] = (float) ((Math.cos(x / 2) * Math.cos(y / 2) * Math.cos(z / 2)) + (Math.sin(x / 2) * Math.sin(y / 2) * Math.sin(z / 2))); quaternion[1] = (float) ((Math.sin(x / 2) * Math.cos(y / 2) * Math.cos(z / 2)) - (Math.cos(x / 2) * Math.sin(y / 2) * Math.sin(z / 2))); quaternion[2] = (float) ((Math.cos(x / 2) * Math.sin(y / 2) * Math.cos(z / 2)) + (Math.sin(x / 2) * Math.cos(y / 2) * Math.sin(z / 2))); quaternion[3] = (float) ((Math.cos(x / 2) * Math.cos(y / 2) * Math.sin(z / 2)) - (Math.sin(x / 2) * Math.sin(y / 2) * Math.cos(z / 2))); return quaternion; }
From source file:Main.java
/** * Returns the bearing from one point to another. * @param latFrom The latitude of the point from * @param lonFrom The longitude of the point from * @param latTo The latitude of the point to * @param lonTo The longitude of the point to * @return the bearing from one point to another *//*from www .j a v a2s . com*/ private static double bearingTo(double latFrom, double lonFrom, double latTo, double lonTo) { double latitude1 = Math.toRadians(latFrom); double latitude2 = Math.toRadians(latTo); double longDiff = Math.toRadians(lonTo - lonFrom); double y = Math.sin(longDiff) * Math.cos(latitude2); double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff); return (Math.toDegrees(Math.atan2(y, x)) + 360) % 360; }
From source file:Main.java
public static double tile2lat(int y, int aZoom) { final double MerkElipsK = 0.0000001; final long sradiusa = 6378137; final long sradiusb = 6356752; final double FExct = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa; final int TilesAtZoom = 1 << aZoom; double result = (y - TilesAtZoom / 2) / -(TilesAtZoom / (2 * Math.PI)); result = (2 * Math.atan(Math.exp(result)) - Math.PI / 2) * 180 / Math.PI; double Zu = result / (180 / Math.PI); double yy = ((y) - TilesAtZoom / 2); double Zum1 = Zu; Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct)) / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI))) * Math.pow(1 + FExct * Math.sin(Zum1), FExct))); while (Math.abs(Zum1 - Zu) >= MerkElipsK) { Zum1 = Zu;/*from www .j a va 2s . co m*/ Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct)) / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI))) * Math.pow(1 + FExct * Math.sin(Zum1), FExct))); } result = Zu * 180 / Math.PI; return result; }
From source file:Main.java
static float computeCircleY(float r, float degrees) { return (float) (r * Math.sin(Math.toRadians(degrees))); }