List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:org.eclipse.swt.snippets.Snippet195.java
static void drawTorus(float r, float R, int nsides, int rings) { float ringDelta = 2.0f * (float) Math.PI / rings; float sideDelta = 2.0f * (float) Math.PI / nsides; float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f; for (int i = rings - 1; i >= 0; i--) { float theta1 = theta + ringDelta; float cosTheta1 = (float) Math.cos(theta1); float sinTheta1 = (float) Math.sin(theta1); GL11.glBegin(GL11.GL_QUAD_STRIP); float phi = 0.0f; for (int j = nsides; j >= 0; j--) { phi += sideDelta;//from ww w . j av a2 s.com float cosPhi = (float) Math.cos(phi); float sinPhi = (float) Math.sin(phi); float dist = R + r * cosPhi; GL11.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); GL11.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); GL11.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); GL11.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); } GL11.glEnd(); theta = theta1; cosTheta = cosTheta1; sinTheta = sinTheta1; } }
From source file:Main.java
/** * Gets the relative bearing from one geographical coordinate to another. * * @param latitude1 the latitude of the source point * @param longitude1 the longitude of the source point * @param latitude2 the latitude of the destination point * @param longitude2 the longitude of the destination point * @return the relative bearing from point 1 to point 2, in degrees. The result is guaranteed * to fall in the range 0-360/*from w ww . j av a 2 s .co m*/ */ public static float getBearing(double latitude1, double longitude1, double latitude2, double longitude2) { latitude1 = Math.toRadians(latitude1); longitude1 = Math.toRadians(longitude1); latitude2 = Math.toRadians(latitude2); longitude2 = Math.toRadians(longitude2); double dLon = longitude2 - longitude1; double y = Math.sin(dLon) * Math.cos(latitude2); double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(dLon); double bearing = Math.atan2(y, x); return mod((float) Math.toDegrees(bearing), 360.0f); }
From source file:org.eclipse.swt.snippets.Snippet209.java
static void drawTorus(GL gl, float r, float R, int nsides, int rings) { float ringDelta = 2.0f * (float) Math.PI / rings; float sideDelta = 2.0f * (float) Math.PI / nsides; float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f; for (int i = rings - 1; i >= 0; i--) { float theta1 = theta + ringDelta; float cosTheta1 = (float) Math.cos(theta1); float sinTheta1 = (float) Math.sin(theta1); gl.glBegin(GL.GL_QUAD_STRIP);/*from www . j a va 2 s .co m*/ float phi = 0.0f; for (int j = nsides; j >= 0; j--) { phi += sideDelta; float cosPhi = (float) Math.cos(phi); float sinPhi = (float) Math.sin(phi); float dist = R + r * cosPhi; gl.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); gl.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); gl.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); gl.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); } gl.glEnd(); theta = theta1; cosTheta = cosTheta1; sinTheta = sinTheta1; } }
From source file:com.jennifer.ui.util.MathUtil.java
public static double rotateY(double x, double y, double radian) { return x * Math.sin(radian) + y * Math.cos(radian); }
From source file:Main.java
double gCos(double y) { return Math.cos(y); }
From source file:Main.java
public static double[] findClosePointsForDrawingArc(int x1, int x2, int y1, int y2) { double[] xy = new double[2]; double d = 5; double angle = 0; // if ((x1 - x2) != 0) { // tan a = y2-y1/x2-x1 // System.out.println(" x1 = " + x1 + " y1 = " + y1 + " | x2 = " + x2 + " | y2 = " + y2); // angle = Math.toDegrees(Math.atan2(Math.abs(y1 - y2), Math.abs(x1 - x2))); // xy[0] = (Math.cos(angle) * d) + x2; // xy[1] = (Math.sin(angle) * d) + y2; // System.out.println("xt " + xy[0] + " yt " + xy[1] + " angel would be : " + angle + " and Different number : " + d); angle = Math.toDegrees(Math.atan2(Math.abs(y1 - y2), Math.abs(x1 - x2))); System.out.println("----------------------------------vvvvv----------------------------------------"); System.out.println(" "); System.out.println("x1 " + x1 + " y1 " + y1 + " | x2 " + x2 + " y2 " + y2); System.out.println("Math.abs(x1-x2)" + Math.abs(x1 - x2) + " | Math.abs(y1-y2) " + Math.abs(y1 - y2) + " | angel would be Math.toDegrees(Math.atan2(Math.abs(y1 - y2), Math.abs(x1 - x2))) : " + angle + " | Different number : " + d); if (x1 > x2) { if (y1 > y2) { System.out.println(//w ww. j a v a 2 s . com "x1>x2 && y1>y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 + (Math.abs(Math.cos(angle)) * d); System.out.println( "x1>x2 && y1>y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 + (Math.abs(Math.sin(angle)) * d); } else if (y1 < y2) { System.out.println( "x1>x2 && y1< y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 + (Math.abs(Math.cos(angle)) * d); System.out.println( "x1>x2 && y1< y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 - (Math.abs(Math.sin(angle)) * d); } else { System.out.println( "x1>x2 && y1 = y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 + (Math.abs(Math.cos(angle)) * d); System.out.println( "x1>x2 && y1 = y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2; } } else if (x1 < x2) { if (y1 > y2) { System.out.println( "x1<x2 && y1>y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 - (Math.abs(Math.cos(angle)) * d); System.out.println( "x1<x2 && y1>y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 + (Math.abs(Math.sin(angle)) * d); } else if (y1 < y2) { System.out.println( "x1<x2 && y1< y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 - (Math.abs(Math.cos(angle)) * d); System.out.println( "x1<x2 && y1< y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 - (Math.abs(Math.sin(angle)) * d); } else { System.out.println( "x1<x2 && y1 =y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 - (Math.abs(Math.cos(angle)) * d); System.out.println( "x1<x2 && y1 =y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2; } } else { if (y1 > y2) { System.out.println( "x1=x2 && y1>y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2; System.out.println( "x1=x2 && y1>y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 + (Math.abs(Math.sin(angle) * d)); } else if (y1 < y2) { System.out.println( "x1=x2 && y1< y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2; System.out.println( "x1=x2 && y1< y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 - (Math.abs(Math.sin(angle)) * d); } else { System.out.println( "x1=x2 && y1 =y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2; System.out.println( "x1=x2 && y1 =y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2; } } System.out.println(" X1 = " + x1 + " | X2 = " + x2 + " | Y1 = " + y1 + " | Y2 = " + y2 + " | X target = " + xy[0] + " | Y target = " + xy[1]); System.out.println(" "); System.out.println("--------------------------------^^^^----------------------------------------"); // } else { // if (y2 > y1) { // System.out.println("(x1 - x2) == 0 | X1 = " + x1 + " | X2 = " + x2 + " | Y1 = " + y1 + " | Y2 = " + y2 + " | X target = " + x1 + " | Y target = " + (y2 + ((y2 - y1) / 12))); // xy[0] = (x2); // xy[1] = y2 + ((y2 - y1) / 12); // } else { // System.out.println("(x1 - x2) == 0 | X1 = " + x1 + " | X2 = " + x2 + " | Y1 = " + y1 + " | Y2 = " + y2 + " | X target = " + x1 + " | Y target = " + (y2 - ((y2 - y1) / 12))); // xy[0] = (x2); // xy[1] = y2 - ((y2 - y1 )/ 12); // } // } return xy; }
From source file:Main.java
/** * <p>This routine calculates the distance between two points (given the * latitude/longitude of those points). It is being used to calculate * the distance between two locations.</p> * <p/>/*w w w .ja va 2 s . c o m*/ * <p>Definitions: South latitudes are negative, east longitudes are positive</p> * <p/> * <p>Passed to function: * <ul> * <li>lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees)</li> * <li>lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees)</li> * <li>unit = the unit you desire for results * <ul> * <li>where: 'M' is statute miles</li> * <li>'K' is kilometers (default) </li> * <li>'N' is nautical miles</li> * </ul> * </li> * </ul> * Worldwide cities and other features databases with latitude longitude * are available at http://www.geodatasource.com</p> * <p/> * <p>For enquiries, please contact sales@geodatasource.com</p> * <p>Official Web site: http://www.geodatasource.com</p> * <p>GeoDataSource.com (C) All Rights Reserved 2013</p> * * @param lat1 - latitude point 1 * @param lon1 - longitude point 1 * @param lat2 - latitude point 2 * @param lon2 - longitude point 2 * @param unit - unit of measure (M, K, N) * @return the distance between the two points */ public static final double distance(double lat1, double lon1, double lat2, double lon2, char unit) { double theta = lon1 - lon2; double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta)); dist = Math.acos(dist); dist = rad2deg(dist); dist = dist * 60 * 1.1515; if (unit == 'K') { dist = dist * 1.609344; } else if (unit == 'N') { dist = dist * 0.8684; } return (dist); }
From source file:Main.java
/** * Gets straighten matrix for the given bounds and degrees. *//* w w w .j ava 2 s.co m*/ public static void getStraightenMatrix(RectF bounds, float degrees, Matrix matrix) { matrix.reset(); if ((degrees != 0) && !bounds.isEmpty()) { float w = bounds.width() / 2; float h = bounds.height() / 2; float adjustAngle; if ((degrees < 0 && w > h) || (degrees > 0 && w <= h)) { // The top left point is the boundary. adjustAngle = (float) Math.atan(h / -w) + MATH_PI + degrees * DEGREES_TO_RADIAN; } else { // The top right point is the boundary. adjustAngle = (float) Math.atan(h / w) - MATH_PI + degrees * DEGREES_TO_RADIAN; } float radius = (float) Math.hypot(w, h); float scaleX = (float) Math.abs(radius * Math.cos(adjustAngle)) / w; float scaleY = (float) Math.abs(radius * Math.sin(adjustAngle)) / h; float scale = Math.max(scaleX, scaleY); postRotateMatrix(degrees, new RectF(bounds), matrix); matrix.postScale(scale, scale); } }
From source file:Main.java
/** * Gets the great circle distance in kilometers between two geographical points, using * the <a href="http://en.wikipedia.org/wiki/Haversine_formula">haversine formula</a>. * * @param latitude1 the latitude of the first point * @param longitude1 the longitude of the first point * @param latitude2 the latitude of the second point * @param longitude2 the longitude of the second point * @return the distance, in kilometers, between the two points *//* w w w. java 2s . c o m*/ public static float getDistance(double latitude1, double longitude1, double latitude2, double longitude2) { double dLat = Math.toRadians(latitude2 - latitude1); double dLon = Math.toRadians(longitude2 - longitude1); double lat1 = Math.toRadians(latitude1); double lat2 = Math.toRadians(latitude2); double sqrtHaversineLat = Math.sin(dLat / 2); double sqrtHaversineLon = Math.sin(dLon / 2); double a = sqrtHaversineLat * sqrtHaversineLat + sqrtHaversineLon * sqrtHaversineLon * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return (float) (EARTH_RADIUS_KM * c); }
From source file:Main.java
/************************************************************************************************************************************ This routine calculates the distance between two points (given the latitude/longitude of those points). It is being used to calculate the distance between two locations/*from w w w.j a v a 2 s.c o m*/ Definitions: South latitudes are negative, east longitudes are positive Passed to function: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) unit = the unit you desire for results where: 'M' is statute miles 'K' is kilometers (default) 'N' is nautical miles *************************************************************************************************************************************/ public static double Distance(double lat1, double lon1, double lat2, double lon2, String unit) { double radius = 6371.0090667; lat1 = lat1 * Math.PI / 180.0; lon1 = lon1 * Math.PI / 180.0; lat2 = lat2 * Math.PI / 180.0; lon2 = lon2 * Math.PI / 180.0; double dlon = lon1 - lon2; double distance = Math .acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(dlon)) * radius; if (unit == "K") { return distance; } else if (unit == "M") { return (distance * 0.621371192); } else if (unit == "F") { //FEET return ((distance * 0.621371192) * 5280); } else if (unit == "N") { return (distance * 0.539956803); } else { return 0; } }