List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:Main.java
/** * Converts to Cartesian points//ww w .ja v a 2 s.c om * * @param lat latitude * @param lon longitude * * @return point in x,y,z */ private static double[] latlon2cartesian(double lat, double lon) { return new double[] { Math.cos(lon) * Math.cos(lat) * EARTH_RADIUS, Math.sin(lon) * Math.cos(lat) * EARTH_RADIUS, Math.sin(lat) * EARTH_RADIUS }; }
From source file:Main.java
/** * Computes the bearing in radians between two points on Earth. * * @param lat1 Latitude of the first point * @param lon1 Longitude of the first point * @param lat2 Latitude of the second point * @param lon2 Longitude of the second point * @return Bearing between the two points in radians. A value of 0 means due * north./*from www .jav a 2 s . c om*/ */ public static double bearingRad(double lat1, double lon1, double lat2, double lon2) { double lat1Rad = Math.toRadians(lat1); double lat2Rad = Math.toRadians(lat2); double deltaLonRad = Math.toRadians(lon2 - lon1); double y = Math.sin(deltaLonRad) * Math.cos(lat2Rad); double x = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad); return Math.atan2(y, x); }
From source file:Main.java
/** * Computes the bearing in degrees between two points on Earth. * /*ww w .ja v a 2 s . co m*/ * @param lat1 Latitude of the first point * @param lon1 Longitude of the first point * @param lat2 Latitude of the second point * @param lon2 Longitude of the second point * @return Bearing between the two points in degrees. A value of 0 means due * north. */ public static double bearing(double lat1, double lon1, double lat2, double lon2) { double lat1Rad = Math.toRadians(lat1); double lat2Rad = Math.toRadians(lat2); double deltaLonRad = Math.toRadians(lon2 - lon1); double y = Math.sin(deltaLonRad) * Math.cos(lat2Rad); double x = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad); return radToBearing(Math.atan2(y, x)); }
From source file:Main.java
/** * Waypoint projection using haversine formula * http://en.wikipedia.org/wiki/Haversine_formula See discussion here for * further information: http://www.movable-type.co.uk/scripts/latlong.html *///from ww w . ja va 2 s .c om public static double[] project(double distance, double bearing, double startLat, double startLon) { double distanceRad = distance / EARTH_RADIUS_KM; double bearingRad = Math.toRadians(bearing); double startLatRad = Math.toRadians(startLat); double startLonRad = Math.toRadians(startLon); double endLat = Math.asin(Math.sin(startLatRad) * Math.cos(distanceRad) + Math.cos(startLatRad) * Math.sin(distanceRad) * Math.cos(bearingRad)); double endLon = startLonRad + Math.atan2(Math.sin(bearingRad) * Math.sin(distanceRad) * Math.cos(startLatRad), Math.cos(distanceRad) - Math.sin(startLatRad) * Math.sin(endLat)); // Adjust projections crossing the 180th meridian: double endLonDeg = Math.toDegrees(endLon); if (endLonDeg > 180 || endLonDeg < -180) { endLonDeg = endLonDeg % 360; // Just in case we circle the earth // more than once. if (endLonDeg > 180) { endLonDeg = endLonDeg - 360; } else if (endLonDeg < -180) { endLonDeg = endLonDeg + 360; } } double[] endCoords = new double[] { Math.toDegrees(endLat), endLonDeg }; return endCoords; }
From source file:info.financialecology.finance.utilities.sandbox.SimpleStrategyFSM.java
public static void main(String[] args) { try {//from w ww . j av a 2 s . c o m // Build FSM SimpleStrategyFSM strategyFSM = new SimpleStrategyFSM(); StateMachine sm = strategyFSM.getStateMachine(); int nTicks = 200; // Number of ticks double sinus_shift = 10.0; double sinus_amplitude = 10.0; double sinus_lambda = 50.0; double threshold5 = 0.05 * 2 * sinus_amplitude; double threshold50 = 0.5 * 2 * sinus_amplitude; double threshold95 = 0.95 * 2 * sinus_amplitude; logger.info( "Thresholds: [5%, " + threshold5 + "], [50%, " + threshold50 + "], [95%, " + threshold95 + "]"); //double sinus_t_prev = sinus_amplitude + sinus_shift + sinus_amplitude * Math.sin(2 * 0 * Math.PI / sinus_lambda); double sinus_t_prev = sinus_shift + sinus_amplitude * Math.sin(2 * 0 * Math.PI / sinus_lambda); strategyFSM.start(); for (int i = 1; i < nTicks; i++) { double sinus_t = sinus_amplitude + sinus_shift + sinus_amplitude * Math.sin(2 * i * Math.PI / sinus_lambda); //double sinus_t = sinus_shift + sinus_amplitude * Math.sin(2 * i * Math.PI / sinus_lambda); logger.info("Tick: " + i + ", value: " + sinus_t); if ((sinus_t >= threshold95) && (sinus_t_prev < threshold95)) strategyFSM.crossing95(); if ((sinus_t >= threshold50) && (sinus_t_prev < threshold50) || (sinus_t <= threshold50) && (sinus_t_prev > threshold50)) strategyFSM.crossing50(); if ((sinus_t <= threshold5) && (sinus_t_prev > threshold5)) strategyFSM.crossing5(); sinus_t_prev = sinus_t; } /* int window = 10; // Window for the calculation of percentiles int nTicks = 200; // Number of ticks double[] sinus = new double[nTicks]; // Price series (= sinus process) double sinus_shift = 100.0; // Parameters of the sinus process double sinus_amplitude = 20.0; double sinus_lambda = 50.0; // Create a sinus price process to test the strategy for (int i = 0; i < nTicks; i++) { sinus[i] = sinus_shift + sinus_amplitude * Math.sin(2*i*Math.PI / sinus_lambda); } for (int i = 0; i < nTicks; i++) { if (i < window) positions.add(0); else { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int j = i-window+1; j <= i; j++) { stats.addValue(sinus[j]); } double perc_95 = stats.getPercentile(95); double perc_5 = stats.getPercentile(5); double perc_50 = stats.getPercentile(50); if (sinus[i-1]<perc_95 && sinus[i]>=perc_95) sm.applyEvent(new Event("Buy")); if (sinus[i-1]>perc_5 && sinus[i]<=perc_5) sm.applyEvent(new Event("Sell")); // TODO: Add liquidation events } } */ // Terminate FSM strategyFSM.stop(); } catch (FiniteStateException e) { logger.error("Unexpected state transition processing error", e); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } }
From source file:Main.java
/** * Returns the distance between two given locations in meters. * * @param loc1 First location object//from w ww . j a va 2s. com * @param loc2 Second location object * @return distance between Loc1 & Loc2 in meters. */ public static float getDistance(Location loc1, Location loc2) { double lat1 = loc1.getLatitude(); double lng1 = loc1.getLongitude(); double lat2 = loc2.getLatitude(); double lng2 = loc2.getLongitude(); double earthRad = 6371; //kilometers double dLatitude = Math.toRadians(lat2 - lat1); double dLongitude = Math.toRadians(lng2 - lng1); double a = Math.sin(dLatitude / 2) * Math.sin(dLatitude / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLongitude / 2) * Math.sin(dLongitude / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); float dist = (float) (earthRad * c); dist = dist * MILES_TO_METER_CONVERSION; return dist; }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; int w = getSize().width - 1; int h = getSize().height - 1; for (int i = 0; i < 12; i++) { double angle = Math.PI / 2 - i * Math.PI / 6; double x = Math.cos(angle); double y = Math.sin(angle); Line2D l = new Line2D.Double(100 + 55.0 * x, 100 - 55.0 * y, 100 + 65.0 * x, 100 - 65.0 * y); g2.draw(l);//from w w w . j av a 2s. co m } }
From source file:Main.java
public void paint(Graphics g) { super.paintComponent(g); int radius = 40; int centerX = 50; int centerY = 100; Polygon p = new Polygon(); centerX = 150;//from w ww . j a v a 2 s . c o m for (int i = 0; i < 5; i++) p.addPoint((int) (centerX + radius * Math.cos(i * 2 * Math.PI / 5)), (int) (centerY + radius * Math.sin(i * 2 * Math.PI / 5))); g.fillPolygon(p); }
From source file:com.jennifer.ui.util.MathUtil.java
public static double rotateX(double x, double y, double radian) { return x * Math.cos(radian) - y * Math.sin(radian); }
From source file:DrawPolyPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); Polygon p = new Polygon(); for (int i = 0; i < 5; i++) p.addPoint((int) (100 + 50 * Math.cos(i * 2 * Math.PI / 5)), (int) (100 + 50 * Math.sin(i * 2 * Math.PI / 5))); g.drawPolygon(p);// w w w. ja va 2 s .c om Polygon s = new Polygon(); for (int i = 0; i < 360; i++) { double t = i / 360.0; s.addPoint((int) (150 + 50 * t * Math.cos(8 * t * Math.PI)), (int) (150 + 50 * t * Math.sin(8 * t * Math.PI))); } g.drawPolygon(s); }