Example usage for java.lang Math tan

List of usage examples for java.lang Math tan

Introduction

In this page you can find the example usage for java.lang Math tan.

Prototype

@HotSpotIntrinsicCandidate
public static double tan(double a) 

Source Link

Document

Returns the trigonometric tangent of an angle.

Usage

From source file:EnvironmentExplorer.java

public void init() {
    // initialize the code base
    try {/* w w  w .j ava 2  s  .  c o  m*/
        java.net.URL codeBase = getCodeBase();
        codeBaseString = codeBase.toString();
    } catch (Exception e) {
        // probably running as an application, try the application
        // code base
        codeBaseString = "file:./";
    }

    if (colorMode == USE_COLOR) {
        objColor = red;
    } else {
        objColor = white;
    }

    Container contentPane = getContentPane();

    contentPane.setLayout(new BorderLayout());

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    canvas = new Canvas3D(config);

    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 *= OFF_SCREEN_SCALE;
        dim.height *= OFF_SCREEN_SCALE;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * OFF_SCREEN_SCALE);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * OFF_SCREEN_SCALE);

        // attach the offscreen canvas to the view
        u.getViewer().getView().addCanvas3D(offScreenCanvas);

    }
    contentPane.add("Center", canvas);

    // setup the env nodes and their GUI elements
    setupLights();
    setupBackgrounds();
    setupFogs();
    setupSounds();

    // 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 -4 -> 4 range
    double viewRadius = 4.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.STOP_ZOOM);
    orbit.setSchedulingBounds(infiniteBounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    contentPane.add("East", guiPanel());
}

From source file:org.geosdi.geoplatform.services.GPWMSServiceImpl.java

private double latToSphericalMercatorY(double y) {
    if (y > 85.05112) {
        y = 85.05112;/*  ww w  .  j a  v a  2s  . c o  m*/
    }

    if (y < -85.05112) {
        y = -85.05112;
    }

    y = (Math.PI / 180.0) * y;
    double tmp = Math.PI / 4.0 + y / 2.0;
    return 20037508.34 * Math.log(Math.tan(tmp)) / Math.PI;
}

From source file:au.org.ala.biocache.web.WMSController.java

double convertLatToMeters(double lat) {
    return 6378137.0 * Math.log(Math.tan(Math.PI / 180 * (45 + lat / 2.0)));
}

From source file:uk.ac.diamond.scisoft.analysis.diffraction.PowderRingsUtils.java

/**
 * Fit ellipses to a single detector with/without fixing wavelength.
 * <p>//w  ww . j av a  2s .c om
 * Combinations of spacings are used to fit the ellipses (if there are more ellipses than spacings then
 * the outer ellipses are used)
 * @param mon
 * @param detector
 * @param env
 * @param ellipses
 * @param spacings
 *            a list of possible spacings
 * @param fixedWavelength 
 * @return q-space
 */
public static QSpace fitEllipsesToQSpace(IMonitor mon, DetectorProperties detector,
        DiffractionCrystalEnvironment env, List<EllipticalROI> ellipses, List<HKL> spacings,
        boolean fixedWavelength) {

    int n = ellipses.size();

    double dmax = spacings.get(0).getD().doubleValue(NonSI.ANGSTROM);
    {
        double rmin = detector.getDetectorDistance()
                * Math.tan(2.0 * Math.asin(0.5 * env.getWavelength() / dmax)) / detector.getVPxSize();
        int l = 0;
        for (EllipticalROI e : ellipses) {
            if (e.getSemiAxis(0) > rmin)
                break;
            l++;
        }

        if (l >= n) {
            throw new IllegalArgumentException("Maybe all rings are too small!");
        }
        if (l > 0) {
            logger.debug("Discarding first {} rings", l);
            ellipses = ellipses.subList(l, n);
            n = ellipses.size();
        }
    }

    if (n >= spacings.size()) { // always allow a choice to be made
        int l = n - spacings.size();
        logger.warn("The number of d-spacings ({}) should be greater than or equal to {}: using outer rings", l,
                n - 1);
        ellipses = ellipses.subList(l + 1, n);
        n = ellipses.size();
    }
    logger.debug("Using {} rings:", n);
    boolean allCircles = true;
    for (int i = 0; i < n; i++) {
        EllipticalROI e = ellipses.get(i);
        logger.debug("    {}", e);
        if (allCircles && !e.isCircular()) {
            allCircles = false;
        }
    }

    DetectorFitFunction f;
    if (allCircles) {
        logger.debug("All rings are circular");
        f = createQFitFunction4(ellipses, detector, env.getWavelength(), fixedWavelength);
    } else {
        f = createQFitFunction7(ellipses, detector, env.getWavelength(), fixedWavelength);
    }

    logger.debug("Init: {}", f.getInitial());

    // set up a combination generator for all
    List<Double> s = new ArrayList<Double>();
    for (int i = 0, imax = spacings.size(); i < imax; i++) {
        HKL d = spacings.get(i);
        s.add(d.getD().doubleValue(NonSI.ANGSTROM));
    }
    CombinationGenerator<Double> gen = new CombinationGenerator<Double>(s, n);
    if (mon != null) {
        mon.worked(1);
    }
    logger.debug("There are {} combinations", gen.getTotalCombinations());

    double min = Double.POSITIVE_INFINITY;

    MultivariateOptimizer opt = FittingUtils.createOptimizer(f.getN());

    // opt.setMaxEvaluations(2000);
    List<Double> fSpacings = null;

    int i = 0;
    for (List<Double> list : gen) { // find combination that minimizes residuals
        f.setSpacings(list);
        double res = FittingUtils.optimize(f, opt, min);
        if (res < min) {
            min = res;
            fSpacings = list;
        }
        //         System.err.printf(".");
        if (mon != null) {
            mon.worked(10);
            if (mon.isCancelled())
                return null;
        }
        if (i++ == 100) {
            //            System.err.printf("\n");
            i = 0;
        }
    }
    //      System.err.printf("\n");

    if (fSpacings == null || f.getParameters() == null) {
        logger.warn("Problem with fitting - as could not find a single fit!");
        return null;
    }

    logger.debug("Parameters: w {}, D {}, e {} (min {})",
            new Object[] { f.getWavelength(), f.getDistance(), f.getNormalAngles(), min });
    logger.debug("Spacings used: {}", fSpacings);
    f.setSpacings(fSpacings);
    logger.debug("Residual value: {}", f.value(f.getParameters()));

    QSpace q = new QSpace(f.getDetectorProperties().get(0).clone(),
            new DiffractionCrystalEnvironment(f.getWavelength()));
    q.setResidual(f.value(f.getParameters()));
    return q;
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void fillPolygon(PolygonRenderEvent pre) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(pre);// w w w .  j a  v a  2s .c  om
    }
    final Fill flBackground = validateMultipleFill(pre.getBackground());

    if (isFullTransparent(flBackground)) {
        return;
    }

    final Location[] loa = pre.getPoints();
    final int[][] i2a = getCoordinatesAsInts(loa);

    if (flBackground instanceof ColorDefinition) {
        final ColorDefinition cd = (ColorDefinition) flBackground;
        _g2d.setColor((Color) _ids.getColor(cd));
        _g2d.fill(getPolygon(loa));
    } else if (flBackground instanceof Gradient) {
        final Gradient g = (Gradient) flBackground;
        final ColorDefinition cdStart = g.getStartColor();
        final ColorDefinition cdEnd = g.getEndColor();
        // final boolean bRadial = g.isCyclic();
        final double dAngleInDegrees = g.getDirection();
        final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0);
        // final int iAlpha = g.getTransparency();

        final double dMinX = BaseRenderer.getX(loa, IConstants.MIN);
        final double dMaxX = BaseRenderer.getX(loa, IConstants.MAX);
        final double dMinY = BaseRenderer.getY(loa, IConstants.MIN);
        final double dMaxY = BaseRenderer.getY(loa, IConstants.MAX);

        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(dMinX, dMaxY);
            p2dEnd = new Point2D.Double(dMinX, dMinY);
        } else if (dAngleInDegrees == -90) {
            p2dStart = new Point2D.Double(dMinX, dMinY);
            p2dEnd = new Point2D.Double(dMinX, dMaxY);
        } else if (dAngleInDegrees > 0) {
            p2dStart = new Point2D.Double(dMinX, dMaxY);
            p2dEnd = new Point2D.Double(dMaxX, dMaxY - (dMaxX - dMinX) * Math.abs(Math.tan(dAngleInRadians)));
        } else if (dAngleInDegrees < 0) {
            p2dStart = new Point2D.Double(dMinX, dMinY);
            p2dEnd = new Point2D.Double(dMaxX, dMinY + (dMaxX - dMinX) * Math.abs(Math.tan(dAngleInRadians)));
        } else {
            p2dStart = new Point2D.Double(dMinX, dMinY);
            p2dEnd = new Point2D.Double(dMaxX, dMinY);
        }
        _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd,
                (Color) _ids.getColor(cdEnd)));
        _g2d.fill(getPolygon(loa));
    } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) {
        Area ar2 = new Area(new Polygon(i2a[0], i2a[1], loa.length));
        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 double dMinX = BaseRenderer.getX(loa, IConstants.MIN);
            final double dMaxX = BaseRenderer.getX(loa, IConstants.MAX);
            final double dMinY = BaseRenderer.getY(loa, IConstants.MIN);
            final double dMaxY = BaseRenderer.getY(loa, IConstants.MAX);
            final Size szImage = _ids.getSize(img);

            final int iXRepeat = (int) (Math.ceil((dMaxX - dMinX) / szImage.getWidth()));
            final int iYRepeat = (int) (Math.ceil((dMaxY - dMinY) / szImage.getHeight()));
            final ImageObserver io = (ImageObserver) _ids.getObserver();
            for (int i = 0; i < iXRepeat; i++) {
                for (int j = 0; j < iYRepeat; j++) {
                    _g2d.drawImage(img, (int) (dMinX + i * szImage.getWidth()),
                            (int) (dMinY + j * szImage.getHeight()), io);
                }
            }

            _g2d.setClip(shClip); // RESTORE
        }
    }
}

From source file:whitebox.stats.Kriging.java

/**
 * Draw Semivariogram surface map and also draw the search are if
 * Anisotropic//from  w  w  w.ja v  a 2  s  . c om
 *
 * @param Radius
 * @param AnIsotropic
 */
public void DrawSemivariogramSurface(double Radius, boolean AnIsotropic) {
    double[][] data = new double[3][BinSurface.length * BinSurface[0].length];
    int n = 0;
    double max = Double.MIN_VALUE;
    for (int i = 0; i < BinSurface.length; i++) {
        for (int j = 0; j < BinSurface[i].length; j++) {
            data[0][n] = BinSurface[i][j].GridHorDistance;
            data[1][n] = BinSurface[i][j].GridVerDistance;
            if ((Math.pow(data[0][n], 2) + Math.pow(data[1][n], 2)) <= Radius * Radius
                    && !Double.isNaN(BinSurface[i][j].Value)) {
                data[2][n] = BinSurface[i][j].Value;
                if (max < data[2][n]) {
                    max = data[2][n];
                }
            } else {
                data[2][n] = -1;
            }
            n++;
        }
    }
    DefaultXYZDataset dataset = new DefaultXYZDataset();
    dataset.addSeries("Value", data);
    NumberAxis xAxis = new NumberAxis();

    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(LagSize);
    renderer.setBlockHeight(LagSize);
    renderer.setBlockAnchor(RectangleAnchor.CENTER);

    LookupPaintScale paintScale = new LookupPaintScale(0, max, Color.white);
    double colorRange = max / 6;
    //double colorRange = 23013;
    paintScale.add(0.0, Color.blue);
    paintScale.add(1 * colorRange, Color.green);
    paintScale.add(2 * colorRange, Color.cyan);
    paintScale.add(3 * colorRange, Color.yellow);
    paintScale.add(4 * colorRange, Color.ORANGE);
    paintScale.add(5 * colorRange, Color.red);

    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);

    if (AnIsotropic) {
        CombinedRangeXYPlot combinedrangexyplot = new CombinedRangeXYPlot();
        XYSeries seriesT1 = new XYSeries("1");
        XYSeriesCollection AngleCollct = new XYSeriesCollection();

        double bw = BandWidth;
        double r = bw / Math.sin(Tolerance);
        if (r > Radius) {
            bw = Radius * Math.sin(Tolerance);
            r = Radius;
        }
        seriesT1.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance));

        if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) {
            if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) {
                double a = (1 + Math.pow(Math.tan(Angle), 2));
                double b = 2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2);
                double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2)
                        - Math.pow(Radius, 2);
                double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y1 = Math.tan(Angle) * (x1 + bw / Math.sin(Angle));
                double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y2 = Math.tan(Angle) * (x2 + bw / Math.sin(Angle));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));
                if (d1 < d2) {
                    seriesT1.add(x1, y1);
                } else {
                    seriesT1.add(x2, y2);
                }
            } else {
                double x1 = -bw * Math.sin(Angle);
                double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));

                if (d1 < d2) {
                    seriesT1.add(x1, y1);
                } else {
                    seriesT1.add(x1, y2);
                }
            }
        } else {
            double y1 = bw * Math.cos(Angle);
            double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
            double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));

            if (d1 < d2) {
                seriesT1.add(x1, y1);
            } else {
                seriesT1.add(x2, y1);
            }
        }

        AngleCollct.addSeries(seriesT1);

        XYSeries seriesT2 = new XYSeries("2");
        seriesT2.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance));
        seriesT2.add(0.0, 0.0);
        AngleCollct.addSeries(seriesT2);

        XYSeries seriesT3 = new XYSeries("3");
        seriesT3.add(Radius * Math.cos(Angle), Radius * Math.sin(Angle));
        seriesT3.add(0, 0);
        AngleCollct.addSeries(seriesT3);

        XYSeries seriesT4 = new XYSeries("4");
        seriesT4.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance));
        seriesT4.add(0, 0);
        AngleCollct.addSeries(seriesT4);

        XYSeries seriesT5 = new XYSeries("5");

        seriesT5.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance));
        if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) {
            if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) {
                double a = (1 + Math.pow(Math.tan(Angle), 2));
                double b = -2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2);
                double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2)
                        - Math.pow(Radius, 2);
                double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y1 = Math.tan(Angle) * (x1 - bw / Math.sin(Angle));
                double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y2 = Math.tan(Angle) * (x2 - bw / Math.sin(Angle));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));
                if (d1 < d2) {
                    seriesT5.add(x1, y1);
                } else {
                    seriesT5.add(x2, y2);
                }
            } else {
                double x1 = bw * Math.sin(Angle);
                double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));

                if (d1 < d2) {
                    seriesT5.add(x1, y1);
                } else {
                    seriesT5.add(x1, y2);
                }
            }
        } else {
            double y1 = -bw * Math.cos(Angle);
            double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
            double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));

            if (d1 < d2) {
                seriesT5.add(x1, y1);
            } else {
                seriesT5.add(x2, y1);
            }
        }
        AngleCollct.addSeries(seriesT5);
        plot.setDataset(1, AngleCollct);
        XYLineAndShapeRenderer lineshapRend = new XYLineAndShapeRenderer(true, false);
        for (int i = 0; i < AngleCollct.getSeriesCount(); i++) {
            //plot.getRenderer().setSeriesPaint(i , Color.BLUE);
            lineshapRend.setSeriesPaint(i, Color.BLACK);
        }
        plot.setRenderer(1, lineshapRend);
        combinedrangexyplot.add(plot);
    }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    JFreeChart chart = new JFreeChart("Semivariogram Surface", plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    // create and display a frame...
    ChartFrame frame = new ChartFrame("", chart);
    frame.pack();
    //frame.setSize(100, 50);
    frame.setVisible(true);
}

From source file:ViewProj.java

/**
 * Calculates the projection transform specified by the field of view and
 * clip distances specified by the view.
 *//*from   w w  w .j a v  a 2  s.c o  m*/
public void updateProjTrans() {
    int projType = view.getProjectionPolicy();
    if (projType == View.PARALLEL_PROJECTION) {
        //System.out.println("PARALLEL_PROJECTION");
        projTrans.setIdentity();
        return;
    }
    //System.out.println("PERSPECTIVE_PROJECTION");
    // figure out the perspective transform from the view
    double fov = view.getFieldOfView();

    // n = near clip
    double n = frontClipDist;
    // f = far clip
    double f = backClipDist;

    //System.out.println("n = " + nf.format(n) + " f = " + nf.format(f));

    // Create a matrix using coefficents derived from the OpenGL
    // glFrustum() man page. This assumes the eye point is a 0,0,0,
    // the front clip plane is a z = -n, the back clip plane is at
    // z = -f and that the front clip plane intersects the FOV so that
    // -1 <= X,Y <= 1 at the front plane (the last assumption may not
    // be true, so we'll scale later).
    Matrix4d matrix = new Matrix4d();
    matrix.m00 = n;
    matrix.m11 = n;
    matrix.m22 = -(f + n) / (f - n);
    matrix.m23 = -2 * f * n / (f - n);
    matrix.m32 = -1;

    //System.out.println("matrix = " + matrix);

    // This is the distance where the FOV maps to a -1 to 1 area in X and Y
    double d = 1 / Math.tan(fov / 2);

    //System.out.println("n = " + nf.format(n) + " f = " + nf.format(f) +
    //   " d = " + nf.format(d));

    // this is a scaling ratio to make the OpenGL glFrustum() matrix
    // elements work with with the J3D matrix. It compensates for the
    // front clip plane not being at the FOV distance (the OpenGL
    // matrix expects n == d).
    double scale = n / d;
    //System.out.println("scale = " + nf.format(scale));

    // scale the elements of the matrix
    //matrix.m00 *= 1.0/scale;
    //matrix.m11 *= 1.0/scale;
    matrix.m22 *= scale;
    matrix.m23 *= scale;
    matrix.m32 *= scale;

    // set the Transform3D
    projTrans.set(matrix);

    //System.out.println("projTrans = " + projTrans);
}

From source file:org.tros.utils.Random.java

/**
 * Returns a random real number from the Cauchy distribution.
 *
 * @return a random real number from the Cauchy distribution.
 *///w w w  .  java  2s. c om
public static double cauchy() {
    return Math.tan(Math.PI * (nextDouble() - 0.5));
}

From source file:org.cryptsecure.Utility.java

/**
 * Gets the tile number for OpenStreetMap.
 * // www  .  ja v a 2  s  .  com
 * @param lat
 *            the lat
 * @param lon
 *            the lon
 * @param zoom
 *            the zoom
 * @return the tile number
 */
public static String getTileNumber(double lat, double lon, final int zoom) {

    // if (zoom == 17) { //250
    // lat += 0.0002000;
    // lon -= 0.0015000;
    // // lon -= 0.001000;
    // }
    // else if (zoom == 16) { //500
    // lat += 0.0008000;
    // lon -= 0.0008000;
    // // lon -= 2*0.001000;
    // }

    int xtile = (int) Math.floor(((lon + 180) / 360) * (1 << zoom));
    int ytile = (int) Math
            .floor((1 - Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))) / Math.PI)
                    / 2 * (1 << zoom));
    if (xtile < 0)
        xtile = 0;
    if (xtile >= (1 << zoom))
        xtile = ((1 << zoom) - 1);
    if (ytile < 0)
        ytile = 0;
    if (ytile >= (1 << zoom))
        ytile = ((1 << zoom) - 1);

    return ("" + zoom + "/" + xtile + "/" + ytile);
}

From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java

/**
 * Find a new random position for the object.
 *
 * <p>We'll rotate it around the Y-axis so it's out of sight, and then up or down by a little bit.
 *//*www .  j  a va  2 s  .  c om*/
private void hideObject() {
    float[] rotationMatrix = new float[16];
    float[] posVec = new float[4];

    // First rotate in XZ plane, between 90 and 270 deg away, and scale so that we vary
    // the object's distance from the user.
    float angleXZ = (float) Math.random() * 180 + 90;
    Matrix.setRotateM(rotationMatrix, 0, angleXZ, 0f, 1f, 0f);
    float oldObjectDistance = objectDistance;
    objectDistance = (float) Math.random() * (MAX_MODEL_DISTANCE - MIN_MODEL_DISTANCE) + MIN_MODEL_DISTANCE;
    float objectScalingFactor = objectDistance / oldObjectDistance;
    Matrix.scaleM(rotationMatrix, 0, objectScalingFactor, objectScalingFactor, objectScalingFactor);
    Matrix.multiplyMV(posVec, 0, rotationMatrix, 0, modelCube, 12);

    float angleY = (float) Math.random() * 80 - 40; // Angle in Y plane, between -40 and 40.
    angleY = (float) Math.toRadians(angleY);
    float newY = (float) Math.tan(angleY) * objectDistance;

    modelPosition[0] = posVec[0];
    modelPosition[1] = newY;
    modelPosition[2] = posVec[2];

    updateModelPosition();
}