List of usage examples for java.lang Math tan
@HotSpotIntrinsicCandidate public static double tan(double a)
From source file:Geometry.java
/** * Return the geometry of an ellipse based on its four top points. * Integer domain. The method use the generic createEllipse() * method for the main task, and then transforms this according * to any rotation or skew defined by the given top points. * //from www .j ava 2s . c o m * @param x X array of four top points of ellipse. * @param y Y array of four top points of ellipse. * @return Geometry of ellipse [x,y,x,y...]. */ public static int[] createEllipse(int[] x, int[] y) { // Center of ellipse int x0 = (x[0] + x[2]) / 2; int y0 = (y[0] + y[2]) / 2; // Angle between axis define skew double[] p0 = { (double) x0, (double) y0, 0.0 }; double[] p1 = { (double) x[0], (double) y[0], 0.0 }; double[] p2 = { (double) x[1], (double) y[1], 0.0 }; double axisAngle = Geometry.computeAngle(p0, p1, p2); // dx / dy double dx = Geometry.length(x0, y0, x[1], y[1]); double dy = Geometry.length(x0, y0, x[0], y[0]) * Math.sin(axisAngle); // Create geometry for unrotated / unsheared ellipse int[] ellipse = createEllipse(x0, y0, (int) Math.round(dx), (int) Math.round(dy)); int nPoints = ellipse.length / 2; // Shear if neccessary. If angle is close to 90 there is no shear. // If angle is close to 0 or 180 shear is infinite, and we set // it to zero as well. if (!Geometry.equals(axisAngle, Math.PI / 2.0, 0.1) && !Geometry.equals(axisAngle, Math.PI, 0.1) && !Geometry.equals(axisAngle, 0.0, 0.1)) { double xShear = 1.0 / Math.tan(axisAngle); for (int i = 0; i < nPoints; i++) ellipse[i * 2 + 0] += Math.round((ellipse[i * 2 + 1] - y0) * xShear); } // Rotate int ddx = x[1] - x0; int ddy = y0 - y[1]; double angle; if (ddx == 0 && ddy == 0) angle = 0.0; else if (ddx == 0) angle = Math.PI / 2.0; else angle = Math.atan((double) ddy / (double) ddx); double cosAngle = Math.cos(angle); double sinAngle = Math.sin(angle); for (int i = 0; i < nPoints; i++) { int xr = (int) Math .round(x0 + (ellipse[i * 2 + 0] - x0) * cosAngle - (ellipse[i * 2 + 1] - y0) * sinAngle); int yr = (int) Math .round(y0 - (ellipse[i * 2 + 1] - y0) * cosAngle - (ellipse[i * 2 + 0] - x0) * sinAngle); ellipse[i * 2 + 0] = xr; ellipse[i * 2 + 1] = yr; } return ellipse; }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void fillArc(ArcRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);/*from ww w . j a va 2 s . c om*/ } final Fill flBackground = validateMultipleFill(are.getBackground()); if (isFullTransparent(flBackground)) { return; } if (flBackground instanceof ColorDefinition) { final ColorDefinition cl = (ColorDefinition) flBackground; final Color clrPrevious = _g2d.getColor(); final Color currentColor = (Color) _ids.getColor(cl); _g2d.setColor(currentColor); if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius()) || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) { Bounds rctOuter = getOuterRectangle(are); Bounds rctInner = getInnerRectangle(are); Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(), rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(), rctInner.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Area fArea = new Area(outerArc); fArea.exclusiveOr(new Area(innerArc)); Shape prevClip = _g2d.getClip(); Area ar2 = new Area(fArea); if (prevClip != null) { Area ar1 = new Area(prevClip); ar2.intersect(ar1); } _g2d.setClip(ar2); _g2d.fill(fArea); _g2d.setClip(prevClip); } else { _g2d.fill(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle()))); } _g2d.setColor(clrPrevious); // RESTORE } else if (flBackground instanceof Gradient) { final Gradient g = (Gradient) flBackground; final ColorDefinition cdStart = g.getStartColor(); final ColorDefinition cdEnd = g.getEndColor(); double dAngleInDegrees = g.getDirection(); final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0); Bounds bo = are.getBounds(); 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()); } final Paint pPrevious = _g2d.getPaint(); _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd, (Color) _ids.getColor(cdEnd))); if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius()) || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) { Bounds rctOuter = getOuterRectangle(are); Bounds rctInner = getInnerRectangle(are); Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(), rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(), rctInner.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Area fArea = new Area(outerArc); fArea.exclusiveOr(new Area(innerArc)); Shape prevClip = _g2d.getClip(); Area ar2 = new Area(fArea); if (prevClip != null) { Area ar1 = new Area(prevClip); ar2.intersect(ar1); } _g2d.setClip(ar2); _g2d.fill(fArea); _g2d.setClip(prevClip); } else { _g2d.fill(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle()))); } _g2d.setPaint(pPrevious); // RESTORE } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) { final Bounds bo = are.getBounds(); final Rectangle2D.Double r2d = new Rectangle2D.Double(bo.getLeft(), bo.getTop(), bo.getWidth(), bo.getHeight()); Shape shPreviousClip = _g2d.getClip(); Area ar = null; if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius()) || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) { Bounds rctOuter = getOuterRectangle(are); Bounds rctInner = getInnerRectangle(are); Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(), rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(), rctInner.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Area fArea = new Area(outerArc); fArea.exclusiveOr(new Area(innerArc)); if (shPreviousClip != null) { Area ar1 = new Area(shPreviousClip); fArea.intersect(ar1); } // _g2d.setClip( fArea ); ar = fArea; } else { // SETUP THE CLIPPING AREA final Shape shArc = new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle())); Area ar2 = new Area(shArc); if (shPreviousClip != null) { Area ar1 = new Area(shPreviousClip); ar2.intersect(ar1); } // _g2d.setClip( ar2 ); ar = ar2; } if (flBackground instanceof PatternImage) { fillWithPatternImage(new Area(ar), flBackground); return; } _g2d.setClip(ar); // LOAD THE IMAGE java.awt.Image img = createImageFromModel(flBackground); if (img != null) { // REPLICATE THE IMAGE AS NEEDED final Size szImage = _ids.getSize(img); int iXRepeat = (int) (Math.ceil(r2d.width / szImage.getWidth())); int iYRepeat = (int) (Math.ceil(r2d.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) (r2d.x + i * szImage.getWidth()), (int) (r2d.y + j * szImage.getHeight()), io); } } } _g2d.setClip(shPreviousClip); // RESTORE } }
From source file:volumesculptor.shell.Main.java
/** * Stops execution and shows a grid. TODO: How to make it stop? * <p/>/*from ww w .j a v a 2s. co m*/ * This method is defined as a JavaScript function. */ public static void show(Context cx, Scriptable thisObj, Object[] args, Function funObj) { printf("show()\n"); AttributeGrid grid = null; boolean show_slices = false; if (args.length > 0) { if (args[0] instanceof Boolean) { show_slices = (Boolean) args[0]; } else if (args[0] instanceof AttributeGrid) { grid = (AttributeGrid) args[0]; } else if (args[0] instanceof NativeJavaObject) { grid = (AttributeGrid) ((NativeJavaObject) args[0]).unwrap(); } } if (grid == null) { System.out.println("No grid specified"); } if (args.length > 1) { if (args[1] instanceof Boolean) { show_slices = (Boolean) args[0]; } } double vs = grid.getVoxelSize(); if (show_slices) { SlicesWriter slicer = new SlicesWriter(); slicer.setFilePattern("/tmp/slices2/slice_%03d.png"); slicer.setCellSize(5); slicer.setVoxelSize(4); slicer.setMaxAttributeValue(AbFab3DGlobal.maxAttribute); try { slicer.writeSlices(grid); } catch (IOException ioe) { ioe.printStackTrace(); } } System.out.println("Saving world: " + grid + " to triangles"); Object smoothing_width = thisObj.get(AbFab3DGlobal.SMOOTHING_WIDTH_VAR, thisObj); Object error_factor = thisObj.get(AbFab3DGlobal.ERROR_FACTOR_VAR, thisObj); Object min_volume = thisObj.get(AbFab3DGlobal.MESH_MIN_PART_VOLUME_VAR, thisObj); Object max_parts = thisObj.get(AbFab3DGlobal.MESH_MAX_PART_COUNT_VAR, thisObj); printf("max_parts: %s\n", max_parts); double sw; double ef; double mv; int mp; if (smoothing_width instanceof Number) { sw = ((Number) smoothing_width).doubleValue(); } else { sw = AbFab3DGlobal.smoothingWidthDefault; } if (smoothing_width instanceof Number) { ef = ((Number) error_factor).doubleValue(); } else { ef = AbFab3DGlobal.errorFactorDefault; } if (min_volume instanceof Number) { mv = ((Number) min_volume).doubleValue(); } else { mv = AbFab3DGlobal.minimumVolumeDefault; } if (max_parts instanceof Number) { mp = ((Number) max_parts).intValue(); } else { mp = AbFab3DGlobal.maxPartsDefault; } double maxDecimationError = ef * vs * vs; // Write out the grid to an STL file MeshMakerMT meshmaker = new MeshMakerMT(); meshmaker.setBlockSize(AbFab3DGlobal.blockSizeDefault); meshmaker.setThreadCount(Runtime.getRuntime().availableProcessors()); meshmaker.setSmoothingWidth(sw); meshmaker.setMaxDecimationError(maxDecimationError); meshmaker.setMaxDecimationCount(AbFab3DGlobal.maxDecimationCountDefault); meshmaker.setMaxAttributeValue(AbFab3DGlobal.maxAttribute); IndexedTriangleSetBuilder its = new IndexedTriangleSetBuilder(160000); meshmaker.makeMesh(grid, its); System.out.println("Vertices: " + its.getVertexCount() + " faces: " + its.getFaceCount()); if (its.getFaceCount() > AbFab3DGlobal.MAX_TRIANGLE_SIZE) { System.out.println("Maximum triangle count exceeded: " + its.getFaceCount()); throw Context.reportRuntimeError("Maximum triangle count exceeded. Max is: " + AbFab3DGlobal.MAX_TRIANGLE_SIZE + " count is: " + its.getFaceCount()); } WingedEdgeTriangleMesh mesh = new WingedEdgeTriangleMesh(its.getVertices(), its.getFaces()); System.out.println("Mesh Min Volume: " + mv + " max Parts: " + mp); if (mv > 0 || mp < Integer.MAX_VALUE) { ShellResults sr = app.common.GridSaver.getLargestShells(mesh, mp, mv); mesh = sr.getLargestShell(); int regions_removed = sr.getShellsRemoved(); System.out.println("Regions removed: " + regions_removed); } try { String outputType = AbFab3DGlobal.getOutputType(); if (outputType.equals("x3d")) { String path = AbFab3DGlobal.getOutputFolder(); String name = "save.x3d";//AbFab3DGlobal.getOutputName(); String out = path + "/" + name; double[] bounds_min = new double[3]; double[] bounds_max = new double[3]; grid.getGridBounds(bounds_min, bounds_max); double max_axis = Math.max(bounds_max[0] - bounds_min[0], bounds_max[1] - bounds_min[1]); max_axis = Math.max(max_axis, bounds_max[2] - bounds_min[2]); double z = 2 * max_axis / Math.tan(Math.PI / 4); float[] pos = new float[] { 0, 0, (float) z }; GridSaver.writeMesh(mesh, out); X3DViewer.viewX3DOM(name, pos); } else if (outputType.equals("stl")) { STLWriter stl = new STLWriter( AbFab3DGlobal.getOutputFolder() + "/" + AbFab3DGlobal.getInputFileName() + ".stl"); mesh.getTriangles(stl); stl.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:com.facebook.presto.operator.scalar.MathFunctions.java
@Description("tangent") @ScalarFunction//from w w w . ja va 2s . c o m @SqlType(StandardTypes.DOUBLE) public static double tan(@SqlType(StandardTypes.DOUBLE) double num) { return Math.tan(num); }
From source file:Geometry.java
/** * Create the geometry for an unrotated, unskewed ellipse. * Integer domain./*w ww.j ava2 s.c o m*/ * * @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 int[] createEllipse(int x0, int y0, int dx, int dy) { // Make sure deltas are positive dx = Math.abs(dx); dy = Math.abs(dy); // This is an approximate number of points we need to make a smooth // surface on a quater of the ellipse int nPoints = dx > dy ? dx : dy; nPoints /= 2; if (nPoints < 1) nPoints = 1; // Allocate arrays for holding the complete set of vertices around // the ellipse. Note that this is a complete ellipse: First and last // point coincide. int[] ellipse = new int[nPoints * 8 + 2]; // Compute some intermediate results to save time in the inner loop int dxdy = dx * dy; int dx2 = dx * dx; int 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; int xi = (int) (x + 0.5); int yi = (int) (y + 0.5); ellipse[(nPoints * 0 + i) * 2 + 0] = x0 + xi; ellipse[(nPoints * 2 - i) * 2 + 0] = x0 - xi; ellipse[(nPoints * 2 + i) * 2 + 0] = x0 - xi; ellipse[(nPoints * 4 - i) * 2 + 0] = x0 + xi; ellipse[(nPoints * 0 + i) * 2 + 1] = y0 - yi; ellipse[(nPoints * 2 - i) * 2 + 1] = y0 - yi; ellipse[(nPoints * 2 + i) * 2 + 1] = y0 + yi; ellipse[(nPoints * 4 - i) * 2 + 1] = y0 + yi; } return ellipse; }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** SQL <code>COT</code> operator applied to long values. */ public static double cot(long b0) { return 1.0d / Math.tan(b0); }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** SQL <code>COT</code> operator applied to BigDecimal values. */ public static double cot(BigDecimal b0) { return 1.0d / Math.tan(b0.doubleValue()); }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** SQL <code>COT</code> operator applied to double values. */ public static double cot(double b0) { return 1.0d / Math.tan(b0); }
From source file:uk.org.openeyes.BiometryFunctions.java
/** * * @param axialLength -- Axial length/*from w w w. ja va 2 s .c o m*/ * @param r1 -- Radius of curvature 1 * @param r2 -- Radius of curvature 2 * @param acd -- Optical anterior chamber depth * @param lens -- lens object containing IOL data * @param dioptresRefraction -- Target refraction or power of IOL * @param resultType -- Result is either IOL power (IOL) or predicted refraction (REF) * @return -- Refractive power in Dioptres */ public double calculateHofferQ(double axialLength, double r1, double r2, double acd, BiometryLensData lens, double dioptresRefraction, String resultType) { // Constants double n = 1.3375; // Refractive index of cornea with fudge factor for converting radius of curvature to dioptric power double vd = 12.0; // Vertex distance String calculationComments = "HofferQ formula calculation has been called\n"; // comments for debug double returnPower; // the return value // Calculate average radius of curvature and corneal power in dioptres double averageRadius = (r1 + r2) / 2; double dioptresCornea = (n - 1) * 1000 / averageRadius; // Calculate refractive error at corneal plane double R = dioptresRefraction / (1 - vd * dioptresRefraction / 1000); // Hoffer's factors double M, G; if (axialLength <= 23) { M = +1; G = +28; calculationComments += "Hoffer factors for AL <= 23 applied\n"; } else { M = -1; G = +23.5; calculationComments += "Hoffer factors for AL > 23 applied</br>"; } // Constrain axial length (NB used ONLY for ACD calculation and replaces ACD constraint as described in erratum) double AL = axialLength; if (AL > 31) { AL = 31; calculationComments += "Axial length constrained down to 31</br>"; } if (AL < 18.5) { AL = 18.5; calculationComments += "Axial length constrained up to 18.5</br>"; } // Predicted ACD double ACD = lens.pACDConst + 0.3 * (AL - 23.5) + Math.tan(dioptresCornea * Math.PI / 180) * Math.tan(dioptresCornea * Math.PI / 180) + 0.1 * M * (23.5 - AL) * (23.5 - AL) * Math.tan(Math.PI * (0.1 * (G - AL) * (G - AL)) / 180) - 0.99166; // IOL power // TODO: need to check if we need to use the original Axial Lenght here or the constrained AL? if (resultType.equals("IOL")) { returnPower = 1336 / (axialLength - ACD - 0.05) - 1.336 / ((1.336 / (dioptresCornea + R)) - (ACD + 0.05) / 1000); } // Predicted refraction else { R = (1.336 / (1.336 / (1336 / (axialLength - ACD - 0.05) - dioptresRefraction) + (ACD + 0.05) / 1000)) - dioptresCornea; returnPower = R / (1 + vd * R / 1000); } return returnPower; }
From source file:org.n52.v3d.terrainserver.povraywts.WebTerrainServlet.java
private double determineDefaultDistance(VgElevationGrid pTerrain, double pLambda, double pExaggeration, double lFovy) { // 1. VsSimpleScene instanzieren und Relief setzen VsSimpleScene lScene = new PovrayScene(); // Statt PovrayScene knnte hier eine beliebige andere VsSimpleScene-Implementierung verwendet werden, da die // Szene nur zur Bestimmung einer Abstandsvorgabe dient... lScene.setTerrain(pTerrain);/* w w w. j av a2 s . c o m*/ lScene.setDefaultExaggeration(pExaggeration); // 2. Vorgabe-Abstand ermitteln: VgEnvelope env = this.getRotatedBBoxEnvelope(lScene.getAspect(), pLambda); boolean orthographicView = false; if (Math.abs(lFovy) < 0.001) // eigentl.: falls lFovy = 0 orthographicView = true; double radius; if (orthographicView) return -1.; // Dieser Fall ist in this.defineScene() gesondert handzuhaben... else radius = 0.5 * Math.max(env.getExtentX(), env.getExtentY()) / Math.tan(lFovy / 2. * Math.PI / 180.); return radius / lScene.getScale(); }