List of usage examples for java.lang Math atan2
@HotSpotIntrinsicCandidate public static double atan2(double y, double x)
From source file:gwap.rest.LocationService.java
/** * Berechnet die Entfernung zwischen position und destination in Metern. * @param positionLatitude: Latitude der Ausgangsposition * @param positionLongitude: Longitude der Ausgangsposition * @param destinationLatitude: Latitude des Ziels * @param destinationLongitude: Longitude des Ziels * @return Entfernung in Metern/*ww w .ja v a 2 s. com*/ */ private Double getDistance(double positionLatitude, double positionLongitude, double destinationLatitude, double destinationLongitude) { double earthRadius = 6369000; double dLat = Math.toRadians(destinationLatitude - positionLatitude); double dLng = Math.toRadians(destinationLongitude - positionLongitude); 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(positionLatitude)) * Math.cos(Math.toRadians(destinationLatitude)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = earthRadius * c; return distance; }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void atan2PiNinety() { try {//from ww w.j a v a2 s .c om Expression expression = getExpressionWithFunctionContext("atan2(pi,90)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.atan2(Math.PI, 90), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }
From source file:com.mylikes.likes.etchasketch.Slate.java
@SuppressLint("NewApi") @Override/*from www .j a v a 2 s . c o m*/ public boolean onTouchEvent(MotionEvent event) { final int action = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) ? event.getActionMasked() : event.getAction(); int N = event.getHistorySize(); int P = event.getPointerCount(); long time = event.getEventTime(); mEmpty = false; // starting a new touch? commit the previous state of the canvas if (action == MotionEvent.ACTION_DOWN) { commitStroke(); } if (mZoomMode) { return false; } int pointerIndex = MotionEventCompat.getActionIndex(event); int pointerId = event.getPointerId(pointerIndex); if (moveMode) { if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) { if (firstFinger != null) { MotionEvent.PointerCoords coords1 = new MotionEvent.PointerCoords(); event.getPointerCoords(0, coords1); Log.d(TAG, "coords1: " + coords1.x + " " + coords1.y); MotionEvent.PointerCoords coords2 = new MotionEvent.PointerCoords(); event.getPointerCoords(1, coords2); firstFinger.set(coords1.x, coords1.y); secondFinger = new PointF(coords2.x, coords2.y); } else { touchStartTime = System.currentTimeMillis(); moveDrawingStartX = event.getX(); moveDrawingStartY = event.getY(); int i = 0; moveDrawingIndex = -1; resizeDrawingIndex = -1; resizeDrawingCorner = null; if (selectedDrawing != null) { moveDrawingIndex = 0; } if (i >= overlays.size()) { return true; } Log.d(TAG, "Start dragging overlay"); firstFinger = new PointF(event.getX(), event.getY()); } return true; } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { if (secondFinger != null) { secondFinger = null; MotionEvent.PointerCoords coords1 = new MotionEvent.PointerCoords(); event.getPointerCoords(0, coords1); moveDrawingStartX = coords1.x; moveDrawingStartY = coords1.y; return true; } if (firstFinger != null) { firstFinger = null; } if (moveDrawingIndex == -1 && resizeDrawingIndex == -1 && System.currentTimeMillis() - touchStartTime < 400 && Math.abs(event.getX() - moveDrawingStartX) + Math.abs(event.getY() - moveDrawingStartY) < 8) { if (resizeDrawingCorner != null && selectedDrawing != null) { if (resizeDrawingCorner == "tl" && selectedDrawing instanceof TextDrawing) { //promptForText((TextDrawing)selectedDrawing); } else if (resizeDrawingCorner == "tr") { //maybeRemoveDrawing(selectedDrawing); } } else { //promptForText((int) event.getX(), (int) event.getY()); } } moveDrawingIndex = -1; Log.d(TAG, "Stop dragging overlay"); // TODO: add to undo stack return true; } else if (firstFinger != null && secondFinger != null && action == MotionEvent.ACTION_MOVE) { MotionEvent.PointerCoords coords1 = new MotionEvent.PointerCoords(); event.getPointerCoords(0, coords1); Log.d(TAG, "coords1: " + coords1.x + " " + coords1.y); MotionEvent.PointerCoords coords2 = new MotionEvent.PointerCoords(); event.getPointerCoords(1, coords2); Log.d(TAG, "coords2: " + coords2.x + " " + coords2.y); float xDist = firstFinger.x - secondFinger.x, yDist = firstFinger.y - secondFinger.y; float origAngle = (float) Math.atan2(yDist, xDist); if (origAngle < 0) origAngle += Math.PI * 2; float lastDistance = (float) Math.sqrt(xDist * xDist + yDist * yDist); xDist = coords2.x - coords1.x; yDist = coords2.y - coords1.y; float newDistance = (float) Math.sqrt(xDist * xDist + yDist * yDist); float newAngle = (float) Math.atan2(yDist, xDist); if (newAngle < 0) newAngle += Math.PI * 2; if (newAngle - origAngle > Math.PI / 2) { origAngle += Math.PI; } else if (origAngle - newAngle > Math.PI / 2) { newAngle += Math.PI; } firstFinger.set(coords1.x, coords1.y); secondFinger = new PointF(coords2.x, coords2.y); if (selectedDrawing != null) { selectedDrawing.resizeBy(newDistance / lastDistance); selectedDrawing.rotateBy(newAngle - origAngle); invalidate(); } } else if (moveDrawingIndex >= 0 && moveDrawingIndex < overlays.size() && action == MotionEvent.ACTION_MOVE) { float x = event.getX(); float y = event.getY(); overlays.get(moveDrawingIndex).moveBy((int) ((x - moveDrawingStartX) * getDrawingDensity()), (int) ((y - moveDrawingStartY) * getDrawingDensity())); // TODO: only invalidate relevant Rect invalidate(); moveDrawingStartX = x; moveDrawingStartY = y; return true; } else if (resizeDrawingIndex >= 0 && resizeDrawingIndex < overlays.size() && action == MotionEvent.ACTION_MOVE) { float x = event.getX(); float y = event.getY(); overlays.get(resizeDrawingIndex).resizeCorner(resizeDrawingCorner, (int) (x - moveDrawingStartX), (int) (y - moveDrawingStartY)); // TODO: only invalidate relevant Rect invalidate(); moveDrawingStartX = x; moveDrawingStartY = y; return true; } return false; } if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { int j = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) ? event.getActionIndex() : 0; mTmpSpot.update(event.getX(j), event.getY(j), event.getSize(j), event.getPressure(j) + event.getSize(j), time, getToolTypeCompat(event, j)); mStrokes[event.getPointerId(j)].add(mTmpSpot); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { mStrokes[event.getPointerId(j)].finish(time); } } else if (action == MotionEvent.ACTION_MOVE) { if (dbgX >= 0) { dbgRect.set(dbgX - 1, dbgY - 1, dbgX + 1, dbgY + 1); } for (int i = 0; i < N; i++) { for (int j = 0; j < P; j++) { mTmpSpot.update(event.getHistoricalX(j, i), event.getHistoricalY(j, i), event.getHistoricalSize(j, i), event.getHistoricalPressure(j, i) + event.getHistoricalSize(j, i), event.getHistoricalEventTime(i), getToolTypeCompat(event, j)); if ((mDebugFlags & FLAG_DEBUG_STROKES) != 0) { if (dbgX >= 0) { //mTiledCanvas.drawLine(dbgX, dbgY, mTmpSpot.x, mTmpSpot.y, mDebugPaints[3]); } dbgX = mTmpSpot.x; dbgY = mTmpSpot.y; dbgRect.union(dbgX - 1, dbgY - 1, dbgX + 1, dbgY + 1); } mStrokes[event.getPointerId(j)].add(mTmpSpot); } } for (int j = 0; j < P; j++) { mTmpSpot.update(event.getX(j), event.getY(j), event.getSize(j), event.getPressure(j) + event.getSize(j), time, getToolTypeCompat(event, j)); if ((mDebugFlags & FLAG_DEBUG_STROKES) != 0) { if (dbgX >= 0) { //mTiledCanvas.drawLine(dbgX, dbgY, mTmpSpot.x, mTmpSpot.y, mDebugPaints[3]); } dbgX = mTmpSpot.x; dbgY = mTmpSpot.y; dbgRect.union(dbgX - 1, dbgY - 1, dbgX + 1, dbgY + 1); } mStrokes[event.getPointerId(j)].add(mTmpSpot); } if ((mDebugFlags & FLAG_DEBUG_STROKES) != 0) { Rect dirty = new Rect(); dbgRect.roundOut(dirty); invalidate(dirty); } } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { for (int j = 0; j < P; j++) { mStrokes[event.getPointerId(j)].finish(time); } dbgX = dbgY = -1; } return true; }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void atan2NullPiHalf() { try {/*from w w w . ja v a 2s . c o m*/ Expression expression = getExpressionWithFunctionContext("atan2(0,pi/2)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.atan2(0, Math.PI / 2), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void atan2NinetyPiHalf() { try {/*from w w w .j a v a 2 s.c o m*/ Expression expression = getExpressionWithFunctionContext("atan2(90,pi/2)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.atan2(90, Math.PI / 2), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * Labels the specified non-self-loop edge with the specified label. * Uses the font specified by this instance's * <code>EdgeFontFunction</code>. (If the font is unspecified, the existing * font for the graphics context is used.) Positions the * label between the endpoints according to the coefficient returned * by this instance's edge label closeness function. *//* w w w . ja va2s .c o m*/ protected void labelEdge(Graphics2D g2d, Edge e, String label, int x1, int x2, int y1, int y2) { int distX = x2 - x1; int distY = y2 - y1; double totalLength = Math.sqrt(distX * distX + distY * distY); double closeness = edgeLabelClosenessFunction.getNumber(e).doubleValue(); int posX = (int) (x1 + (closeness) * distX); int posY = (int) (y1 + (closeness) * distY); int xDisplacement = (int) (LABEL_OFFSET * (distY / totalLength)); int yDisplacement = (int) (LABEL_OFFSET * (-distX / totalLength)); Component component = prepareRenderer(graphLabelRenderer, label, isPicked(e), e); Dimension d = component.getPreferredSize(); Shape edgeShape = edgeShapeFunction.getShape(e); double parallelOffset = 1; parallelOffset += parallelEdgeIndexFunction.getIndex(e); if (edgeShape instanceof Ellipse2D) { parallelOffset += edgeShape.getBounds().getHeight(); parallelOffset = -parallelOffset; } parallelOffset *= d.height; AffineTransform old = g2d.getTransform(); AffineTransform xform = new AffineTransform(old); xform.translate(posX + xDisplacement, posY + yDisplacement); double dx = x2 - x1; double dy = y2 - y1; if (graphLabelRenderer.isRotateEdgeLabels()) { double theta = Math.atan2(dy, dx); if (dx < 0) { theta += Math.PI; } xform.rotate(theta); } if (dx < 0) { parallelOffset = -parallelOffset; } xform.translate(-d.width / 2, -(d.height / 2 - parallelOffset)); g2d.setTransform(xform); rendererPane.paintComponent(g2d, component, screenDevice, 0, 0, d.width, d.height, true); g2d.setTransform(old); }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap bulging(Bitmap bmImage, int radius, int pointX, int pointY) { Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig()); // Bitmap bmTemp = bmImage.copy(Config.ARGB_8888, true); for (int i = 0; i < bmImage.getWidth(); i++) { for (int j = 0; j < bmImage.getHeight(); j++) { // get center point double cx = pointX; // bmImage.getWidth() / 2; double cy = pointY; // bmImage.getHeight() / 2; // compute distance to center point double r = Math.sqrt(Math.pow(i - cx, 2) + Math.pow(j - cy, 2)); // compute angle atan2(y, x) in range (-PI..PI] n polar coordinate system double a = Math.atan2(j - cy, i - cx); // rn = r ^ k, k=1..2 double rn = Math.pow(r, radius / 10.0) / (radius); // compute mapping point and then shift to center point int kx = (int) (rn * Math.cos(a) + cx); int ky = (int) (rn * Math.sin(a) + cy); if (kx >= 0 && kx < bmImage.getWidth() && ky >= 0 && ky < bmImage.getHeight()) bmTemp.setPixel(i, j, bmImage.getPixel(kx, ky)); else//ww w . ja va 2s . co m bmTemp.setPixel(i, j, 0x00ffffff); } // /for(j) } // /for(i) return bmTemp; }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void atan2PiHalfNull() { try {//from www .j av a2s . com Expression expression = getExpressionWithFunctionContext("atan2(pi/2,0)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.atan2(Math.PI / 2, 0), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void atan2PiHalfNinety() { try {/*from w w w . ja va 2 s .c o m*/ Expression expression = getExpressionWithFunctionContext("atan2(pi/2,90)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.atan2(Math.PI / 2, 90), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void atan2PiPi() { try {//from w w w.jav a2 s. c o m Expression expression = getExpressionWithFunctionContext("atan2(pi,pi)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.atan2(Math.PI, Math.PI), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }