List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:Main.java
public static byte[] createSoundDataInByteArray(int bufferSamples, final int sampleRate, final double frequency, double sweep) { final double rad = 2 * Math.PI * frequency / sampleRate; byte[] vai = new byte[bufferSamples]; sweep = Math.PI * sweep / ((double) sampleRate * vai.length); for (int j = 0; j < vai.length; j++) { int unsigned = (int) (Math.sin(j * (rad + j * sweep)) * Byte.MAX_VALUE) + Byte.MAX_VALUE & 0xFF; vai[j] = (byte) unsigned; }//from w w w . ja va2s . com return vai; }
From source file:Main.java
public static double getGeoDistance(double longitude1, double latitude1, double longitude2, double latitude2) { double EARTH_RADIUS = 6378137; double radLat1 = rad(latitude1); double radLat2 = rad(latitude2); double a = radLat1 - radLat2; double b = rad(longitude1) - rad(longitude2); 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))); s = s * EARTH_RADIUS;//from w w w . j a va 2 s. c o m s = Math.round(s * 10000) / 10000; return s; }
From source file:Main.java
public static float[] getRotationFromGyro(float[] values, float timestamp, float nowTimeStamp, float[] currentRotMatrix, boolean swapX, boolean swapY, boolean swapZ) { float[] deltaRotationVector = new float[4]; if (timestamp != 0) { final float dT = (nowTimeStamp - timestamp) * NS2S; float axisX = swapX ? -values[0] : values[0]; float axisY = swapY ? -values[1] : values[1]; float axisZ = swapZ ? -values[2] : values[2]; float omegaMagnitude = (float) Math.sqrt(axisX * axisX + axisY * axisY + axisZ * axisZ); if (omegaMagnitude > 0.1f) { axisX /= omegaMagnitude;/*from w w w . j av a 2s. c o m*/ axisY /= omegaMagnitude; axisZ /= omegaMagnitude; } float thetaOverTwo = omegaMagnitude * dT / 2.0f; float sinThetaOverTwo = (float) Math.sin(thetaOverTwo); float cosThetaOverTwo = (float) Math.cos(thetaOverTwo); deltaRotationVector[0] = sinThetaOverTwo * axisX; deltaRotationVector[1] = sinThetaOverTwo * axisY; deltaRotationVector[2] = sinThetaOverTwo * axisZ; deltaRotationVector[3] = cosThetaOverTwo; } float[] deltaRotationMatrix = new float[16]; SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector); return naivMatrixMultiply(currentRotMatrix, deltaRotationMatrix); }
From source file:Main.java
public static Bitmap rotateAndFrame(Bitmap bitmap) { final boolean positive = sRandom.nextFloat() >= 0.5f; final float angle = (ROTATION_ANGLE_MIN + sRandom.nextFloat() * ROTATION_ANGLE_EXTRA) * (positive ? 1.0f : -1.0f); final double radAngle = Math.toRadians(angle); final int bitmapWidth = bitmap.getWidth(); final int bitmapHeight = bitmap.getHeight(); final double cosAngle = Math.abs(Math.cos(radAngle)); final double sinAngle = Math.abs(Math.sin(radAngle)); final int strokedWidth = (int) (bitmapWidth + 2 * PHOTO_BORDER_WIDTH); final int strokedHeight = (int) (bitmapHeight + 2 * PHOTO_BORDER_WIDTH); final int width = (int) (strokedHeight * sinAngle + strokedWidth * cosAngle); final int height = (int) (strokedWidth * sinAngle + strokedHeight * cosAngle); final float x = (width - bitmapWidth) / 2.0f; final float y = (height - bitmapHeight) / 2.0f; final Bitmap decored = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(decored); canvas.rotate(angle, width / 2.0f, height / 2.0f); canvas.drawBitmap(bitmap, x, y, sPaint); canvas.drawRect(x, y, x + bitmapWidth, y + bitmapHeight, sStrokePaint); return decored; }
From source file:Main.java
/** * Get the coordinates of a point on the line by cut length. * * @param A Point A/*from ww w .jav a 2 s . c om*/ * @param B Point B * @param cutLength cut length * @return the point. */ public static Point getPointByCutLength(Point A, Point B, int cutLength) { float radian = getRadian(A, B); return new Point(A.x + (int) (cutLength * Math.cos(radian)), A.y + (int) (cutLength * Math.sin(radian))); }
From source file:Main.java
public static double[] wgs84togcj02(double lng, double lat) { if (out_of_china(lng, lat)) { return new double[] { lng, lat }; }/* ww w .j a v a 2 s .co m*/ double dlat = transformlat(lng - 105.0, lat - 35.0); double dlng = transformlng(lng - 105.0, lat - 35.0); double radlat = lat / 180.0 * pi; double magic = Math.sin(radlat); magic = 1 - ee * magic * magic; double sqrtmagic = Math.sqrt(magic); dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi); dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * pi); double mglat = lat + dlat; double mglng = lng + dlng; return new double[] { mglng, mglat }; }
From source file:Main.java
public static double accurateDistanceMeters(double lat1, double lng1, double lat2, double lng2) { double dlat = Math.sin(0.5 * (lat2 - lat1)); double dlng = Math.sin(0.5 * (lng2 - lng1)); double x = dlat * dlat + dlng * dlng * Math.cos(lat1) * Math.cos(lat2); return (2 * Math.atan2(Math.sqrt(x), Math.sqrt(Math.max(0.0, 1.0 - x)))) * EARTH_RADIUS_METERS; }
From source file:Main.java
/** * Calculate the difference between true solar time and mean. The "equation * of time" is a term accounting for changes in the time of solar noon for * a given location over the course of a year. Earth's elliptical orbit and * Kepler's law of equal areas in equal times are the culprits behind this * phenomenon. See the//from ww w . java 2 s .c om * <A HREF="http://www.analemma.com/Pages/framesPage.html">Analemma page</A>. * Below is a plot of the equation of time versus the day of the year. * * <P align="center"><img src="doc-files/EquationOfTime.png"></P> * * @param t number of Julian centuries since J2000. * @return Equation of time in minutes of time. */ private static double equationOfTime(final double t) { double eps = Math.toRadians(obliquityCorrected(t)); double l0 = Math.toRadians(sunGeometricMeanLongitude(t)); double m = Math.toRadians(sunGeometricMeanAnomaly(t)); double e = eccentricityEarthOrbit(t); double y = Math.tan(eps / 2); y *= y; double sin2l0 = Math.sin(2 * l0); double cos2l0 = Math.cos(2 * l0); double sin4l0 = Math.sin(4 * l0); double sin1m = Math.sin(m); double sin2m = Math.sin(2 * m); double etime = y * sin2l0 - 2 * e * sin1m + 4 * e * y * sin1m * cos2l0 - 0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m; return Math.toDegrees(etime) * 4.0; }
From source file:Main.java
/** * Special crop of bitmap rotated by not stright angle, in this case the original crop bitmap contains parts * beyond the required crop area, this method crops the already cropped and rotated bitmap to the final * rectangle.<br>/* www . j av a2s . c om*/ * Note: rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping. */ private static Bitmap cropForRotatedImage(Bitmap bitmap, float[] points, Rect rect, int degreesRotated, boolean fixAspectRatio, int aspectRatioX, int aspectRatioY) { if (degreesRotated % 90 != 0) { int adjLeft = 0, adjTop = 0, width = 0, height = 0; double rads = Math.toRadians(degreesRotated); int compareTo = degreesRotated < 90 || (degreesRotated > 180 && degreesRotated < 270) ? rect.left : rect.right; for (int i = 0; i < points.length; i += 2) { if (points[i] >= compareTo - 1 && points[i] <= compareTo + 1) { adjLeft = (int) Math.abs(Math.sin(rads) * (rect.bottom - points[i + 1])); adjTop = (int) Math.abs(Math.cos(rads) * (points[i + 1] - rect.top)); width = (int) Math.abs((points[i + 1] - rect.top) / Math.sin(rads)); height = (int) Math.abs((rect.bottom - points[i + 1]) / Math.cos(rads)); break; } } rect.set(adjLeft, adjTop, adjLeft + width, adjTop + height); if (fixAspectRatio) { fixRectForAspectRatio(rect, aspectRatioX, aspectRatioY); } Bitmap bitmapTmp = bitmap; bitmap = Bitmap.createBitmap(bitmap, rect.left, rect.top, rect.width(), rect.height()); if (bitmapTmp != bitmap) { bitmapTmp.recycle(); } } return bitmap; }
From source file:Main.java
private static byte generateSample(int step, float freq, int samplingRate) { double phase4 = calcPhase(step, freq * 0.08f, samplingRate); return (byte) (60 * (Math.sin(phase4))); }