List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:edu.oregonstate.eecs.mcplan.ml.KernelPrincipalComponentsAnalysis.java
public static void main(final String[] args) throws FileNotFoundException { final File root = new File("test/KernelPrincipalComponentsAnalysis"); root.mkdirs();/*from www . ja v a 2s. c o m*/ final int seed = 42; final int N = 30; final RandomGenerator rng = new MersenneTwister(seed); final ArrayList<RealVector> data = new ArrayList<RealVector>(); final ArrayList<RealVector> shuffled = new ArrayList<RealVector>(); // final double[][] covariance = new double[][] { {1.0, 0.0}, // {0.0, 1.0} }; // final MultivariateNormalDistribution p = new MultivariateNormalDistribution( // rng, new double[] { 0.0, 0.0 }, covariance ); // final MultivariateNormalDistribution q = new MultivariateNormalDistribution( // rng, new double[] { 10.0, 0.0 }, covariance ); // // for( int i = 0; i < N; ++i ) { // data.add( new ArrayRealVector( p.sample() ) ); // data.add( new ArrayRealVector( q.sample() ) ); // } // Fn.shuffle( rng, data ); final double sigma = 0.01; final double[][] covariance = new double[][] { { sigma, 0.0 }, { 0.0, sigma } }; final MultivariateNormalDistribution p = new MultivariateNormalDistribution(rng, new double[] { 0.0, 0.0 }, covariance); for (final double r : new double[] { 1.0, 3.0, 5.0 }) { for (int i = 0; i < N; ++i) { final double theta = i * 2 * Math.PI / N; final double[] noise = p.sample(); final RealVector v = new ArrayRealVector( new double[] { r * Math.cos(theta) + noise[0], r * Math.sin(theta) + noise[1] }); data.add(v); shuffled.add(v); } } Fn.shuffle(rng, shuffled); final Csv.Writer data_writer = new Csv.Writer(new PrintStream(new File(root, "data.csv"))); for (final RealVector v : data) { for (int i = 0; i < v.getDimension(); ++i) { data_writer.cell(v.getEntry(i)); } data_writer.newline(); } data_writer.close(); System.out.println("[Training]"); final int Ncomponents = 2; final KernelPrincipalComponentsAnalysis<RealVector> kpca = new KernelPrincipalComponentsAnalysis<RealVector>( shuffled, new RadialBasisFunctionKernel(0.5), 1e-6); System.out.println("[Finished]"); for (int i = 0; i < Ncomponents; ++i) { System.out.println(kpca.eigenvectors.get(i)); } System.out.println("Transformed data:"); final KernelPrincipalComponentsAnalysis.Transformer<RealVector> transformer = kpca .makeTransformer(Ncomponents); final Csv.Writer transformed_writer = new Csv.Writer(new PrintStream(new File(root, "transformed.csv"))); for (final RealVector u : data) { final RealVector v = transformer.transform(u); System.out.println(v); for (int i = 0; i < v.getDimension(); ++i) { transformed_writer.cell(v.getEntry(i)); } transformed_writer.newline(); } transformed_writer.close(); }
From source file:Main.java
public static PointF rotatePoint(PointF point, PointF centerPoint, float rotate) { float x = point.x; float y = point.y; float sinA = (float) Math.sin(Math.toRadians(rotate)); float cosA = (float) Math.cos(Math.toRadians(rotate)); float newX = centerPoint.x + (x - centerPoint.x) * cosA - (y - centerPoint.y) * sinA; float newY = centerPoint.y + (y - centerPoint.y) * cosA + (x - centerPoint.x) * sinA; return new PointF(newX, newY); }
From source file:Main.java
public static float[] position_on_circle(final float centerX, final float centerY, float pDegree, float pRadius) { double radian = (pDegree / 180) * Math.PI; float x = ((float) (centerX + Math.cos(radian) * pRadius));//-this.getWidth()/2; float y = ((float) (centerY - Math.sin(radian) * pRadius));//-this.getHeight()/2; return new float[] { x, y }; }
From source file:Main.java
public static double[] mercatorToGeo(double[] e) { double j = Math.PI, f = j / 2, i = 6378137, n = 0.003356551468879694, k = 0.00000657187271079536, h = 1.764564338702e-8, m = 5.328478445e-11; double g = f - 2 * Math.atan(1 / Math.exp(e[1] / i)); double l = g + n * Math.sin(2 * g) + k * Math.sin(4 * g) + h * Math.sin(6 * g) + m * Math.sin(8 * g); double d = e[0] / i; return new double[] { d * 180 / Math.PI, l * 180 / Math.PI }; }
From source file:Main.java
public static Double getDistance(double lat1, double lat2, double lon1, double lon2, double el1, double el2) { final int R = 6371; // Radius of the earth Double latDistance = Math.toRadians(lat2 - lat1); Double lonDistance = Math.toRadians(lon2 - lon1); Double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2); Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = R * c; // convert to meters double height = el1 - el2; distance = Math.pow(distance, 2) + Math.pow(height, 2); return Math.sqrt(distance); }
From source file:Main.java
public static long[] getTileFromGeo(double lat, double lon, int zoom) { double rLon, rLat, a, k, z; rLon = lon * Math.PI / 180;/*from w w w.ja va2s .co m*/ rLat = lat * Math.PI / 180; a = 6378137; k = 0.0818191908426; z = Math.pow(Math.tan(Math.PI / 4 + rLat / 2) / (Math.tan(Math.PI / 4 + Math.asin(k * Math.sin(rLat)) / 2)), k); return new long[] { (int) (((20037508.342789 + a * rLon) * 53.5865938 / Math.pow(2, (23 - zoom))) / 256), (int) (((20037508.342789 - a * Math.log(z)) * 53.5865938 / Math.pow(2, (23 - zoom)))) / 256 }; }
From source file:Main.java
private static double[] bdToGaoDe(double bd_lat, double bd_lon) { double[] gd_lat_lon = new double[2]; double PI = 3.1415926535897932384626 * 3000.0 / 180.0; double x = bd_lon - 0.0065, y = bd_lat - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * PI); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * PI); gd_lat_lon[0] = z * Math.cos(theta); gd_lat_lon[1] = z * Math.sin(theta); return gd_lat_lon; }
From source file:Main.java
public static double haversine(double lat1, double lon1, double lat2, double lon2) { final double R = 6372.8; // In kilometers double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); lat1 = Math.toRadians(lat1);/* w w w . j a v a2 s.c o m*/ lat2 = Math.toRadians(lat2); double a = Math.pow(Math.sin(dLat / 2), 2) + Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.asin(Math.sqrt(a)); return R * c; }
From source file:Main.java
/** * Calculates the distance between two locations in KM */// w w w.j a va 2s .co m public static double checkDistance(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 6371; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double sindLat = Math.sin(dLat / 2); double sindLng = Math.sin(dLng / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c * 1000; return dist; // in meter }
From source file:Main.java
public static double distance(double lat1, double lon1, double lat2, double lon2) { if (lat1 == lat2 && lon1 == lon2) { return 0; }/*from ww w .j a v a2s.c om*/ // haversine great circle distance approximation, returns meters 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)); if (dist > 1) { return 0; } dist = Math.acos(dist); dist = rad2deg(dist); dist = dist * 60; // 60 nautical miles per degree of separation dist = dist * 1852; // 1852 meters per nautical mile return dist / 1000; }