List of usage examples for java.lang Math tan
@HotSpotIntrinsicCandidate public static double tan(double a)
From source file:Geometry.java
/** * Create the geometry for an unrotated, unskewed ellipse. * Floating point domain./*w ww.j a va 2 s . c om*/ * * @param x0 X center of ellipse. * @param y0 Y center of ellipse. * @param dx X ellipse radius. * @param dy Y ellipse radius. * @return Ellipse geometry [x,y,x,y,...]. */ public static double[] createEllipse(double x0, double y0, double dx, double dy) { // Make sure deltas are positive dx = Math.abs(dx); dy = Math.abs(dy); // As we don't know the resolution of the appliance of the ellipse // we create one vertex per 2nd degree. The nPoints variable holds // number of points in a quater of the ellipse. int nPoints = 45; // Allocate arrays for holding the complete set of vertices around // the ellipse. Note that this is a complete ellipse: First and last // point coincide. double[] ellipse = new double[nPoints * 8 + 2]; // Compute some intermediate results to save time in the inner loop double dxdy = dx * dy; double dx2 = dx * dx; double dy2 = dy * dy; // Handcode the entries in the four "corner" points of the ellipse, // i.e. at point 0, 90, 180, 270 and 360 degrees ellipse[nPoints * 0 + 0] = x0 + dx; ellipse[nPoints * 0 + 1] = y0; ellipse[nPoints * 8 + 0] = x0 + dx; ellipse[nPoints * 8 + 1] = y0; ellipse[nPoints * 2 + 0] = x0; ellipse[nPoints * 2 + 1] = y0 - dy; ellipse[nPoints * 4 + 0] = x0 - dx; ellipse[nPoints * 4 + 1] = y0; ellipse[nPoints * 6 + 0] = x0; ellipse[nPoints * 6 + 1] = y0 + dy; // Find the angle step double angleStep = nPoints > 0 ? Math.PI / 2.0 / nPoints : 0.0; // Loop over angles from 0 to 90. The rest of the ellipse can be derrived // from this first quadrant. For each angle set the four corresponding // ellipse points. double a = 0.0; for (int i = 1; i < nPoints; i++) { a += angleStep; double t = Math.tan(a); double x = (double) dxdy / Math.sqrt(t * t * dx2 + dy2); double y = x * t + 0.5; ellipse[(nPoints * 0 + i) * 2 + 0] = x0 + x; ellipse[(nPoints * 2 - i) * 2 + 0] = x0 - x; ellipse[(nPoints * 2 + i) * 2 + 0] = x0 - x; ellipse[(nPoints * 4 - i) * 2 + 0] = x0 + x; ellipse[(nPoints * 0 + i) * 2 + 1] = y0 - y; ellipse[(nPoints * 2 - i) * 2 + 1] = y0 - y; ellipse[(nPoints * 2 + i) * 2 + 1] = y0 + y; ellipse[(nPoints * 4 - i) * 2 + 1] = y0 + y; } return ellipse; }
From source file:AppearanceExplorer.java
public void init() { // initialize the code base try {/*ww w . j ava 2 s . c om*/ java.net.URL codeBase = getCodeBase(); codeBaseString = codeBase.toString(); } catch (Exception e) { // probably running as an application, try the application // code base codeBaseString = "file:./"; } // set up a NumFormat object to print out float with only 3 fraction // digits nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(3); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); canvas = new Canvas3D(config); canvas.setSize(600, 600); u = new SimpleUniverse(canvas); if (isApplication) { offScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size Screen3D sOn = canvas.getScreen3D(); Screen3D sOff = offScreenCanvas.getScreen3D(); Dimension dim = sOn.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale); // attach the offscreen canvas to the view u.getViewer().getView().addCanvas3D(offScreenCanvas); } contentPane.add("Center", canvas); BackgroundTool bgTool = new BackgroundTool(codeBaseString); bgSwitch = bgTool.getSwitch(); bgChooser = bgTool.getChooser(); // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); // set up sound u.getViewer().createAudioDevice(); // get the view view = u.getViewer().getView(); // Get the viewing platform ViewingPlatform viewingPlatform = u.getViewingPlatform(); // Move the viewing platform back to enclose the -2 -> 2 range double viewRadius = 2.0; // want to be able to see circle // of viewRadius size around origin // get the field of view double fov = u.getViewer().getView().getFieldOfView(); // calc view distance to make circle view in fov float viewDistance = (float) (viewRadius / Math.tan(fov / 2.0)); tmpVector.set(0.0f, 0.0f, viewDistance);// setup offset tmpTrans.set(tmpVector); // set trans to translate // move the view platform viewingPlatform.getViewPlatformTransform().setTransform(tmpTrans); // add an orbit behavior to move the viewing platform OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.PROPORTIONAL_ZOOM | OrbitBehavior.REVERSE_ROTATE | OrbitBehavior.REVERSE_TRANSLATE); orbit.setZoomFactor(0.25); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit); u.addBranchGraph(scene); contentPane.add("East", guiPanel()); }
From source file:com.danilov.supermanga.core.view.SlidingLayer.java
/** * Get the x destination based on the velocity * /*from ww w .ja v a2 s . c o m*/ * @param xValue * @param yValue * @return * @since 1.0 * */ private int[] getDestScrollPos(int xValue, int yValue) { int[] pos = new int[2]; if (mIsOpen) { return pos; } else { switch (mScreenSide) { case STICK_TO_RIGHT: pos[0] = -getWidth() + mOffsetWidth; break; case STICK_TO_LEFT: pos[0] = getWidth() - mOffsetWidth; break; case STICK_TO_TOP: pos[1] = getHeight() - mOffsetWidth; break; case STICK_TO_BOTTOM: pos[1] = -getHeight() + mOffsetWidth; break; case STICK_TO_MIDDLE: // Calculate slope m to get direction of swiping and apply the same vector until the end of the // animation float m = 1; // If no veocity nor translation (difficult to get) the target is random if (xValue == 0 && yValue == 0) { m = mRandom != null ? (float) Math.tan(mRandom.nextFloat() * Math.PI - Math.PI / 2) : 1; } else if (xValue == 0) { // Avoid division by 0 (Get the max value of the tan which is equivalent) m = (float) Math.tan(Math.PI / 2); } else { // Get slope m = yValue / (float) xValue; } if (Math.abs(m) >= 1) { pos[0] = Math.round(getOperationSignForDiffMeasure(xValue) * getHeight() / Math.abs(m) - (mLastX - getWidth() / 2)); pos[1] = Math.round(getOperationSignForDiffMeasure(yValue) * getHeight()); } else { pos[0] = Math.round(getOperationSignForDiffMeasure(xValue) * getWidth()); pos[1] = Math.round(getOperationSignForDiffMeasure(yValue) * getWidth() * Math.abs(m) - (mLastY - getHeight() / 2)); } break; } return pos; } }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** SQL <code>TAN</code> operator applied to long values. */ public static double tan(long b0) { return Math.tan(b0); }
From source file:org.n52.v3d.terrainserver.povraywts.WebTerrainServlet.java
private VsSimpleScene defineScene(VgElevationGrid pTerrain, String pDrape, int pVisAdds, double pDistance, VgPoint pPoi, double pLambda, double pPhi, double pExaggeration, double lFovy) { // Szene instanzieren, Relief und Drape setzen: VsSimpleScene lScene = new PovrayScene(); // todo: dynamisch instanziieren; Klassenname und Renderer-spez. Properties-Dateiname aus "web.xml" ((PovrayScene) lScene).setRendererTimeout(mRendererTimeout); ((PovrayScene) lScene).setImmediateTermination(mRendererImmediateTermination); lScene.setTerrain(pTerrain);//w w w. j a v a 2 s .com lScene.setDrape(pDrape); lScene.setDefaultExaggeration(pExaggeration); // Szene mit Kamera und Ansichtspunkt versehen: VsCamera lCam = new VsCamera(); lScene.addCamera(lCam); VsViewpoint lViewpoint = new VsViewpoint(); lCam.addViewpoint(lViewpoint); // Prfen, ob im Weiteren orthografische Ansicht zu generieren ist: boolean orthographicView = false; if (Math.abs(lFovy) < 0.001) // eigentl.: falls lFovy = 0 orthographicView = true; // Aktuelle Ansichtspunktinformation setzen, falls kein POI in Anfrage angegeben: double radius, x, y, z, d_xy; if (pPoi == null) { if (!orthographicView) { // Bem.: Bedingung pDistance >= 0 ist sicherzustellen. if (pDistance > 0.) radius = lScene.getScale() * pDistance; else { // pDistance = 0; z. B., falls im Request nicht angegeben VgEnvelope env = this.getRotatedBBoxEnvelope(lScene.getAspect(), pLambda); radius = 0.5 * Math.max(env.getExtentX(), env.getExtentY()) / Math.tan(lFovy / 2. * Math.PI / 180.); } lCam.setProjection(VsCamera.PerspectiveView); lCam.setFovy(lFovy); } else { // orthografische Ansicht radius = 10.; // beliebig, ungleich 0, >> 1 (wegen Clipping-Plane in POV-Ray) lCam.setProjection(VsCamera.OrthographicView); } d_xy = radius * Math.cos(pPhi); x = -d_xy * Math.sin(pLambda); y = -d_xy * Math.cos(pLambda); z = radius * Math.sin(pPhi); // -pi/2. <= pPhi <= pi/2.! //System.out.println("d_xy = " + d_xy); //System.out.println("x = " + x + ", y = " + y + ", z = " + z); double z_offset = 0.5 * (lScene.normZMax() + lScene.normZMin()); lViewpoint.setLookFrom(lScene.denorm(new T3dVector(x, y, z / pExaggeration + z_offset))); lViewpoint.setLookAt(lScene.denorm(new T3dVector(0., 0., z_offset))); if (d_xy <= 1.e-6) // Sonderfall Draufsicht lViewpoint.setLookUp(new T3dVector(Math.sin(pLambda), Math.cos(pLambda), 0.)); } // Ansichtspunktinformation setzen, falls POI in Anfrage angegeben: if (pPoi != null) { if (orthographicView) throw new T3dException("Please specify a POI, or choose an perspective view."); lCam.setProjection(VsCamera.PerspectiveView); lCam.setFovy(lFovy); T3dVector normPoi = lScene.norm(pPoi); if (Math.abs(pDistance) < 0.0001) { radius = -10.; // beliebig, < 0 d_xy = radius * Math.cos(pPhi); x = -d_xy * Math.sin(pLambda); y = -d_xy * Math.cos(pLambda); z = radius * Math.sin(pPhi); // -pi/2. <= pPhi <= pi/2. lViewpoint.setLookFrom(pPoi); lViewpoint.setLookAt(lScene.denorm( new T3dVector(normPoi.getX() + x, normPoi.getY() + y, normPoi.getZ() + z / pExaggeration))); } else { radius = lScene.getScale() * pDistance; d_xy = radius * Math.cos(pPhi); x = -d_xy * Math.sin(pLambda); y = -d_xy * Math.cos(pLambda); z = radius * Math.sin(pPhi); // -pi/2. <= pPhi <= pi/2. lViewpoint.setLookFrom(lScene.denorm( new T3dVector(normPoi.getX() + x, normPoi.getY() + y, normPoi.getZ() + z / pExaggeration))); lViewpoint.setLookAt(pPoi); } if (d_xy <= 1.e-6) // Sonderfall Draufsicht lViewpoint.setLookUp(new T3dVector(Math.sin(pLambda), Math.cos(pLambda), 0.)); //System.out.println("d_xy = " + d_xy); //System.out.println("x = " + x + ", y = " + y + ", z = " + z); } //System.out.println("lookFrom = " + lScene.getCurrentViewpoint().getLookFrom()); //System.out.println("lookAt = " + lScene.getCurrentViewpoint().getLookAt()); //System.out.println("lookUp = " + lScene.getCurrentViewpoint().getLookUp()); // Erweiterte Darzustellungsparameter setzen: lScene.drawBBoxShape(false); if ((pVisAdds & 1) > 0) lScene.drawBBoxShape(true); lScene.drawTerrainPedestal(false); if ((pVisAdds & 2) > 0) { lScene.setPedestalColor(mPedestalColor); lScene.drawTerrainPedestal(true); } // Generierte Szene zurckgeben: return lScene; }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** SQL <code>TAN</code> operator applied to BigDecimal values. */ public static double tan(BigDecimal b0) { return Math.tan(b0.doubleValue()); }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** SQL <code>TAN</code> operator applied to double values. */ public static double tan(double b0) { return Math.tan(b0); }
From source file:com.pt.treasuretrash.widget.SlidingLayer.java
/** * Get the x destination based on the velocity * //from www.j a v a 2s .co m * @param xValue * @param yValue * @return * @since 1.0 * */ private int[] getDestScrollPos(int xValue, int yValue) { int[] pos = new int[2]; if (mIsOpen) { return pos; } else { switch (mScreenSide) { case STICK_TO_RIGHT: pos[0] = -getWidth() + mOffsetWidth; break; case STICK_TO_LEFT: pos[0] = getWidth() - mOffsetWidth; break; case STICK_TO_TOP: pos[1] = getHeight() - mOffsetWidth; break; case STICK_TO_BOTTOM: pos[1] = -getHeight() + mOffsetWidth; break; case STICK_TO_MIDDLE: // Calculate slope m to get direction of swiping and apply the // same vector until the end of the // animation float m = 1; // If no veocity nor translation (difficult to get) the target // is random if (xValue == 0 && yValue == 0) { m = mRandom != null ? (float) Math.tan(mRandom.nextFloat() * Math.PI - Math.PI / 2) : 1; } else if (xValue == 0) { // Avoid division by 0 (Get the max value of the tan which // is equivalent) m = (float) Math.tan(Math.PI / 2); } else { // Get slope m = yValue / (float) xValue; } if (Math.abs(m) >= 1) { pos[0] = Math.round(getOperationSignForDiffMeasure(xValue) * getHeight() / Math.abs(m) - (mLastX - getWidth() / 2)); pos[1] = Math.round(getOperationSignForDiffMeasure(yValue) * getHeight()); } else { pos[0] = Math.round(getOperationSignForDiffMeasure(xValue) * getWidth()); pos[1] = Math.round(getOperationSignForDiffMeasure(yValue) * getWidth() * Math.abs(m) - (mLastY - getHeight() / 2)); } break; } return pos; } }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void fillArea(AreaRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);/*ww w . j a v a 2s .c om*/ } final Fill flBackground = validateMultipleFill(are.getBackground()); if (isFullTransparent(flBackground)) { return; } // SETUP SWING DATA STRUCTURES final GeneralPath gp = new GeneralPath(); PrimitiveRenderEvent pre; for (int i = 0; i < are.getElementCount(); i++) { pre = are.getElement(i); if (pre instanceof ArcRenderEvent) { final ArcRenderEvent acre = (ArcRenderEvent) pre; final Arc2D.Double a2d = new Arc2D.Double(acre.getTopLeft().getX(), acre.getTopLeft().getY(), acre.getWidth(), acre.getHeight(), acre.getStartAngle(), acre.getAngleExtent(), toG2dArcType(acre.getStyle())); gp.append(a2d, true); } else if (pre instanceof LineRenderEvent) { final LineRenderEvent lre = (LineRenderEvent) pre; final Line2D.Double l2d = new Line2D.Double(lre.getStart().getX(), lre.getStart().getY(), lre.getEnd().getX(), lre.getEnd().getY()); gp.append(l2d, true); } } // BEGIN FILLING if (flBackground instanceof ColorDefinition) { _g2d.setColor((Color) _ids.getColor((ColorDefinition) flBackground)); } else if (flBackground instanceof Gradient) { final Gradient g = (Gradient) flBackground; final ColorDefinition cdStart = g.getStartColor(); final ColorDefinition cdEnd = g.getEndColor(); // boolean bCyclic = g.isCyclic(); double dAngleInDegrees = g.getDirection(); final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0); // int iAlpha = g.getTransparency(); Bounds bo = are.getBounds(); /* * if (bCyclic) { } */ if (dAngleInDegrees < -90 || dAngleInDegrees > 90) { throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, "SwingRendererImpl.exception.gradient.angle", //$NON-NLS-1$ new Object[] { new Double(dAngleInDegrees) }, Messages.getResourceBundle(getULocale())); } Point2D.Double p2dStart, p2dEnd; if (dAngleInDegrees == 90) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees == -90) { p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees > 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getHeight() - bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else if (dAngleInDegrees < 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop()); } _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd, (Color) _ids.getColor(cdEnd))); } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) { // TODO TBD } _g2d.fill(gp); }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void fillOval(OvalRenderEvent ore) throws ChartException { if (iv != null) { iv.modifyEvent(ore);/*from ww w . j ava 2 s . com*/ } final Fill flBackground = validateMultipleFill(ore.getBackground()); if (isFullTransparent(flBackground)) { return; } final Bounds bo = ore.getBounds(); final Ellipse2D.Double e2d = new Ellipse2D.Double(bo.getLeft(), bo.getTop(), bo.getWidth(), bo.getHeight()); if (flBackground instanceof ColorDefinition) { final ColorDefinition cd = (ColorDefinition) flBackground; _g2d.setColor((Color) _ids.getColor(cd)); _g2d.fill(e2d); } else if (flBackground instanceof Gradient) { final Gradient g = (Gradient) flBackground; final ColorDefinition cdStart = g.getStartColor(); final ColorDefinition cdEnd = g.getEndColor(); // boolean bCyclic = g.isCyclic(); double dAngleInDegrees = g.getDirection(); final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0); if (dAngleInDegrees < -90 || dAngleInDegrees > 90) { throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, "SwingRendererImpl.exception.gradient.angle", //$NON-NLS-1$ new Object[] { new Double(dAngleInDegrees) }, Messages.getResourceBundle(getULocale())); } Point2D.Double p2dStart, p2dEnd; if (dAngleInDegrees == 90) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees == -90) { p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees > 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getHeight() - bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else if (dAngleInDegrees < 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop()); } _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd, (Color) _ids.getColor(cdEnd))); _g2d.fill(e2d); } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) { Area ar2 = new Area(e2d); if (flBackground instanceof PatternImage) { fillWithPatternImage(ar2, flBackground); return; } java.awt.Image img = createImageFromModel(flBackground); if (img != null) { final Shape shClip = _g2d.getClip(); if (shClip != null) { Area ar1 = new Area(shClip); ar2.intersect(ar1); } _g2d.setClip(ar2); final Size szImage = _ids.getSize(img); int iXRepeat = (int) (Math.ceil(e2d.width / szImage.getWidth())); int iYRepeat = (int) (Math.ceil(e2d.height / szImage.getHeight())); ImageObserver io = (ImageObserver) _ids.getObserver(); for (int i = 0; i < iXRepeat; i++) { for (int j = 0; j < iYRepeat; j++) { _g2d.drawImage(img, (int) (e2d.x + i * szImage.getWidth()), (int) (e2d.y + j * szImage.getHeight()), io); } } _g2d.setClip(shClip); // RESTORE } } }