Example usage for java.lang Math toRadians

List of usage examples for java.lang Math toRadians

Introduction

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

Prototype

public static double toRadians(double angdeg) 

Source Link

Document

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Usage

From source file:ExtendedGeneralPath.java

/**
 * Adds an elliptical arc, defined by two radii, an angle from the
 * x-axis, a flag to choose the large arc or not, a flag to
 * indicate if we increase or decrease the angles and the final
 * point of the arc./*  w w  w.java 2s.  c  o  m*/
 *
 * @param rx the x radius of the ellipse
 * @param ry the y radius of the ellipse
 *
 * @param angle the angle from the x-axis of the current
 * coordinate system to the x-axis of the ellipse in degrees.
 *
 * @param largeArcFlag the large arc flag. If true the arc
 * spanning less than or equal to 180 degrees is chosen, otherwise
 * the arc spanning greater than 180 degrees is chosen
 *
 * @param sweepFlag the sweep flag. If true the line joining
 * center to arc sweeps through decreasing angles otherwise it
 * sweeps through increasing angles
 *
 * @param x the absolute x coordinate of the final point of the arc.
 * @param y the absolute y coordinate of the final point of the arc.
 */
public synchronized void arcTo(float rx, float ry, float angle, boolean largeArcFlag, boolean sweepFlag,
        float x, float y) {

    // Ensure radii are valid
    if (rx == 0 || ry == 0) {
        lineTo(x, y);
        return;
    }

    checkMoveTo(); // check if prev command was moveto

    // Get the current (x, y) coordinates of the path
    double x0 = cx;
    double y0 = cy;
    if (x0 == x && y0 == y) {
        // If the endpoints (x, y) and (x0, y0) are identical, then this
        // is equivalent to omitting the elliptical arc segment entirely.
        return;
    }

    Arc2D arc = computeArc(x0, y0, rx, ry, angle, largeArcFlag, sweepFlag, x, y);
    if (arc == null)
        return;

    AffineTransform t = AffineTransform.getRotateInstance(Math.toRadians(angle), arc.getCenterX(),
            arc.getCenterY());
    Shape s = t.createTransformedShape(arc);
    path.append(s, true);

    makeRoom(7);
    types[numSeg++] = ExtendedPathIterator.SEG_ARCTO;
    values[numVals++] = rx;
    values[numVals++] = ry;
    values[numVals++] = angle;
    values[numVals++] = largeArcFlag ? 1 : 0;
    values[numVals++] = sweepFlag ? 1 : 0;
    cx = values[numVals++] = x;
    cy = values[numVals++] = y;
}

From source file:uk.ac.diamond.scisoft.ncd.rcp.reduction.LazyNcdProcessingTest.java

@BeforeClass
public static void initLazyNcdProcessing() throws Exception {

    testScratchDirectoryName = TestUtils
            .generateDirectorynameFromClassname(LazyNcdProcessingTest.class.getCanonicalName());
    TestUtils.makeScratchDirectory(testScratchDirectoryName);
    filename = testScratchDirectoryName + "ncd_processing_test.nxs";
    bgFilename = testScratchDirectoryName + "ncd_bg_test.nxs";

    String testFileFolder = TestUtils.getGDALargeTestFilesLocation();
    if (testFileFolder == null) {
        Assert.fail("TestUtils.getGDALargeTestFilesLocation() returned null - test aborted");
    }/*from  w ww . jav  a2s  .  com*/

    Path bgPath = new Path(testFileFolder + "NCDReductionTest/i22-24132.nxs");
    Path drPath = new Path(testFileFolder + "NCDReductionTest/i22-24125.nxs");
    Path inputPath = new Path(testFileFolder + "NCDReductionTest/i22-24139.nxs");

    FileInputStream inFile = new FileInputStream(inputPath.toOSString());
    FileOutputStream outFile = new FileOutputStream(filename);

    IOUtils.copy(inFile, outFile);

    inFile = new FileInputStream(bgPath.toOSString());
    outFile = new FileOutputStream(bgFilename);

    IOUtils.copy(inFile, outFile);

    drFile = drPath.toOSString();

    flags = new NcdReductionFlags();
    flags.setEnableNormalisation(true);
    flags.setEnableBackground(true);
    flags.setEnableDetectorResponse(true);
    flags.setEnableSector(true);
    flags.setEnableRadial(true);
    flags.setEnableAzimuthal(true);
    flags.setEnableFastintegration(false);
    flags.setEnableInvariant(true);
    flags.setEnableAverage(true);
    flags.setEnableSaxs(true);
    flags.setEnableWaxs(false);

    ncdDetectors = new NcdDetectors();
    ncdDetectors.setDetectorSaxs(detector);
    ncdDetectors.setDetectorWaxs(null);
    ncdDetectors.setPxSaxs(pxSaxs);
    ncdDetectors.setPxWaxs(null);

    intSector = new SectorROI(262.0, 11.0, 20.0, 500.0, Math.toRadians(60.0), Math.toRadians(120.0));
    intPoints = intSector.getIntRadius(1) - intSector.getIntRadius(0);
    azPoints = (int) Math.ceil((intSector.getAngle(1) - intSector.getAngle(0)) * intSector.getRadius(1));
    framesSec = new long[] { 1, lastFrame - firstFrame + 1, intPoints };
    framesSecAz = new long[] { 1, lastFrame - firstFrame + 1, azPoints };
    framesInv = new long[] { 1, lastFrame - firstFrame + 1 };
    framesAve = new long[] { 1, 1, intPoints };
    framesBg = new long[] { 1, 1, intPoints };

    testClass = new LazyNcdProcessing();
    testClass.setBgFile(bgFilename);
    testClass.setDrFile(drFile);
    testClass.setAbsScaling(absScaling);
    testClass.setBgDetector(detectorBg);
    testClass.setBgScaling(bgScaling);
    testClass.setFirstFrame(firstFrame);
    testClass.setLastFrame(lastFrame);
    testClass.setCalibration(calibration);
    testClass.setNormChannel(normChannel);
    testClass.setCrb(crb);
    testClass.setEnableMask(enableMask);
    testClass.setFlags(flags);
    testClass.setIntSector(intSector);
    testClass.setMask(mask);
    testClass.setNcdDetectors(ncdDetectors);

    testbgClass = new LazyNcdProcessing();
    testbgClass.setDrFile(drFile);
    testbgClass.setAbsScaling(absScaling);
    testbgClass.setFirstFrame(bgFirstFrame);
    testbgClass.setLastFrame(bgLastFrame);
    testbgClass.setFrameSelection(bgFrameSelection);
    testbgClass.setCalibration(calibration);
    testbgClass.setNormChannel(normChannel);
    testbgClass.setCrb(crb);
    testbgClass.setEnableMask(enableMask);

    flags.setEnableBackground(false);
    flags.setEnableInvariant(false);
    testbgClass.setFlags(flags);

    testbgClass.setIntSector(intSector);
    testbgClass.setMask(mask);

    testbgClass.setNcdDetectors(ncdDetectors);

    DataSliceIdentifiers dr_id = NcdNexusUtilsTest.readDataId(drFile, detector, "data", null)[0];
    SliceSettings drSlice = new SliceSettings(drFrames, 1, 1);
    int[] start = new int[] { 0, 0, 0, 0 };
    drSlice.setStart(start);
    dr = NcdNexusUtils.sliceInputData(drSlice, dr_id);

    testbgClass.configure(detector, dim, bgFilename, new NullProgressMonitor());
    testbgClass.execute(new NullProgressMonitor());
    testbgClass.complete();

    testClass.configure(detector, dim, filename, new NullProgressMonitor());
    testClass.execute(new NullProgressMonitor());
    testClass.complete();
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.function.MapToPolarAndIntegrate.java

/**
 * @param x//  w  w  w . j  av  a 2  s. co  m
 * @param y
 * @param sr
 * @param sp
 * @param er
 * @param ep
 * @param isDegrees
 */
public MapToPolarAndIntegrate(double x, double y, double sr, double sp, double er, double ep, double dpp,
        boolean isDegrees) {
    cx = x;
    cy = y;

    srad = sr;
    erad = er;

    this.dpp = dpp;

    if (isDegrees) {
        sphi = Math.toRadians(sp);
        ephi = Math.toRadians(ep);
    } else {
        sphi = sp;
        ephi = ep;
    }

    if (sphi > ephi) {
        double tphi = sphi;
        sphi = ephi;
        ephi = tphi;
    }
}

From source file:pl.mg6.newmaps.demo.MarkersExampleActivity.java

private void addColorfulMarkersCircle(GoogleMap map) {
    for (int degree = 9; degree < 360; degree += 18) {
        double rad = Math.toRadians(degree);

        LatLng position = new LatLng(30.0 * Math.cos(rad), 20.0 * Math.sin(rad));
        BitmapDescriptor icon = BitmapDescriptorFactory.defaultMarker(degree);
        boolean draggable = true;
        MarkerOptions options = new MarkerOptions().position(position).icon(icon).draggable(draggable);

        Marker marker = map.addMarker(options);
        data.put(marker, "value (" + degree + ")");
    }/*from  w  w  w.  jav a 2  s  .co m*/
}

From source file:ImageProcessingTest.java

public ImageProcessingFrame() {
    setTitle("ImageProcessingTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    add(new JComponent() {
        public void paintComponent(Graphics g) {
            if (image != null)
                g.drawImage(image, 0, 0, null);
        }/* w w  w .  java 2  s  .  c om*/
    });

    JMenu fileMenu = new JMenu("File");
    JMenuItem openItem = new JMenuItem("Open");
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            openFile();
        }
    });
    fileMenu.add(openItem);

    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
    fileMenu.add(exitItem);

    JMenu editMenu = new JMenu("Edit");
    JMenuItem blurItem = new JMenuItem("Blur");
    blurItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            float weight = 1.0f / 9.0f;
            float[] elements = new float[9];
            for (int i = 0; i < 9; i++)
                elements[i] = weight;
            convolve(elements);
        }
    });
    editMenu.add(blurItem);

    JMenuItem sharpenItem = new JMenuItem("Sharpen");
    sharpenItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            float[] elements = { 0.0f, -1.0f, 0.0f, -1.0f, 5.f, -1.0f, 0.0f, -1.0f, 0.0f };
            convolve(elements);
        }
    });
    editMenu.add(sharpenItem);

    JMenuItem brightenItem = new JMenuItem("Brighten");
    brightenItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            float a = 1.1f;
            // float b = 20.0f;
            float b = 0;
            RescaleOp op = new RescaleOp(a, b, null);
            filter(op);
        }
    });
    editMenu.add(brightenItem);

    JMenuItem edgeDetectItem = new JMenuItem("Edge detect");
    edgeDetectItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            float[] elements = { 0.0f, -1.0f, 0.0f, -1.0f, 4.f, -1.0f, 0.0f, -1.0f, 0.0f };
            convolve(elements);
        }
    });
    editMenu.add(edgeDetectItem);

    JMenuItem negativeItem = new JMenuItem("Negative");
    negativeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            short[] negative = new short[256 * 1];
            for (int i = 0; i < 256; i++)
                negative[i] = (short) (255 - i);
            ShortLookupTable table = new ShortLookupTable(0, negative);
            LookupOp op = new LookupOp(table, null);
            filter(op);
        }
    });
    editMenu.add(negativeItem);

    JMenuItem rotateItem = new JMenuItem("Rotate");
    rotateItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (image == null)
                return;
            AffineTransform transform = AffineTransform.getRotateInstance(Math.toRadians(5),
                    image.getWidth() / 2, image.getHeight() / 2);
            AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);
            filter(op);
        }
    });
    editMenu.add(rotateItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    setJMenuBar(menuBar);
}

From source file:com.alvermont.terraj.planet.project.MercatorProjection.java

/**
 * Carry out the projection/*ww w  .j  a v a 2s. com*/
 */
public void project() {
    setcolours();

    final int width = getParameters().getProjectionParameters().getWidth();
    final int height = getParameters().getProjectionParameters().getHeight();

    final double lat = getParameters().getProjectionParameters().getLatitudeRadians();
    final double lon = getParameters().getProjectionParameters().getLongitudeRadians();

    final double scale = getParameters().getProjectionParameters().getScale();

    final double hgrid = getParameters().getProjectionParameters().getHgrid();
    final double vgrid = getParameters().getProjectionParameters().getVgrid();

    final boolean doShade = getParameters().getProjectionParameters().isDoShade();

    cacheParameters();

    colours = new short[width][height];
    shades = new short[width][height];

    double y;
    double scale1;
    double cos2;
    double theta1;
    int i;
    int j;
    int k;

    y = Math.sin(lat);
    y = (1.0 + y) / (1.0 - y);
    y = 0.5 * Math.log(y);
    k = (int) ((0.5 * y * width * scale) / Math.PI);

    progress.progressStart(height, "Generating Terrain");

    for (j = 0; j < height; ++j) {
        //            if (debug && ((j % (Height/25)) == 0))
        //            {fprintf(stderr, "%c", view); fflush(stderr);}
        progress.progressStep(j);

        y = (Math.PI * ((2.0 * (j - k)) - height)) / width / scale;
        y = Math.exp(2. * y);
        y = (y - 1.) / (y + 1.);

        scale1 = (scale * width) / height / Math.sqrt(1.0 - (y * y)) / Math.PI;

        cos2 = Math.sqrt(1.0 - (y * y));
        depth = (3 * ((int) (log2(scale1 * height)))) + 3;

        for (i = 0; i < width; ++i) {
            theta1 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * i) - width)) / width / scale);
            colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2);

            if (doShade) {
                shades[i][j] = shade;
            }
        }
    }

    progress.progressComplete("Terrain Generated");

    if (hgrid != 0.0) {
        /* draw horizontal gridlines */
        for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid)
            ;

        for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) {
            y = Math.sin(Math.toRadians(theta1));
            y = (1.0 + y) / (1.0 - y);
            y = 0.5 * Math.log(y);
            j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k;

            if ((j >= 0) && (j < height)) {
                for (i = 0; i < width; ++i)
                    colours[i][j] = BLACK;
            }
        }
    }

    if (vgrid != 0.0) {
        /* draw vertical gridlines */
        for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid)
            ;

        for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) {
            i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI)));

            if ((i >= 0) && (i < width)) {
                for (j = 0; j < height; ++j)
                    colours[i][j] = BLACK;
            }
        }
    }

    if (doShade) {
        smoothshades();
    }
}

From source file:org.apache.drill.exec.fn.impl.TestNewMathFunctions.java

@Test
public void testExtendedMathFunc() throws Throwable {
    final BigDecimal d = new BigDecimal(
            "100111111111111111111111111111111111.00000000000000000000000000000000000000000000000000001");
    final Object[] expected = new Object[] { Math.cbrt(1000), Math.log(10), Math.log10(5),
            (Math.log(64.0) / Math.log(2.0)), Math.exp(10), Math.toDegrees(0.5), Math.toRadians(45.0), Math.PI,
            Math.cbrt(d.doubleValue()), Math.log(d.doubleValue()), (Math.log(d.doubleValue()) / Math.log(2)),
            Math.exp(d.doubleValue()), Math.toDegrees(d.doubleValue()), Math.toRadians(d.doubleValue()) };
    runTest(expected, "functions/testExtendedMathFunctions.json");
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java

/**
 * data provider generator for single-value tests
 * @return data/*from  w ww. ja v  a  2s  .co  m*/
 */
@DataProvider
public static Object[] singlevaluegenerate() {
    return Stream.concat(

            singlevaluetestcase(

                    Stream.of(2.5, 9.1, 111.7, 889.9),

                    Stream.of(CNextPrime.class),

                    (i) -> (double) Primes.nextPrime(i.intValue())),

            singlevaluetestcase(

                    Stream.of(-2, -6, 4, -1, -5, 3, 49, 30, 6, 5, 1.3, 2.8, 9.7, 1, 8, 180, Math.PI),

                    Stream.of(CAbs.class, CACos.class, CASin.class, CATan.class, CCeil.class, CCos.class,
                            CCosh.class, CDegrees.class, CExp.class, CIsPrime.class, CLog.class, CLog10.class,
                            CFloor.class, CRadians.class, CRound.class, CSignum.class, CSin.class, CSinh.class,
                            CSqrt.class, CTan.class, CTanh.class),

                    (i) -> Math.abs(i.doubleValue()), (i) -> Math.acos(i.doubleValue()),
                    (i) -> Math.asin(i.doubleValue()), (i) -> Math.atan(i.doubleValue()),
                    (i) -> Math.ceil(i.doubleValue()), (i) -> Math.cos(i.doubleValue()),
                    (i) -> Math.cosh(i.doubleValue()), (i) -> Math.toDegrees(i.doubleValue()),
                    (i) -> Math.exp(i.doubleValue()), (i) -> Primes.isPrime(i.intValue()),
                    (i) -> Math.log(i.doubleValue()), (i) -> Math.log10(i.doubleValue()),
                    (i) -> Math.floor(i.doubleValue()), (i) -> Math.toRadians(i.doubleValue()),
                    (i) -> Math.round(i.doubleValue()), (i) -> Math.signum(i.doubleValue()),
                    (i) -> Math.sin(i.doubleValue()), (i) -> Math.sinh(i.doubleValue()),
                    (i) -> Math.sqrt(i.doubleValue()), (i) -> Math.tan(i.doubleValue()),
                    (i) -> Math.tanh(i.doubleValue()))

    ).toArray();
}

From source file:com.hangulo.powercontact.util.Utils.java

public static double getDistanceX(double here_lat, double here_lng, double lat, double lng) {

    final double sinLat = Math.sin(Math.toRadians(lat));
    final double cosLat = Math.cos(Math.toRadians(lat));
    final double sinLng = Math.sin(Math.toRadians(lng));
    final double cosLng = Math.cos(Math.toRadians(lng));

    return cosLat * Math.cos(Math.toRadians(here_lat))
            * (Math.cos(Math.toRadians(here_lng)) * cosLng + (Math.sin(Math.toRadians(here_lng)) * sinLng))
            + sinLat * (Math.sin(Math.toRadians(here_lat)));
}

From source file:org.rifidi.designer.library.retail.shelf.Shelf.java

@Override
public void init() {
    prepare();/*from  ww w .j  a  v  a  2  s.  c  o  m*/
    Node mainNode = new Node();
    mainNode.setModelBound(new BoundingBox());
    Node node = new Node("maingeometry");
    node.setModelBound(new BoundingBox());
    mainNode.attachChild(node);

    model.setLocalTranslation(new Vector3f(0, 3.7f, 0));
    model.setLocalScale(5.0f);
    model.setLocalRotation(new Quaternion(new float[] { (float) Math.toRadians(270), 0, 0 }));
    node.attachChild(model);
    setNode(mainNode);
    getNode().updateGeometricState(0f, true);
    getNode().updateModelBound();

    Node _node = new Node("hiliter");
    Box box = new Box("hiliter", ((BoundingBox) getNode().getWorldBound()).getCenter().clone()
            .subtractLocal(getNode().getLocalTranslation()).add(new Vector3f(0, 2, 0)), 4f, 4f, 1f);
    box.setModelBound(new BoundingBox());
    box.updateModelBound();
    _node.attachChild(box);
    _node.setModelBound(new BoundingBox());
    _node.updateModelBound();
    _node.setCullHint(CullHint.Always);
    getNode().attachChild(_node);
}