List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java
/** * Calculate length of the day for a specific day * /*from w w w. j a va 2s . c o m*/ * @param latitude * the latitude * @param day * the day * @return time in hours */ public double length(double latitude, int day) { final double p = Math .asin(.39795 * Math.cos(.2163108 + 2 * Math.atan(.9671396 * Math.tan(.00860 * (day - 186))))); return (24.0d - (24.0d / Math.PI) * Math .acos((Math.sin(0.8333d * Math.PI / 180d) + Math.sin(latitude * Math.PI / 180.0d) * Math.sin(p)) / (Math.cos(latitude * Math.PI / 180.0d) * Math.cos(p)))); }
From source file:edu.umn.cs.spatialHadoop.nasa.SpatioAggregateQueries.java
/** * Performs a spatio-temporal aggregate query on an indexed directory * @param inFile//from ww w . ja va2 s . c om * @param params * @throws ParseException * @throws IOException * @throws InterruptedException */ public static AggregateQuadTree.Node aggregateQuery(Path inFile, OperationsParams params) throws ParseException, IOException, InterruptedException { // 1- Find matching temporal partitions final FileSystem fs = inFile.getFileSystem(params); Vector<Path> matchingPartitions = selectTemporalPartitions(inFile, params); // 2- Find all matching files (AggregateQuadTrees) in matching partitions final Rectangle spatialRange = params.getShape("rect", new Rectangle()).getMBR(); // Convert spatialRange from lat/lng space to Sinusoidal space double cosPhiRad = Math.cos(spatialRange.y1 * Math.PI / 180); double southWest = spatialRange.x1 * cosPhiRad; double southEast = spatialRange.x2 * cosPhiRad; cosPhiRad = Math.cos(spatialRange.y2 * Math.PI / 180); double northWest = spatialRange.x1 * cosPhiRad; double northEast = spatialRange.x2 * cosPhiRad; spatialRange.x1 = Math.min(northWest, southWest); spatialRange.x2 = Math.max(northEast, southEast); // Convert to the h v space used by MODIS spatialRange.x1 = (spatialRange.x1 + 180.0) / 10.0; spatialRange.x2 = (spatialRange.x2 + 180.0) / 10.0; spatialRange.y2 = (90.0 - spatialRange.y2) / 10.0; spatialRange.y1 = (90.0 - spatialRange.y1) / 10.0; // Vertically flip because the Sinusoidal space increases to the south double tmp = spatialRange.y2; spatialRange.y2 = spatialRange.y1; spatialRange.y1 = tmp; // Find the range of cells in MODIS Sinusoidal grid overlapping the range final int h1 = (int) Math.floor(spatialRange.x1); final int h2 = (int) Math.ceil(spatialRange.x2); final int v1 = (int) Math.floor(spatialRange.y1); final int v2 = (int) Math.ceil(spatialRange.y2); PathFilter rangeFilter = new PathFilter() { @Override public boolean accept(Path p) { Matcher matcher = MODISTileID.matcher(p.getName()); if (!matcher.matches()) return false; int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); return h >= h1 && h < h2 && v >= v1 && v < v2; } }; final Vector<Path> allMatchingFiles = new Vector<Path>(); for (Path matchingPartition : matchingPartitions) { // Select all matching files FileStatus[] matchingFiles = fs.listStatus(matchingPartition, rangeFilter); for (FileStatus matchingFile : matchingFiles) { allMatchingFiles.add(matchingFile.getPath()); } } //noinspection SizeReplaceableByIsEmpty if (allMatchingFiles.isEmpty()) return null; final int resolution = AggregateQuadTree.getResolution(fs, allMatchingFiles.get(0)); // 3- Query all matching files in parallel List<Node> threadsResults = Parallel.forEach(allMatchingFiles.size(), new RunnableRange<AggregateQuadTree.Node>() { @Override public Node run(int i1, int i2) { Node threadResult = new AggregateQuadTree.Node(); for (int i_file = i1; i_file < i2; i_file++) { Path matchingFile = allMatchingFiles.get(i_file); try { Matcher matcher = MODISTileID.matcher(matchingFile.getName()); matcher.matches(); // It has to match int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); // Clip the query region and normalize in this tile Rectangle translated = spatialRange.translate(-h, -v); int x1 = (int) (Math.max(translated.x1, 0) * resolution); int y1 = (int) (Math.max(translated.y1, 0) * resolution); int x2 = (int) (Math.min(translated.x2, 1.0) * resolution); int y2 = (int) (Math.min(translated.y2, 1.0) * resolution); AggregateQuadTree.Node fileResult = AggregateQuadTree.aggregateQuery(fs, matchingFile, new java.awt.Rectangle(x1, y1, (x2 - x1), (y2 - y1))); threadResult.accumulate(fileResult); } catch (Exception e) { throw new RuntimeException("Error reading file " + matchingFile, e); } } return threadResult; } }); AggregateQuadTree.Node finalResult = new AggregateQuadTree.Node(); for (Node threadResult : threadsResults) { finalResult.accumulate(threadResult); } numOfTreesTouchesInLastRequest = allMatchingFiles.size(); return finalResult; }
From source file:dsp.unige.figures.ChannelHelper.java
/** * Returns the rain attenuation in dB given the state s, using procedure * from [1]. [1]. A prediction model that combines Rain Attenuation and * Other Propagation Impairments Along Earth- Satellinte Paths * // ww w. j av a 2 s.c o m * @param s * @return rain attenuation in dB. */ public static double getRainAttenuation(Station s) { // ==================== step 1 =========================== // calculate freezing height (in km) from the absolute value of station // latitude double hFr; if (s.stationLatitude >= 0 && s.stationLatitude < 23) hFr = 5.0d; else hFr = 5.0 - 0.075 * (s.stationLatitude - 23); // ==================== step 2 =========================== // calculate slant-path length Ls below the freezing height double Ls = (hFr - s.stationAltitude) / Math.sin(s.elevationAngle * Math.PI / 180); // ==================== step 3 =========================== // calculate horizontal projection Lg of the slant path length double Lg = Ls * Math.cos(s.elevationAngle * Math.PI / 180); // ==================== step 4 =========================== // obtain rain attenuation double gamma = s.getRainK() * Math.pow(s.R001, s.getRainAlpha()); // ==================== step 5 =========================== // calculate horizontal path adjustment double rh001 = 1 / (1 + 0.78 * Math.sqrt(Lg * gamma / s.frequency) - 0.38 * (1 - Math.exp(-2 * Lg))); // ==================== step 6 =========================== // calculate the adjusted rainy path length double ZETA = Math.atan((hFr - s.stationAltitude) / (Lg * rh001)); double Lr; if (ZETA > s.elevationAngle) { Lr = (Lg * rh001) / (Math.cos(s.elevationAngle * Math.PI / 180)); } else { Lr = (hFr - s.stationAltitude) / (Math.sin(s.elevationAngle * Math.PI / 180)); } // ==================== step 7 =========================== // calculate vertical path adjustment double CHI; if (Math.abs(s.elevationAngle) < 36) { CHI = 36 - s.elevationAngle; } else { CHI = 0; } double rv001 = 1 / (1 + Math.sqrt(Math.sin(s.elevationAngle * Math.PI / 180)) * (31 * (1 - Math.exp(-s.elevationAngle / (1 + CHI))) * (Math.sqrt(Lr * gamma) / Math.pow(s.frequency, 2)) - 0.45)); // ==================== step 8 =========================== // effective path length through rain double Le = Lr * rv001; // ==================== step 9 =========================== // get the attenuation exceded in 0.01% of average year time double A001 = gamma * Le; return A001; }
From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java
/** * // http://www.movable-type.co.uk/scripts/latlong.html * // Under Creative Commons License http://creativecommons.org/licenses/by/3.0/ * Calculate distance between two GPS co-ordinate * @param lat1//from w ww.j a v a 2s . c o m * @param lon1 * @param lat2 * @param lon2 * @return */ public static double getDistanceMeters(double lat1, double lon1, double lat2, double lon2) { int r = 6371; double dLat = Math.abs(lat2 - lat1) * (Math.PI / 180); double dLon = Math.abs(lon2 - lon1) * (Math.PI / 180); double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) + (Math.cos(lat1 * (Math.PI / 180)) * Math.cos(lat2 * (Math.PI / 180)) * Math.sin(dLon / 2) * Math.sin(dLon / 2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double d = r * c * 1000; // show as meters return Double.parseDouble(mDecimalFormat.format(d)); }
From source file:com.google.location.lbs.gnss.gps.pseudorange.Ecef2EnuConverter.java
/** * Computes a rotation matrix for converting a vector in Earth-Centered Earth-Fixed (ECEF) * Cartesian system into a vector in local east-north-up (ENU) Cartesian system with respect to * a reference location. The matrix has the following content: * * - sinLng cosLng 0 * - sinLat * cosLng - sinLat * sinLng cosLat * cosLat * cosLng cosLat * sinLng sinLat * * <p> Reference: Pratap Misra and Per Enge * "Global Positioning System: Signals, Measurements, and Performance" Page 137. * * @param refLat Latitude of reference location * @param refLng Longitude of reference location * @return the Ecef to Enu rotation matrix *//*from w w w .j a v a 2 s . c o m*/ public static RealMatrix getRotationMatrix(double refLat, double refLng) { RealMatrix rotationMatrix = new Array2DRowRealMatrix(3, 3); // Fill in the rotation Matrix rotationMatrix.setEntry(0, 0, -1 * Math.sin(refLng)); rotationMatrix.setEntry(1, 0, -1 * Math.cos(refLng) * Math.sin(refLat)); rotationMatrix.setEntry(2, 0, Math.cos(refLng) * Math.cos(refLat)); rotationMatrix.setEntry(0, 1, Math.cos(refLng)); rotationMatrix.setEntry(1, 1, -1 * Math.sin(refLat) * Math.sin(refLng)); rotationMatrix.setEntry(2, 1, Math.cos(refLat) * Math.sin(refLng)); rotationMatrix.setEntry(0, 2, 0); rotationMatrix.setEntry(1, 2, Math.cos(refLat)); rotationMatrix.setEntry(2, 2, Math.sin(refLat)); return rotationMatrix; }
From source file:com.opengamma.analytics.math.integration.GaussLegendreWeightAndAbscissaFunction.java
private double getInitialRootGuess(final int i, final int n) { return Math.cos(Math.PI * (i + 0.75) / (n + 0.5)); }
From source file:com.joey.software.dsp.HilbertTransform.java
public static void getHilbert(float[] reIn, float[] imIn, float[] reOut, float[] imOut) { float[] fftRe = new float[reIn.length]; float[] fftIm = new float[reIn.length]; FastFourierTransform3 fft = new FastFourierTransform3(reIn.length); fft.fft(reIn, imIn, fftRe, fftIm);/* w ww .j a v a 2 s. c o m*/ for (int n = 0; n < reIn.length; n++) { for (int k = 0; k < reIn.length; k++) { double val = 2 * Math.PI * k * n / reIn.length; reOut[k] += fftRe[k] * Math.sin(val) / reIn.length; imOut[k] += fftIm[k] * Math.cos(val) / reIn.length; } } }
From source file:controle.JfreeChartController.java
private DefaultCategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (double i = 0; i <= 10; i += 0.1) { dataset.addValue(Math.cos(Math.PI * i), "cosseno", Double.valueOf(i)); }/*from w ww . java 2 s .com*/ return dataset; }
From source file:org.honeybee.coderally.Modelt.java
@Override public void onTimeStep() { if (!gogogogo) return;/*from w w w . j av a 2s.c om*/ Point checkpoint = schewy.getMidPoint(getCar().getCheckpoint()); double heading = getCar().calculateHeading(checkpoint); double rotation; if (heading < 1) { rotation = -90; } else if (heading > 1) { rotation = 90; } else { rotation = 0; } Point position = getCar().getPosition(); double radians = getCar().getRotation().getRadians() - Math.PI / 2 + Math.toRadians(rotation); Point target = new Point(position.getX() + Math.cos(radians) * 500, position.getY() + Math.sin(radians) * 500); getCar().setTarget(target); slowForTightCorner(getCar()); }
From source file:org.elasticsoftware.elasticactors.geoevents.Coordinate.java
public double distance(final double latitude, final double longitude, LengthUnit unit) { double a = 6378137, b = 6356752.3142; // ellipsiod//from w w w . j a v a 2 s . c o m double L = (longitude - this.longitude) * degToRad; double U1 = Math.atan((1 - f) * Math.tan(this.latitude * degToRad)); double U2 = Math.atan((1 - f) * Math.tan(latitude * degToRad)); double sinU1 = Math.sin(U1), cosU1 = Math.cos(U1); double sinU2 = Math.sin(U2), cosU2 = Math.cos(U2); double cosSqAlpha, sinSigma, cos2SigmaM, cosSigma, sigma; double lambda = L, lambdaP, iterLimit = 20; do { double sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda); sinSigma = Math.sqrt((cosU2 * sinLambda) * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)); if (sinSigma == 0) return 0; // co-incident points cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda; sigma = Math.atan2(sinSigma, cosSigma); double sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma; cosSqAlpha = 1 - sinAlpha * sinAlpha; cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha; if (cos2SigmaM == Double.NaN) cos2SigmaM = 0; // equatorial line: cosSqAlpha=0 (?6) double C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha)); lambdaP = lambda; lambda = L + (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM))); } while (Math.abs(lambda - lambdaP) > EPSILON && --iterLimit > 0); if (iterLimit == 0) return Double.NaN; double uSquared = cosSqAlpha * (a * a - b * b) / (b * b); double A = 1 + uSquared / 16384 * (4096 + uSquared * (-768 + uSquared * (320 - 175 * uSquared))); double B = uSquared / 1024 * (256 + uSquared * (-128 + uSquared * (74 - 47 * uSquared))); double deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM))); double s = b * A * (sigma - deltaSigma); return unit.convert(s, LengthUnit.METRES); }