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:SplineInterpolatorTest.java

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile) {/*from w w  w. j  av  a2s .  com*/
    TransformGroup tg = new TransformGroup();

    // we need to flip the helicopter model
    // 90 degrees about the X axis
    Transform3D t3d = new Transform3D();
    t3d.rotX(Math.toRadians(-90));
    tg.setTransform(t3d);

    try {
        tg.addChild(loadGeometryGroup("heli.obj", app));

        // create an Alpha object for the Interpolator
        Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE,
                (long) Utils.getRandomNumber(0, 500), (long) Utils.getRandomNumber(0, 500),
                (long) Utils.getRandomNumber(20000, 5000), 4000, 100, (long) Utils.getRandomNumber(20000, 5000),
                5000, 50);

        attachSplinePathInterpolator(alpha, new Transform3D(),
                new URL(((Java3dApplet) m_Component).getWorkingDirectory(), "heli_spline.xls"));
    } catch (Exception e) {
        System.err.println(e.toString());
    }

    return tg;
}

From source file:lucee.runtime.img.Image.java

public void rotate(float x, float y, float angle, int interpolation) throws ExpressionException {
    if (x == -1)/*from w  w w  .  j  a v  a 2 s . c  o m*/
        x = (float) getWidth() / 2;
    if (y == -1)
        y = (float) getHeight() / 2;

    angle = (float) Math.toRadians(angle);
    ColorModel cmSource = image().getColorModel();

    if (cmSource instanceof IndexColorModel && cmSource.hasAlpha() && !cmSource.isAlphaPremultiplied()) {
        image(PaletteToARGB(image()));
        cmSource = image().getColorModel();
    }

    BufferedImage alpha = null;
    if (cmSource.hasAlpha() && !cmSource.isAlphaPremultiplied()) {
        alpha = getAlpha(image());
        image(removeAlpha(image()));
    }

    Interpolation interp = Interpolation.getInstance(0);
    if (INTERPOLATION_BICUBIC == interpolation)
        interp = Interpolation.getInstance(1);
    else if (INTERPOLATION_BILINEAR == interpolation)
        interp = Interpolation.getInstance(2);

    if (alpha != null) {
        ParameterBlock params = new ParameterBlock();
        params.addSource(alpha);
        params.add(x);
        params.add(y);
        params.add(angle);
        params.add(interp);
        params.add(new double[] { 0.0 });
        RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION,
                (RenderingHints.VALUE_INTERPOLATION_BICUBIC));
        hints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER,
                new BorderExtenderConstant(new double[] { 255.0 })));
        hints.add(new RenderingHints(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.TRUE));
        alpha = JAI.create("rotate", params, hints).getAsBufferedImage();
    }

    ParameterBlock params = new ParameterBlock();
    params.addSource(image());
    params.add(x);
    params.add(y);
    params.add(angle);
    params.add(interp);
    params.add(new double[] { 0.0 });
    BorderExtender extender = new BorderExtenderConstant(new double[] { 0.0 });
    RenderingHints hints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, extender);
    hints.add(new RenderingHints(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.TRUE));
    image(JAI.create("rotate", params, hints).getAsBufferedImage());
    if (alpha != null)
        image(addAlpha(image(), alpha, 0, 0));
}

From source file:org.deegree.tools.rendering.InteractiveWPVS.java

private ViewParams getViewParams(TerrainRenderingManager demRenderer) {
    // // setup viewer position and direction
    // // Point3d eye = new Point3d( 1169.4413, 989.9026, 331.31174 );
    // // Point3d eye = new Point3d( 15927.5, 7689, 300 );
    ////from  w w  w  . ja  va 2 s. com
    // // Vector3d viewDirection = new Vector3d( 0.72272307, 0.64145917, -0.25741702 );
    // // Point3d lookingAt = new Point3d( viewDirection );
    // // lookingAt.add( eye );
    // // Vector3d viewerUp = new Vector3d( 0.2185852, 0.14120139, 0.96556276 );
    // //
    // // Point3d eye = new Point3d( 12962.94836753434, 12593.593984246898, 90.38167030764276 );
    // // Point3d lookingAt = new Point3d( 12962.613589134678, 12594.53064243064, 90.48460169230239 );
    // // Vector3d viewerUp = new Vector3d( 0.017654201204610157, -0.10298316020337722, 0.9945408808038575 );
    //
    // // looking up the godesberger hill
    // // Point3d eye = new Point3d( 13451.07327279907, 11069.148746358578, 102.0725860674174 );
    // // Point3d lookingAt = new Point3d( 13450.82937390088, 11070.108252492108, 102.21351621742897 );
    // // Vector3d viewerUp = new Vector3d( 0.06727614458805162, -0.12823156824233176, 0.9894742800958647 );

    // Point3d eye = new Point3d( 17986.5718025168, 10445.807745848066, 29013.44152491993 );
    // Point3d lookingAt = new Point3d( 17986.5314521542, 10445.81549881379, 29012.4423694065 );
    // Vector3d viewerUp = new Vector3d( -0.0042550244648288235, 0.9999738721136294, 0.007931932463392117 );

    // hochwasser blick
    // Point3d eye = new Point3d( 12540.065339366225, 14825.06184789524, 405.8445763856689 );
    // Point3d lookingAt = new Point3d( 11778.0, 14865.0, 50.0 );
    // Vector3d viewerUp = new Vector3d( -0.42203907810090174, 0.022118130853929614, 0.9063077870366498 );

    // ls_ns_gebiet
    // Point3d eye = new Point3d( 7911.181456483806, 11214.239820576904, 298.4662832984199 );
    // Point3d lookingAt = new Point3d( 7992.0, 12138.0, 50.0 );
    // Vector3d viewerUp = new Vector3d( 0.022557566113149727, 0.2578341604962995, 0.9659258262890682 );

    // umgebungs
    // Point3d eye = new Point3d( 11646.815747933482, 18449.506280218528, 212.34068114402103 );
    // Point3d lookingAt = new Point3d( 11429.0, 18087.0, 50.0 );
    // Vector3d viewerUp = new Vector3d( -0.1845731388432743, -0.3071812879698955, 0.9335804264972021 );

    // jens
    // Point3d eye = new Point3d( 10913.308304137812, 15021.543377732793, 90.34890557577096 );
    // Point3d lookingAt = new Point3d( 10914.25310107993, 15021.218113244397, 90.30938658346824 );
    // Vector3d viewerUp = new Vector3d( 0.030261091918976406, -0.03347475349449462, 0.9989813347577329 );

    // Point3d eye = new Point3d( -73047.70146472409, 38512.120946986484, 26970.205157368593 );
    // Point3d lookingAt = new Point3d( -73046.78120268782, 38511.863489770185, 26969.910482010924 );
    // Vector3d viewerUp = new Vector3d( 0.2747903722504608, -0.11093253999688812, 0.9550833591306462 );

    // Point3d eye = new Point3d( 11795.310126271357, 14458.153190013969, 128.14202719026218 );
    // Point3d lookingAt = new Point3d( 11795.526694264807, 14459.094383967173, 127.88269680896333 );
    // Vector3d viewerUp = new Vector3d( 0.06763746981420082, 0.2505311057936102, 0.9657428942047335 );

    // // sunposition
    // Point3d eye = new Point3d( 0, 0, 7 );
    // Point3d lookingAt = new Point3d( 0, 0, 0 );
    // Vector3d viewerUp = new Vector3d( 0, 1, 0 );

    // Point3d eye = new Point3d( 14863.581689508377, 14874.257693700007, 146.73991301323542 );
    // Point3d lookingAt = new Point3d( 14864.08371028227, 14873.40329772973, 146.8740124858517 );
    // Vector3d viewerUp = new Vector3d( -0.0579411289423698, 0.12147962354586098, 0.9909013707932913 );

    // Point3d eye = new Point3d( 17183.96902170159, 11104.651411049092, 5252.299959766186 );
    // Point3d lookingAt = new Point3d( 17183.87383467913, 11104.540544537771, 5251.310693347357 );
    // Vector3d viewerUp = new Vector3d( 0.005618138084521037, -0.9938227673681405, 0.1108365624924782 );

    // schloss
    // Point3d eye = new Point3d( 9215.695465194443, 15321.819352516042, 177.70466056621308 );
    // Point3d lookingAt = new Point3d( 9215.868711190713, 15322.726799941856, 177.32187473293513 );
    // Vector3d viewerUp = new Vector3d( 0.08839715708976609, 0.37276722064380496, 0.9237047914955354 );

    // rhein
    // Point3d eye = new Point3d( 13925.753788033839, 14431.125891954574, 85.04428646818577 );
    // Point3d lookingAt = new Point3d( 13926.097992769744, 14430.235130354195, 84.74752583894274 );
    // Vector3d viewerUp = new Vector3d( 0.09598128880808184, -0.28103511759282995, 0.9548857810638757 );

    // tree_posttower
    // Point3d eye = new Point3d( 12402.045997461932, 14793.69142817672, 70.4937199211793 );
    // Point3d lookingAt = new Point3d( 12401.10002391475, 14793.382817636224, 70.39425343271608 );
    // Vector3d viewerUp = new Vector3d( -0.1033479271492392, -0.0037871342018632754, 0.9946380565655442 );

    // Point3d eye = new Point3d( 6448.260268219342, 17363.50304721038, 84.29050865858129 );
    // Point3d lookingAt = new Point3d( 6447.634642666272, 17364.28204533543, 84.33239646721954 );
    // Vector3d viewerUp = new Vector3d( 0.06425052852314768, -0.002059566706843565, 0.9979316749003633 );

    // Point3d eye = new Point3d( 350, -127, 23.7 );
    // Point3d lookingAt = new Point3d( 349.37437444693, -126.221001874950, 23.65811219136174 );
    // Vector3d viewerUp = new Vector3d( 0.06425052852314768, -0.002059566706843565, 0.9979316749003633 );

    // Point3d eye = new Point3d( 6442.004012688637, 17371.293028460885, 84.7093867449643 );
    // Point3d lookingAt = new Point3d( 6441.378387135567, 17372.072026585935, 84.75127455360256 );
    // Vector3d viewerUp = new Vector3d( 0.06425052852314768, -0.002059566706843565, 0.9979316749003633 );

    // essen gebude
    // Point3d eye = new Point3d( 5441.872284653714, 7803.240170850542, 150.8541731262849 );
    // Point3d lookingAt = new Point3d( 5441.621465393425, 7804.178715235103, 150.61705683228917 );
    // Vector3d viewerUp = new Vector3d( 0.030150645228390737, 0.2524015253189707, 0.9671527328239826 );

    // demo
    // Point3d eye = new Point3d( 7751.4274632595325, 7738.632168131135, 1700.8178651653407 );
    // Point3d lookingAt = new Point3d( 7751.506737376979, 7739.419748747671, 1700.2067740209447 );
    // Vector3d viewerUp = new Vector3d( -0.08199978679939689, 0.6160949046469247, 0.7833920496359404 );

    // Point3d eye = new Point3d( 4842.663403926125, -21159.654750781716, 24123.268156063317 );
    // Point3d lookingAt = new Point3d( 4842.742678043572, -21158.86717016518, 24122.65706491892 );
    // Vector3d viewerUp = new Vector3d( -0.081999.78679939689, 0.6160949046469247, 0.7833920496359404 );

    // Point3d eye = new Point3d( 13360.610583075291, 13759.692891781559, 8636.598222159204 );
    // Point3d lookingAt = new Point3d( 13360.078832161853, 13759.276659426903, 8635.860664301814 );
    // Vector3d viewerUp = new Vector3d( -0.7073708715804196, -0.2605954677793352, 0.6570513314895419 );

    // Point3d eye = new Point3d( 6081.839091011266, 384.75124442199444, 6432.359365945068 );
    // Point3d lookingAt = new Point3d( 6081.859440809533, 385.502735808828, 6431.699936963884 );
    // Vector3d viewerUp = new Vector3d( -0.006707700408040963, 0.6596533401191206, 0.7515400705382526 );

    // Kennedy
    // Point3d eye = new Point3d( 10394.591904069532, 17177.24388643706, 82.62293305712367 );
    // Point3d lookingAt = new Point3d( 10394.961152650601, 17176.37017540717, 82.30625574245802 );
    // Vector3d viewerUp = new Vector3d( 0.12756699054896722, -0.2898805092310912, 0.9485230378278534 );
    // Point3d eye = new Point3d( 10394.591904069532, 17177.24388643706, 82.62293305712367 );
    // Point3d lookingAt = new Point3d( 10394.961152650601, 17176.37017540717, 82.30625574245802 );
    // Vector3d viewerUp = new Vector3d( 0.12756699054896722, -0.2898805092310912, 0.9485230378278534 );

    // start a position that works for any other datasets (not Bonn) as well
    // Point3d eye = new Point3d( 0.0, 0.0, 500.0 );
    // Point3d lookingAt = new Point3d( 0.0, 0.0, 0.0 );
    // Vector3d viewerUp = new Vector3d( 0, 1, 0 );

    Point3d eye = new Point3d(200, 200, 200);
    Point3d lookingAt = new Point3d(200, 200, 40);
    Vector3d viewerUp = new Vector3d(0, 1, 0);

    // Point3d eye = new Point3d( 10048.734288083613, 16641.184387034107, 102.67907642130088 );
    // Point3d lookingAt = new Point3d( 10049.187423499783, 16642.04973827599, 102.89316874434968 );
    // Vector3d viewerUp = new Vector3d( -0.12084130245951936, -0.17831934773102942, 0.9765242392509327 );

    // Point3d eye = new Point3d( -32.39931707896916, 159.80418924642078, 1126.912059107212 );
    // Point3d lookingAt = new Point3d( -32.214625131242, 159.68821181918537, 1125.9361297445957 );
    // Vector3d viewerUp = new Vector3d( 0.043593521862963565, -0.9910685786306717, 0.12602649444650582 );

    // Point3d eye = new Point3d( 16384.0, 16384.0, 23449.175586768335 );
    // Point3d lookingAt = new Point3d( 16384.0, 16384.0, 23295.975589820093 );
    // Vector3d viewerUp = new Vector3d( 0.0, 1.0, 0.0 );

    // Point3d eye = new Point3d( 275.9620120805319, 64.46718597043534, 562.4719914099325 );
    // Point3d lookingAt = new Point3d( 275.53842374511527, 64.61744308424116, 561.5786853471244 );
    // Vector3d viewerUp = new Vector3d( -0.8988362258828301, 0.05280297809393711, 0.43509227130010486 );

    // Point3d eye = new Point3d( 12918.670266734358, 11638.312310974536, 150.9617994096138 );
    // Point3d lookingAt = new Point3d( 12918.923183515637, 11637.442084650263, 150.53902376427538 );
    // Vector3d viewerUp = new Vector3d( 0.0768278457638342, -0.4175378808700864, 0.9054057654741021 );

    // demRenderer = null;

    // geglttet?
    // Point3d eye = new Point3d( 7510.179944980607, 18132.55247159876, 68.67045685404854 );
    // Point3d lookingAt = new Point3d( 7511.084219286393, 18132.97794378385, 68.63494066607761 );
    // Vector3d viewerUp = new Vector3d( 0.027791438877521564, 0.024351414382101418, 0.9993170890876871 );

    // b9
    // Point3d eye = new Point3d( 10979.19258508588, 14968.466515333152, 64.72044690627314 );
    // Point3d lookingAt = new Point3d( 10979.980566257613, 14967.850816271703, 64.72102890882154 );
    // Vector3d viewerUp = new Vector3d( -0.013955210675769197, -0.016915050429668607, 0.9997595376708944 );

    // Point3d eye = new Point3d( 9828.47264469345, 16798.85145159197, 60.203111000265814 );
    // Point3d lookingAt = new Point3d( 9827.530665218446, 16799.169395749544, 60.09547187476404 );
    // Vector3d viewerUp = new Vector3d( -0.09913125830807487, 0.04286879256498191, 0.994150521928221 );

    // Point3d eye = new Point3d( 15576.6342518542, 12838.569167080923, 68.48134435085872 );
    // Point3d lookingAt = new Point3d( 15576.117083773124, 12839.42435008561, 68.44671481997439 );
    // Vector3d viewerUp = new Vector3d( -0.06343873856618466, 0.0020477656389633015, 0.9979836336858363 );

    // Point3d eye = new Point3d( 12812.052257831021, 14217.479020702382, 107.09873254245474 );
    // Point3d lookingAt = new Point3d( 12811.188477648411, 14217.920063628097, 106.85508334010474 );
    // Vector3d viewerUp = new Vector3d( -0.22985946417393577, 0.08539437677143473, 0.9694701785744898 );

    // Point3d eye = new Point3d( 12981.026537448855, 14614.67522876718, 64.11014757850944 );
    // Point3d lookingAt = new Point3d( 12981.038842815053, 14614.578292510932, 63.11493305882678 );
    // Vector3d viewerUp = new Vector3d( -0.9531604427744198, 0.29967690949927844, -0.04097462925758576 );

    // Point3d eye = new Point3d( 12981.149591110829, 14613.705866204698, 54.15800238168214 );
    // Point3d lookingAt = new Point3d( 12981.161896477026, 14613.60892994845, 53.162787861999476 );
    // Vector3d viewerUp = new Vector3d( -0.9531604427744198, 0.29967690949927844, -0.04097462925758576 );

    // Point3d eye = new Point3d( 15194.79953395015, 14758.685598863745, 260.46604235461416 );
    // Point3d lookingAt = new Point3d( 15193.928403030075, 14758.526682033795, 260.00141738622966 );
    // Vector3d viewerUp = new Vector3d( -0.46922710289487696, -0.009549895584917189, 0.8830258916945521 );

    // Point3d eye = new Point3d( 14044.001468902079, 14493.412095321868, 99.7017835888749 );
    // Point3d lookingAt = new Point3d( 14043.100411829999, 14493.217441627952, 99.31421928156796 );
    // Vector3d viewerUp = new Vector3d( -0.38859083784627274, -0.034487121403220806, 0.9207647903775463 );

    // Point3d eye = new Point3d( 13941.009894736511, 14468.932309482483, 54.79817692426634 );
    // Point3d lookingAt = new Point3d( 13940.629520838034, 14468.899319115404, 53.873932728700424 );
    // Vector3d viewerUp = new Vector3d( -0.9095971676519867, -0.16730620974684152, 0.3803177944553526 );

    // Point3d eye = new Point3d( 13830.390906966933, 14466.7982625299, 52.331671222522104 );
    // Point3d lookingAt = new Point3d( 13829.983666405678, 14466.903710390307, 51.42445797636429 );
    // Vector3d viewerUp = new Vector3d( -0.8982101223665114, 0.13370044237873424, 0.4187394987169722 );

    // Point3d eye = new Point3d( 11672.849103687942, 14869.854300744528, 69.884234719344 );
    // Point3d lookingAt = new Point3d( 11671.965328114737, 14870.006960868699, 69.44192756058229 );
    // Vector3d viewerUp = new Vector3d( -0.4447948753649359, 0.01934610579968591, 0.8954235015003251 );

    // Point3d eye = new Point3d( 11608.37185230881, 14960.25622251627, 57.303409872107316 );
    // Point3d lookingAt = new Point3d( 11607.966165915617, 14960.942471044413, 56.69968683295827 );
    // Vector3d viewerUp = new Vector3d( -0.49208113043558477, 0.3926383915255517, 0.7769757104112581 );

    // Point3d eye = new Point3d( 11640.826763764217, 14905.356340264812, 105.60125300402316 );
    // Point3d lookingAt = new Point3d( 11640.421077371024, 14906.042588792956, 104.99752996487413 );
    // Vector3d viewerUp = new Vector3d( -0.49208113043558477, 0.3926383915255517, 0.7769757104112581 );

    // eye = new Point3d( 302.89945876629815, 32478.042855379656, 1107.8712218394253 );
    // lookingAt = new Point3d( 302.8243522721566, 32477.936366469246, 1106.8797486292488 );
    // viewerUp = new Vector3d( -0.012344764703222063, 0.9943046401331957, -0.10585787355701011 );
    //
    // eye = new Point3d( 255.80779269279031, 32411.27445849423, 486.2189150965908 );
    // lookingAt = new Point3d( 255.73268619864876, 32411.16796958382, 485.2274418864143 );
    // viewerUp = new Vector3d( -0.012344764703222063, 0.9943046401331957, -0.10585787355701011 );
    //
    // eye = new Point3d( 10620.468935048752, 14985.997719715537, 71.66828874932546 );
    // lookingAt = new Point3d( 10620.490821833564, 14985.32548833627, 70.92827122157445 );
    // viewerUp = new Vector3d( 0.14028570064737583, -0.7308065630552575, 0.6680132405792482 );

    double fovy = 45.0;
    if (demRenderer != null && eye.x == 200 && eye.y == 200 && eye.z == 200) {
        RenderFragmentManager fragmentManager = demRenderer.getFragmentManager();
        if (fragmentManager != null) {
            MultiresolutionMesh multiresolutionMesh = fragmentManager.getMultiresolutionMesh();
            if (multiresolutionMesh != null) {
                double[][] bBox = multiresolutionMesh.getBBox();
                if (bBox != null) {
                    double centerX = bBox[0][0] + ((bBox[1][0] - bBox[0][0]) * 0.5f);
                    double centerY = bBox[0][1] + ((bBox[1][1] - bBox[0][1]) * 0.5f);
                    double centerZ = bBox[0][2] + ((bBox[1][2] - bBox[0][2]) * 0.5f);
                    double eyeZ = Math.max(centerX, centerY) / Math.tan(Math.toRadians(fovy * 0.5));
                    lookingAt = new Point3d(centerX, centerY, centerZ);
                    eye = new Point3d(centerX, centerY, eyeZ);
                }
            }
        }
    }

    // texture error
    // Point3d eye = new Point3d( 4773.823341206398, 31098.005203681878, 10435.788368373765 );
    // Point3d lookingAt = new Point3d( 4774.131456607485, 31097.242049024728, 10435.220336799908 );
    // Vector3d viewerUp = new Vector3d( 0.22472638841595236, -0.5217978426441787, 0.8229368516243384 );

    return new ViewParams(eye, lookingAt, viewerUp, fovy, zNear, zFar);
}

From source file:lucee.runtime.img.Image.java

public void _rotate(float x, float y, float angle, String interpolation) throws ExpressionException {

    float radiansAngle = (float) Math.toRadians(angle);

    // rotation center
    float centerX = (float) getWidth() / 2;
    float centerY = (float) getHeight() / 2;

    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image());//from   w w w . ja v  a2s  .c  om
    pb.add(centerX);
    pb.add(centerY);
    pb.add(radiansAngle);
    pb.add(new javax.media.jai.InterpolationBicubic(10));

    // create a new, rotated image
    image(JAI.create("rotate", pb).getAsBufferedImage());

}

From source file:org.ecocean.MarkedIndividual.java

public float distFrom(float lat1, float lng1, float lat2, float lng2) {
    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    int meterConversion = 1609;

    return new Float(dist * meterConversion).floatValue();
}

From source file:foodsimulationmodel.pathmapping.Route.java

/**
 * Calculate the distance (in meters) between two Coordinates, using the coordinate reference system that the
 * roadGeography is using. For efficiency it can return the angle as well (in the range -0 to 2PI) if returnVals
 * passed in as a double[2] (the distance is stored in index 0 and angle stored in index 1).
 * /*from  w  w w . j  a  va2 s .c  om*/
 * @param c1
 * @param c2
 * @param returnVals
 *            Used to return both the distance and the angle between the two Coordinates. If null then the distance
 *            is just returned, otherwise this array is populated with the distance at index 0 and the angle at
 *            index 1.
 * @return The distance between Coordinates c1 and c2.
 */
public static synchronized double distance(Coordinate c1, Coordinate c2, double[] returnVals) {
    // TODO check this now, might be different way of getting distance in new Simphony
    GeodeticCalculator calculator = new GeodeticCalculator(ContextManager.roadProjection.getCRS());
    calculator.setStartingGeographicPoint(c1.x, c1.y);
    calculator.setDestinationGeographicPoint(c2.x, c2.y);
    double distance = calculator.getOrthodromicDistance();
    if (returnVals != null && returnVals.length == 2) {
        returnVals[0] = distance;
        double angle = Math.toRadians(calculator.getAzimuth()); // Angle in range -PI to PI
        // Need to transform azimuth (in range -180 -> 180 and where 0 points north)
        // to standard mathematical (range 0 -> 360 and 90 points north)
        if (angle > 0 && angle < 0.5 * Math.PI) { // NE Quadrant
            angle = 0.5 * Math.PI - angle;
        } else if (angle >= 0.5 * Math.PI) { // SE Quadrant
            angle = (-angle) + 2.5 * Math.PI;
        } else if (angle < 0 && angle > -0.5 * Math.PI) { // NW Quadrant
            angle = (-1 * angle) + 0.5 * Math.PI;
        } else { // SW Quadrant
            angle = -angle + 0.5 * Math.PI;
        }
        returnVals[1] = angle;
    }
    return distance;
}

From source file:it.cnr.icar.eric.client.ui.swing.graph.JBGraph.java

/**
 * Given a graph, a hub vertex in a graph and a list of spoke
 * vertices in teh graph this will modify the location of the
 * spokes so that they are laid out in a circle around the hub
 * started with first spoke at an angle of 135 degrees (left of
 * V).//from w  w  w .  j a va2 s  .co  m
 *
 * @param graph DOCUMENT ME!
 * @param hubCell DOCUMENT ME!
 * @param spokeCells DOCUMENT ME!
 */
@SuppressWarnings("unused")
public static void circleLayout(JGraph graph, GraphCell hubCell, ArrayList<Object> spokeCells) {
    if (spokeCells.size() == 0) {
        return;
    }

    GraphView graphView = graph.getView();
    CellView hubCellView = graphView.getMapping(hubCell, true);

    // Maximum width or height
    int max = 0;
    Rectangle bounds = hubCellView.getBounds();

    // Update Maximum
    if (bounds != null) {
        max = Math.max(Math.max(bounds.width, bounds.height), max);
    }

    //Now get the spokeCellViews
    ArrayList<Object> spokeCellViews = new ArrayList<Object>();

    Iterator<Object> iter = spokeCells.iterator();

    while (iter.hasNext()) {
        GraphCell spokeCell = (GraphCell) iter.next();
        CellView spokeCellView = graphView.getMapping(spokeCell, true);

        if (spokeCellView != null) {
            spokeCellViews.add(spokeCellView);
        } else {
            System.err.println("Null spokeCellView for spokeCell: " + spokeCell);
        }

        // Fetch Bounds
        //bounds = spokeCellView.getBounds();
        // Update Maximum
        //if (bounds != null)
        //   max = Math.max(Math.max(bounds.width, bounds.height), max);
    }

    Rectangle hubBounds = hubCellView.getBounds();

    // Compute Radius
    int r = (int) Math.max(((spokeCellViews.size()) * max) / Math.PI, 100);

    //System.err.println("Origin=" + hubBounds.getLocation() + " radius = " + r);
    //Set max radius to 250 pixels.
    if (r > 250) {
        r = 250;
    }

    // Compute step angle in radians
    double stepAngle = Math.toRadians(360.0 / ((double) (spokeCellViews.size())));

    //System.err.println("cellCount=" + spokeCellViews.size() + " stepAngle= " + stepAngle);
    //angle from hub to a spoke.
    double theta = Math.toRadians(90.0);

    if ((spokeCells.size() % 2) == 0) {
        theta = Math.toRadians(135.0);
    }

    // Arrange spokes in a circle around hub.
    iter = spokeCellViews.iterator();

    while (iter.hasNext()) {
        VertexView spokeCellView = (VertexView) iter.next();
        DefaultGraphCell spokeCell = (DefaultGraphCell) spokeCellView.getCell();
        Rectangle spokeBounds = spokeCellView.getBounds();

        //System.err.println("Cell=" + spokeCell.getUserObject() + " theta= " + theta);
        // Update Location
        if (spokeBounds != null) {
            int x = (hubBounds.x + (int) (r * Math.cos(theta))) - (int) ((spokeBounds.width) / 2.0);
            int y = hubBounds.y - (int) (r * Math.sin(theta)) - (int) ((spokeBounds.height) / 2.0);

            translate(spokeCellView, x - spokeBounds.x, y - spokeBounds.y);

            //spokeBounds.setLocation(x, y);
            //System.err.println("X=" + x + " Y=" + y);
        }

        theta -= stepAngle;
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#toDegrees(java.lang.Number)}.
 *//*from w w  w  .  ja  v a2  s.c  o  m*/
@Test
public void testToDegrees() {
    assertEquals("null", (Object) Math.toDegrees(0d), toDegrees(null));
    for (Class<?> type : NUMBERS) {
        short s = -1080;
        while (s <= 1080) {
            assertEquals("deg: " + s + ": " + type.getSimpleName(), (Object) Math.toDegrees(Math.toRadians(s)),
                    toDegrees(toRadians(s)));
            s++;
        }
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#toRadians(java.lang.Number)}.
 *//* w  ww . ja v  a2  s.  co  m*/
@Test
public void testToRadians() {
    assertEquals("null", (Object) Math.toRadians(0d), toRadians(null));
    for (Class<?> type : NUMBERS) {
        short s = -1080;
        while (s <= 1080) {
            assertEquals("deg: " + s + ": " + type.getSimpleName(), (Object) Math.toRadians(s), toRadians(s));
            s++;
        }
    }
}

From source file:com.planetmayo.debrief.satc_rcp.views.MaintainContributionsView.java

/**
 * copy the SATC scenario to the clipboard
 * /*w  w w  . ja  v a  2s  . c o m*/
 */
protected void exportSATC() {
    // - ok, really we just export the state & bearing data
    if (activeSolver != null) {
        StringBuffer res = new StringBuffer();
        final String newLine = System.getProperty("line.separator");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MMM/dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        @SuppressWarnings("deprecation")
        Date dateLead = new Date(100, 7, 7);

        Iterator<BaseContribution> conts = activeSolver.getContributions().iterator();
        while (conts.hasNext()) {
            BaseContribution baseC = conts.next();
            if (baseC instanceof BearingMeasurementContribution) {
                BearingMeasurementContribution bmc = (BearingMeasurementContribution) baseC;

                // ok - sort out the date offset
                Date startDate = bmc.getStartDate();
                long offset = startDate.getTime() - dateLead.getTime();

                // get ready for the offset
                Point2D origin = null;

                // get ready to calculate offsetes
                GeodeticCalculator calc = GeoSupport.createCalculator();

                // ok, first the states
                res.append("//X, Y, Time, Course Degs, Speed Kts" + newLine);
                Iterator<HostState> states = bmc.getHostState().iterator();
                while (states.hasNext()) {
                    BearingMeasurementContribution.HostState hostState = states.next();

                    // sort out the X,Y offset
                    double x, y;
                    if (origin == null) {
                        x = 0;
                        y = 0;
                        origin = new Point2D.Double(hostState.dLong, hostState.dLat);
                    } else {
                        // ok, calc a new XY, from the origin
                        java.awt.geom.Point2D.Double thisP = new Point2D.Double(hostState.dLong,
                                hostState.dLat);
                        calc.setStartingGeographicPoint(origin);
                        calc.setDestinationGeographicPoint(thisP);
                        double angle = calc.getAzimuth();
                        double dist = calc.getOrthodromicDistance();

                        // and the new x,y coords
                        x = Math.sin(Math.toRadians(angle)) * dist;
                        y = Math.cos(Math.toRadians(angle)) * dist;

                    }

                    res.append(x + ", " + y + ", " + sdf.format(new Date(hostState.time - offset)) + ","
                            + hostState.courseDegs + "," + hostState.speedKts + newLine);
                }

                // now the cuts
                res.append("//Time, Bearing Degs" + newLine);
                Iterator<BMeasurement> cuts = bmc.getMeasurements().iterator();
                while (cuts.hasNext()) {
                    BearingMeasurementContribution.BMeasurement cut = cuts.next();
                    res.append(sdf.format(new Date(cut.getDate().getTime() - offset)) + ","
                            + Math.toDegrees(cut.getBearingRads()) + newLine);
                }
            }
        }

        // hmm, did we find anything
        if (res.length() > 0) {
            // ok, put it on the clipboard.
            new TextTransfer().setClipboardContents(res.toString());
        }
    }
}