List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:Main.java
public static double GetDistance(double pLatitude1, double pLongitude1, double pLatitude2, double pLongitude2) { double vDist = Math.sin(deg2rad(pLatitude1)) * Math.sin(deg2rad(pLatitude2)) + Math.cos(deg2rad(pLatitude1)) * Math.cos(deg2rad(pLatitude2)) * Math.cos(deg2rad(pLongitude1 - pLongitude2)); vDist = Math.acos(vDist);// ww w . java 2s .c o m vDist = rad2deg(vDist); vDist = vDist * 111189.57696;// * 60 * 1.1515 * 1.609344 * 1000; return vDist; }
From source file:Main.java
public static double goertzel(double[] data, double freq, double sr) { double s_prev = 0; double s_prev2 = 0; double coeff = 2 * Math.cos((2 * Math.PI * freq) / sr); double s;//w w w. j av a 2 s .c om for (int i = 0; i < data.length; i++) { double sample = data[i]; s = sample + coeff * s_prev - s_prev2; s_prev2 = s_prev; s_prev = s; } double power = s_prev2 * s_prev2 + s_prev * s_prev - coeff * s_prev2 * s_prev; return power; }
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 Point getDirectionPoint(double bearing, Point posFrom, int length) { int x = (int) (Math.sin(bearing) * length); int y = (int) (Math.cos(bearing) * length); return new Point(posFrom.x + x, posFrom.y + y); }
From source file:Main.java
public static double smallestAngularDifferenceDegrees(double firstAngleDeg, double secondAngleDeg) { double d = ((firstAngleDeg - secondAngleDeg) * 3.141592653589793d) / 180.0d; return (Math.atan2(Math.sin(d), Math.cos(d)) * 180.0d) / 3.141592653589793d; }
From source file:Main.java
public static double distance(double lat1, double lon1, double lat2, double lon2) { Double theta = lon1 - lon2;/*w w w . java 2s . c om*/ 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; // M // dist = dist * 1.609344 * 1000; // m dist = dist * 1.609344; // km // dist = dist * 0.8684; //n return dist; }
From source file:Main.java
/** * Get a Hann window.//w ww . j a v a 2s.c om */ private static double[] hann(int windowWidth) { double[] envelopeArray = new double[windowWidth]; for (int i = 0; i < windowWidth; i++) { envelopeArray[i] = 0.5 * (1 - Math.cos(2 * Math.PI * i / windowWidth)); } return envelopeArray; }
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();/* ww w .j av a2 s. com*/ 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
private static float getX(double angle, double radius) { return (float) (Math.cos(angle + Math.PI / 2) * radius); }
From source file:Main.java
public static float getActionSpot(int _direction, int _distance, float _x, float _y, char _type, float _xOffset, float _yOffset) { // Palautetaan x- tai y-arvo _typen mukaan if (_type == 'x') { return _x + _xOffset + (float) Math.cos((_direction * Math.PI) / 180) * _distance; } else {//ww w . j a va2s .com return _y + _yOffset + (float) Math.sin((_direction * Math.PI) / 180) * _distance; } }