List of usage examples for java.lang Math atan2
@HotSpotIntrinsicCandidate public static double atan2(double y, double x)
From source file:org.pooledtimeseries.PoT.java
static int opticalFlowType(Point fxy, int dim) { double degree = Math.atan2(fxy.y, fxy.x); int type = 7; for (int i = 0; i < dim; i++) { double boundary = (i + 1) * 2 * Math.PI / dim - Math.PI; if (degree < boundary) { type = i;/* w ww .j a v a2s . c o m*/ break; } } return type; }
From source file:me.solhub.simple.engine.DebugLocationsStructure.java
@Override protected void draw() { Graphics2D g = (Graphics2D) getGraphics(); Graphics2D bbg = (Graphics2D) _backBuffer.getGraphics(); //anti-aliasing code // bbg.setRenderingHint( // RenderingHints.KEY_TEXT_ANTIALIASING, // RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // bbg.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); bbg.setColor(Color.WHITE);/* ww w . j a va 2 s .c o m*/ bbg.fillRect(0, 0, _windowWidth, _windowHeight); bbg.translate(_xOffset, _yOffset); // draw destinations bbg.setColor(_simState.startingDestination.getColor()); bbg.drawOval(-(int) _simState.startingDestination.getRadius(), -(int) _simState.startingDestination.getRadius(), (int) _simState.startingDestination.getRadius() * 2, (int) _simState.startingDestination.getRadius() * 2); Iterator<Entry<Vector2D, Color>> blah = _destinationColors.entrySet().iterator(); double destinationRadius = _simState.getDestinationRadius(); while (blah.hasNext()) { Entry<Vector2D, Color> temp = blah.next(); bbg.setColor(temp.getValue()); //calculate center coordinate int x = (int) (temp.getKey().getX() - (destinationRadius)); int y = (int) (temp.getKey().getY() - (destinationRadius)); //drawOval draws a circle inside a rectangle bbg.drawOval(x, y, _simState.getDestinationRadius() * 2, _simState.getDestinationRadius() * 2); } // draw each of the agents Iterator<Agent> agentIter = _simState.getAgentIterator(); while (agentIter.hasNext()) { Agent temp = agentIter.next(); if (temp.isAlive()) { // decide whether to color for destination or group // if( isDestinationColors ) // { // // if stopped then blink white and destination color // if( temp.hasReachedDestination() ) // { // if( pulseWhite % 20 == 0 ) // { // bbg.setColor( Color.WHITE ); // } // else // { // bbg.setColor( temp.getDestinationColor() ); // } // } // else // { // bbg.setColor( temp.getDestinationColor() ); // } // } // else // { // // if stopped then blink black and white // if( temp.hasReachedDestination() ) // { // if( pulseWhite % 20 == 0 ) // { // bbg.setColor( Color.WHITE ); // } // else // { // bbg.setColor( temp.getGroup().getGroupColor() ); // } // } // //set color to red if cancelled and global and not multiple initiators // else if(temp.getCurrentDecision().getDecision().getDecisionType().equals( // DecisionType.CANCELLATION ) // && _simState.getCommunicationType().equals( "global" ) // && !Agent.canMultipleInitiate() // ) // { // bbg.setColor( Color.RED ); // } // else // { // bbg.setColor( temp.getGroup().getGroupColor() ); // } // } double dx = temp.getCurrentDestination().getX() - temp.getCurrentLocation().getX(); double dy = temp.getCurrentDestination().getY() - temp.getCurrentLocation().getY(); double heading = Math.atan2(dy, dx); Utils.drawDirectionalTriangle(bbg, heading - Math.PI / 2, temp.getCurrentLocation().getX(), temp.getCurrentLocation().getY(), 7, temp.getPreferredDestination().getColor(), temp.getGroup().getGroupColor()); // bbg.fillOval( (int) temp.getCurrentLocation().getX() - _agentSize, // (int) temp.getCurrentLocation().getY() - _agentSize , _agentSize * 2, _agentSize * 2 ); } } pulseWhite++; bbg.setColor(Color.BLACK); // the total number of groups bbg.setFont(_infoFont); bbg.drawString("Run: " + (_simState.getCurrentSimulationRun() + 1), _fontXOffset, _fontYOffset); bbg.drawString("Time: " + _simState.getSimulationTime(), _fontXOffset, _fontYOffset + _fontSize); bbg.drawString("Delay: " + LIVE_DELAY, _fontXOffset, _fontYOffset + _fontSize * 2); if (_simState.getCommunicationType().equals("global") && !Agent.canMultipleInitiate()) { String initiatorName = "None"; if (_initiatingAgent != null) { initiatorName = _initiatingAgent.getId().toString(); } bbg.drawString("Init: " + initiatorName, _fontXOffset, _fontYOffset + _fontSize * 3); bbg.drawString("Followers: " + _numberFollowing, _fontXOffset, _fontYOffset + _fontSize * 4); } else { bbg.drawString("Groups: " + _simState.getNumberGroups(), _fontXOffset, _fontYOffset + _fontSize * 3); bbg.drawString("Reached: " + _simState.numReachedDestination, _fontXOffset, _fontYOffset + _fontSize * 4); bbg.drawString("Inits: " + _simState.numInitiating, _fontXOffset, _fontYOffset + _fontSize * 5); bbg.drawString("Eaten: " + _simState.getPredator().getTotalAgentsEaten(), _fontXOffset, _fontYOffset + _fontSize * 6); } g.scale(_zoom, _zoom); g.drawImage(_backBuffer, 0, 0, this); if (SHOULD_VIDEO) { // setup to save to a png BufferedImage buff = new BufferedImage(_windowWidth, _windowHeight, BufferedImage.TYPE_INT_RGB); Graphics2D temp = (Graphics2D) buff.getGraphics(); temp.scale(8, 4); temp.drawImage(_backBuffer, 0, 0, this); // sub-directory File dir = new File("video"); dir.mkdir(); // format string for filename String filename = String.format("video/run-%03d-time-%05d.png", _simState.getCurrentSimulationRun(), _simState.getSimulationTime()); File outputfile = new File(filename); // save it try { ImageIO.write(buff, "png", outputfile); } catch (IOException e) { e.printStackTrace(); } } }
From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java
static int opticalFlowType(Point fxy, int dim) { double degree = Math.atan2(fxy.y, fxy.x); int type = 7; for (int i = 0; i < dim; i++) { double boundary = (i + 1) * 2 * Math.PI / dim - Math.PI; if (degree < boundary) { type = i;//from w w w .j av a2 s . co m break; } } return type; }
From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java
/** * Convert from cartesian to polar// w ww .j ava 2s. c o m * * @param xPos current x point * @param yPos current y point * @return angle of the Thumb w.r.t the arc. */ private double getTouchDegrees(float xPos, float yPos) { float x = xPos - mTranslateX; float y = yPos - mTranslateY; //invert the x-coord if we are rotating anti-clockwise x = (mClockwise) ? x : -x; // convert to arc Angle double angle = Math.toDegrees(Math.atan2(y, x) + (Math.PI / 2) - Math.toRadians(mRotation)); if (angle < 0) { angle = 360 + angle; } angle -= mStartAngle; return angle; }
From source file:org.kalypsodeegree_impl.graphics.displayelements.RasterDisplayElement_Impl.java
private double calculateSlope(final int i, final int j, final double[][] values, final double xres, final double yres, final double z) { final double scale = 1.0; final double az = 315.0; final double alt = 75.0; if (i == 0 || i > values.length - 2) return Double.NaN; if (j == 0 || j > values[0].length - 2) return Double.NaN; // First Slope ... final double x = z * // (values[i - 1][j - 1] + values[i - 1][j] + values[i - 1][j] + values[i - 1][j + 1] - values[i + 1][j - 1] - values[i + 1][j] - values[i + 1][j] - values[i + 1][j + 1]) // / (8.0 * xres * scale);/* www.j a v a 2 s . c o m*/ final double y = z * // (values[i - 1][j + 1] + values[i][j + 1] + values[i][j + 1] + values[i + 1][j + 1] - values[i - 1][j - 1] - values[i][j - 1] - values[i][j - 1] - values[i + 1][j - 1]) // / (8.0 * yres * scale); final double slope = 90.0 - Math.toDegrees(Math.atan(Math.sqrt(x * x + y * y))); // ... then aspect... final double aspect = Math.atan2(x, y); // ... then the shade value final double cang = Math.sin(Math.toRadians(alt)) * Math.sin(Math.toRadians(slope)) + // Math.cos(Math.toRadians(alt)) * Math.cos(Math.toRadians(slope)) // * Math.cos(Math.toRadians(az - 90.0) - aspect); if (cang <= 0.0) return 1.0; return cang; }
From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java
public void calculateAngles(float[] result, float[] rVector, float[] accVector, float[] magVector) { //caculate temp rotation matrix from rotation vector first SensorManager.getRotationMatrix(rMatrix, null, accVector, magVector); SensorManager.getQuaternionFromVector(quaternion, rVector); roll = Math.atan2(2.0f * (quaternion[0] * quaternion[1] + quaternion[2] * quaternion[3]), 1.0f - 2.0f * (quaternion[1] * quaternion[1] + quaternion[2] * quaternion[2])); pitch = Math.asin(2.0f * (quaternion[0] * quaternion[2] - quaternion[3] * quaternion[1])); yaw = Math.atan2(2.0f * (quaternion[0] * quaternion[3] + quaternion[1] * quaternion[2]), 1.0f - 2.0f * (quaternion[2] * quaternion[2] + quaternion[3] * quaternion[3])); rollW = ((roll + Math.PI) / (Math.PI * 2.0) * SCALE); pitchW = ((pitch + Math.PI / 2.0) / Math.PI * SCALE); yawW = ((yaw + Math.PI) / (Math.PI * 2.0) * SCALE); //calculate Euler angles now SensorManager.getOrientation(rMatrix, result); //Now we can convert it to degrees convertToDegrees(result);/* w w w . j a v a 2s. c o m*/ }
From source file:com.example.appf.CS3570.java
public void computerEuler() { //Quaternion describing orientation of sensor relative to earth. double ESq_1, ESq_2, ESq_3, ESq_4; //Quaternion describing orientation of sensor relative to auxiliary frame. double ASq_1, ASq_2, ASq_3, ASq_4; //Compute the quaternion conjugate. ESq_1 = SEq_1;/* w w w . j a v a2 s .c o m*/ ESq_2 = -SEq_2; ESq_3 = -SEq_3; ESq_4 = -SEq_4; //Compute the quaternion product. ASq_1 = ESq_1 * AEq_1 - ESq_2 * AEq_2 - ESq_3 * AEq_3 - ESq_4 * AEq_4; ASq_2 = ESq_1 * AEq_2 + ESq_2 * AEq_1 + ESq_3 * AEq_4 - ESq_4 * AEq_3; ASq_3 = ESq_1 * AEq_3 - ESq_2 * AEq_4 + ESq_3 * AEq_1 + ESq_4 * AEq_2; ASq_4 = ESq_1 * AEq_4 + ESq_2 * AEq_3 - ESq_3 * AEq_2 + ESq_4 * AEq_1; //Compute the Euler angles from the quaternion. phi = Math.atan2(2 * ASq_3 * ASq_4 - 2 * ASq_1 * ASq_2, 2 * ASq_1 * ASq_1 + 2 * ASq_4 * ASq_4 - 1); theta = Math.asin(2 * ASq_2 * ASq_3 - 2 * ASq_1 * ASq_3); psi = Math.atan2(2 * ASq_2 * ASq_3 - 2 * ASq_1 * ASq_4, 2 * ASq_1 * ASq_1 + 2 * ASq_2 * ASq_2 - 1); }
From source file:fr.gotorennes.AbstractMapActivity.java
public static double getDistance(double lat1, double lon1, double lat2, double lon2) { double dLat = (lat2 - lat1) * deg2rad; double dLon = (lon2 - lon1) * deg2rad; double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 * deg2rad) * Math.cos(lat2 * deg2rad) * Math.sin(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return c * erad; }
From source file:uk.ac.diamond.scisoft.analysis.diffraction.PowderRingsUtils.java
/** * Find major axes by looking along thick line given by relative coordinates to centre for * maximum intensity values//w ww . j av a2 s.c o m * @param mon * @param axes * @param image * @param mask * @param roi * @param offset minimum position of peaks * @param width of line * @param centre * @param dx * @param dy */ private static void findMajorAxes(IMonitor mon, TreeSet<Double> axes, Dataset image, Dataset mask, EllipticalROI roi, double offset, double width, double[] centre, double dx, double dy) { RectangularROI rroi = new RectangularROI(); rroi.setPoint(centre); rroi.setAngle(Math.atan2(dy, dx)); rroi.setLengths(Math.hypot(dx, dy), width); rroi.translate(0, -0.5); rroi.setClippingCompensation(true); Dataset profile = ROIProfile.maxInBox(image, mask, rroi)[0]; List<IdentifiedPeak> peaks = Generic1DFitter .findPeaks(DatasetFactory.createRange(profile.getSize(), Dataset.INT), profile, PEAK_SMOOTHING); if (mon != null) mon.worked(profile.getSize()); System.err.printf("\n"); DescriptiveStatistics stats = new DescriptiveStatistics(); int[] pb = new int[1]; int[] pe = new int[1]; for (IdentifiedPeak p : peaks) { if (p.getPos() < offset) { continue; } pb[0] = (int) p.getMinXVal(); pe[0] = (int) p.getMaxXVal(); p.setArea((Double) profile.getSlice(pb, pe, null).sum()); stats.addValue(p.getArea()); System.err.printf("P %f A %f W %f H %f\n", p.getPos(), p.getArea(), p.getFWHM(), p.getHeight()); } double area = stats.getMean() + 0.4 * (stats.getPercentile(75) - stats.getPercentile(25)); logger.debug("Area: {}", stats); logger.debug("Minimum threshold: {}", area); double majorFactor = roi.getSemiAxis(0) / roi.getDistance(rroi.getAngle()); double maxFWHM = MAX_FWHM_FACTOR * width; for (IdentifiedPeak p : peaks) { double l = p.getPos(); if (l < offset) { continue; } // System.err.println(p); // filter on area and FWHM if (p.getFWHM() > maxFWHM) { continue; } if (p.getArea() < area) { break; } axes.add(l * majorFactor); } if (mon != null) mon.worked(peaks.size()); }
From source file:net.konyan.yangonbusonthemap.HomeActivity.java
public static float distFrom(float lat1, float lng1, float lat2, float lng2) { double earthRadius = 6371000; //meters double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); float dist = (float) (earthRadius * c); return dist;/*from w w w. ja v a 2 s .c om*/ }