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:edu.csun.ecs.cs.multitouchj.application.touchpong.TouchPong.java

private void onGameStateStart() {
    wonControl.setVisible(false);//from  w  w w.  j  ava2  s .c om
    lostControl.setVisible(false);

    Random random = new Random(new Date().getTime());
    float ballAngle = (float) random.nextInt(360);
    float ballX = (float) Math.cos(Math.toRadians(ballAngle));
    float ballY = (float) Math.sin(Math.toRadians(ballAngle));
    if (ballX == 0.0f) {
        ballX = 0.5f;
    }
    if (ballY == 0.0f) {
        ballY = 0.5f;
    }

    log.debug("angle: " + ballAngle + ", x: " + ballX + ", y: " + ballY);
    ballUnitVector.set(ballX, ballY);
    ballUnitVector = ballUnitVector.normalise(null);

    gameState = GameState.Playing;
}

From source file:uk.ac.diamond.scisoft.xpdf.views.XPDFPhase.java

/**
 * Gets the volume of the unit cell// w w  w .jav  a  2  s  .c  om
 * @return
 *       the volume of the unit cell
 */
public double getUnitCellVolume() {
    // Volume if all angles were 90
    double[] trueLengths = this.getUnitCellLengths(), trueAngles = this.getUnitCellAngle();
    double orthoVolume = trueLengths[0] * trueLengths[1] * trueLengths[2];
    // Shape coefficient; angular dependency
    double ca = Math.cos(Math.toRadians(trueAngles[0])), cb = Math.cos(Math.toRadians(trueAngles[1])),
            cg = Math.cos(Math.toRadians(trueAngles[2]));
    double shapeCoefficient = Math.sqrt(1 - ca * ca - cb * cb - cg * cg + 2 * ca * cb * cg);
    return orthoVolume * shapeCoefficient;
}

From source file:com.automaster.autoview.server.servlet.ExcelServlet.java

private double caculaDistanciaEntreDoisPontos(double lat1, double lon1, double lat2, double lon2) {

    //Transforma cordenadas em radianos
    /*String lat1Reduzida = String.valueOf(lat1);
    int index = lat1Reduzida.indexOf(".");
    String latFinal1 = lat1Reduzida.substring(0, index+5);
            /*  ww w.  ja va2s.co m*/
    String lon1Reduzida = String.valueOf(lon1);
    String lonFinal1 = lon1Reduzida.substring(0, index+5);
            
    String lat2Reduzida = String.valueOf(lat2);
    String latFinal2 = lat2Reduzida.substring(0, index+5);
            
    String lon2Reduzida = String.valueOf(lon2);
    String lonFinal2 = lon2Reduzida.substring(0, index+5);*/

    double lat01 = Math.toRadians(lat1);
    double lon01 = Math.toRadians(lon1);
    double lat02 = Math.toRadians(lat2);
    double lon02 = Math.toRadians(lon2);
    //calcula a distncia em KM atravs da frmula
    double dist = (6371 * Math.acos(
            Math.cos(lat01) * Math.cos(lat02) * Math.cos(lon02 - lon01) + Math.sin(lat01) * Math.sin(lat02)));
    //formata o resultado
    if (dist > 0) {
        BigDecimal decimalFormatado = new BigDecimal(dist).setScale(2, RoundingMode.HALF_EVEN);
        return decimalFormatado.doubleValue();
    }
    return 0;
    //return dist;

}

From source file:net.malisis.core.renderer.element.Shape.java

/**
 * Rotates this {@link Shape} around the given axis the specified angle. Offsets the origin for the rotation.
 *
 * @param angle the angle/*from  w w w  . j a v a  2s .  co  m*/
 * @param x the x
 * @param y the y
 * @param z the z
 * @param offsetX the offset x
 * @param offsetY the offset y
 * @param offsetZ the offset z
 */
@Override
public void rotate(float angle, float x, float y, float z, float offsetX, float offsetY, float offsetZ) {
    if (mergedVertexes != null) {
        for (MergedVertex mv : mergedVertexes.values())
            mv.rotate(angle, x, y, z, offsetX, offsetY, offsetZ);
    } else {
        translate(offsetX, offsetY, offsetZ);
        transformMatrix.rotate((float) Math.toRadians(angle), new Vector3f(x, y, z));
        translate(-offsetX, -offsetY, -offsetZ);
    }
}

From source file:com.mbientlab.metawear.tutorial.starter.DeviceSetupActivityFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // Grab Date//ww  w  .  j a v  a 2s  . c  om
    year = Calendar.getInstance().get(Calendar.YEAR);
    month = Calendar.getInstance().get(Calendar.MONTH) + 1;
    day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

    // Initialize variables used for trial name
    SubjectCode = (EditText) view.findViewById(R.id.SubjectCode);
    TrialNumber = (EditText) view.findViewById(R.id.TrialNumber);
    TrialType = (EditText) view.findViewById(R.id.TrialType);
    FileName_text = (TextView) view.findViewById(R.id.FileName_text);

    // Initialize buttons for device behavior
    ProgramState_text = (TextView) view.findViewById(R.id.ProgramState_text);
    ProgramState_switch = (Switch) view.findViewById(R.id.ProgramState);

    // Initialize thresholds and feedback toggles
    Threshold_L = (EditText) view.findViewById(R.id.Threshold_L);
    MotorToggle_switch = (Switch) view.findViewById(R.id.MotorToggle_switch);

    Threshold_L.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            Threshold_L_string = Threshold_L.getText().toString();
            if (Threshold_L_string.length() > 0) {
                threshold_L = Double.parseDouble(Threshold_L_string);
            } else {

            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
    SubjectCode.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            SubjectCode_string = SubjectCode.getText().toString();
            FileName_text.setText("" + year + "" + month + "" + day + "_" + SubjectCode_string + "_"
                    + TrialType_string + "_" + TrialNumber_string_final);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    TrialType.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            TrialType_string = TrialType.getText().toString();
            FileName_text.setText("" + year + "" + month + "" + day + "_" + SubjectCode_string + "_"
                    + TrialType_string + "_" + TrialNumber_string_final);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    TrialNumber.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            TrialNumber_string = TrialNumber.getText().toString();
            if (TrialNumber_string.length() > 0) {
                TrialNumber_int = Integer.parseInt(TrialNumber_string);
                TrialNumber_string_final = String.format("%03d", TrialNumber_int);
            } else {
            }

            /*if (TrialNumber_string.length() == 1){
            TrialNumber_string_final = "00"+TrialNumber_string;
            }
            if (TrialNumber_string.length() == 2){
            TrialNumber_string_final = "0"+TrialNumber_string;
            }
            if (TrialNumber_string.length() == 3){
            TrialNumber_string_final = TrialNumber_string;
            }*/
            FileName_text.setText("" + year + "" + month + "" + day + "_" + SubjectCode_string + "_"
                    + TrialType_string + "_" + TrialNumber_string_final);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    MotorToggle_switch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (MotorToggle_state == false) {
                MotorToggle_state = true;
            } else {
                MotorToggle_state = false;
            }
        }
    });

    ProgramState_switch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (ProgramState_status == false) {
                ProgramState_status = true;
                accelerometer.acceleration().addRouteAsync(new RouteBuilder() {
                    @Override
                    public void configure(RouteComponent source) {
                        source.stream(new Subscriber() {
                            @Override
                            public void apply(Data data, Object... env) {

                                // Read Accel and Prepare for writing to CSV
                                accel_raw_x = data.value(Acceleration.class).x();
                                accel_raw_y = data.value(Acceleration.class).y();
                                accel_raw_z = data.value(Acceleration.class).z();
                                accel_string_x = Double.toString(accel_raw_x);
                                accel_string_y = Double.toString(accel_raw_y);
                                accel_string_z = Double.toString(accel_raw_z);

                                if (initial_accel_loop == 1) {
                                    double vertical_sensor_norm_init = Math.sqrt(accel_raw_x * accel_raw_x
                                            + accel_raw_y * accel_raw_y + accel_raw_z * accel_raw_z);
                                    vertical_sensor_0 = accel_raw_x * 1 / vertical_sensor_norm_init;
                                    vertical_sensor_1 = accel_raw_y * 1 / vertical_sensor_norm_init;
                                    vertical_sensor_2 = accel_raw_z * 1 / vertical_sensor_norm_init;

                                    initial_accel_loop = 0;
                                }
                            }
                        });
                    }
                }).continueWith(new Continuation<Route, Void>() {

                    @Override
                    public Void then(Task<Route> task) throws Exception {
                        accelerometer.acceleration().start();
                        accelerometer.start();
                        Log.i("MainActivity", "Running!");

                        initial_accel_loop = 1;

                        ProgramState_text.setText("Collecting");
                        return null;
                    }
                });
                gyroscope.angularVelocity().addRouteAsync(new RouteBuilder() {
                    @Override
                    public void configure(RouteComponent source) {
                        source.stream(new Subscriber() {
                            @Override
                            public void apply(Data data, Object... env) {

                                // Read Gyro and Prepare for writing to CSV
                                gyro_raw_x = data.value(AngularVelocity.class).x();
                                gyro_raw_y = data.value(AngularVelocity.class).y();
                                gyro_raw_z = data.value(AngularVelocity.class).z();
                                gyro_raw_x = Math.toRadians(gyro_raw_x);
                                gyro_raw_y = Math.toRadians(gyro_raw_y);
                                gyro_raw_z = Math.toRadians(gyro_raw_z);

                                gyro_string_x = Double.toString(gyro_raw_x);
                                gyro_string_y = Double.toString(gyro_raw_y);
                                gyro_string_z = Double.toString(gyro_raw_z);

                                if (initial_accel_loop == 0) {
                                    // Get Timestamp
                                    currentTime = System.currentTimeMillis();
                                    deltaTime = (currentTime - previousTime) / 1000;

                                    if (gyro_raw_x != previous_gyro_raw_x) {
                                        previous_gyro_raw_x = gyro_raw_x;

                                        totalTime = totalTime + deltaTime;
                                        time_stamp = Double.toString(totalTime);
                                        previousTime = currentTime;

                                        //// CALCULATE INCLINATION ANGLE /////
                                        vertical_sensor_from_accel_0 = accel_raw_x;
                                        vertical_sensor_from_accel_1 = accel_raw_y;
                                        vertical_sensor_from_accel_2 = accel_raw_z;

                                        // normalize accelerometer estimate
                                        vertical_sensor_from_accel_norm = Math.sqrt(
                                                vertical_sensor_from_accel_0 * vertical_sensor_from_accel_0
                                                        + vertical_sensor_from_accel_1
                                                                * vertical_sensor_from_accel_1
                                                        + vertical_sensor_from_accel_2
                                                                * vertical_sensor_from_accel_2);

                                        vertical_sensor_from_accel_0 = vertical_sensor_from_accel_0
                                                / vertical_sensor_from_accel_norm;
                                        vertical_sensor_from_accel_1 = vertical_sensor_from_accel_1
                                                / vertical_sensor_from_accel_norm;
                                        vertical_sensor_from_accel_2 = vertical_sensor_from_accel_2
                                                / vertical_sensor_from_accel_norm;

                                        // GYROSCOPE INCLINATION ANGLE
                                        angular_velocity_body_matrix_0_0 = 0;
                                        angular_velocity_body_matrix_0_1 = -gyro_raw_z;
                                        angular_velocity_body_matrix_0_2 = gyro_raw_y;
                                        angular_velocity_body_matrix_1_0 = gyro_raw_z;
                                        angular_velocity_body_matrix_1_1 = 0;
                                        angular_velocity_body_matrix_1_2 = -gyro_raw_x;
                                        angular_velocity_body_matrix_2_0 = -gyro_raw_y;
                                        angular_velocity_body_matrix_2_1 = gyro_raw_x;
                                        angular_velocity_body_matrix_2_2 = 0;

                                        // rotational velocity based on gyroscope readings
                                        vertical_sensor_dot_from_gyro_0 = -(angular_velocity_body_matrix_0_0
                                                * vertical_sensor_0
                                                + angular_velocity_body_matrix_0_1 * vertical_sensor_1
                                                + angular_velocity_body_matrix_0_2 * vertical_sensor_2);
                                        vertical_sensor_dot_from_gyro_1 = -(angular_velocity_body_matrix_1_0
                                                * vertical_sensor_0
                                                + angular_velocity_body_matrix_1_1 * vertical_sensor_1
                                                + angular_velocity_body_matrix_1_2 * vertical_sensor_2);
                                        vertical_sensor_dot_from_gyro_2 = -(angular_velocity_body_matrix_2_0
                                                * vertical_sensor_0
                                                + angular_velocity_body_matrix_2_1 * vertical_sensor_1
                                                + angular_velocity_body_matrix_2_2 * vertical_sensor_2);

                                        // rotational velocity based on difference to accelerometer estimate
                                        vertical_sensor_dot_from_accel_0 = -alpha
                                                * (vertical_sensor_0 - vertical_sensor_from_accel_0);
                                        vertical_sensor_dot_from_accel_1 = -alpha
                                                * (vertical_sensor_1 - vertical_sensor_from_accel_1);
                                        vertical_sensor_dot_from_accel_2 = -alpha
                                                * (vertical_sensor_2 - vertical_sensor_from_accel_2);

                                        // combine the two estimates
                                        vertical_sensor_dot_0 = vertical_sensor_dot_from_gyro_0
                                                + vertical_sensor_dot_from_accel_0;
                                        vertical_sensor_dot_1 = vertical_sensor_dot_from_gyro_1
                                                + vertical_sensor_dot_from_accel_1;
                                        vertical_sensor_dot_2 = vertical_sensor_dot_from_gyro_2
                                                + vertical_sensor_dot_from_accel_2;

                                        // integrate rotational velocity
                                        vertical_sensor_0 = vertical_sensor_0
                                                + deltaTime * vertical_sensor_dot_0;
                                        vertical_sensor_1 = vertical_sensor_1
                                                + deltaTime * vertical_sensor_dot_1;
                                        vertical_sensor_2 = vertical_sensor_2
                                                + deltaTime * vertical_sensor_dot_2;

                                        // normalize after integration
                                        vertical_sensor_norm = Math.sqrt(vertical_sensor_0 * vertical_sensor_0
                                                + vertical_sensor_1 * vertical_sensor_1
                                                + vertical_sensor_2 * vertical_sensor_2);
                                        vertical_sensor_0 = vertical_sensor_0 / vertical_sensor_norm;
                                        vertical_sensor_1 = vertical_sensor_1 / vertical_sensor_norm;
                                        vertical_sensor_2 = vertical_sensor_2 / vertical_sensor_norm;

                                        // calculate inclination angles
                                        inclination_angle = Math.acos(vertical_sensor_0 * sensor_axis_sensor_0
                                                + vertical_sensor_1 * sensor_axis_sensor_1
                                                + vertical_sensor_2 * sensor_axis_sensor_2);
                                        inclination_angle_from_accel = Math
                                                .acos(vertical_sensor_from_accel_0 * sensor_axis_sensor_0
                                                        + vertical_sensor_from_accel_1 * sensor_axis_sensor_1
                                                        + vertical_sensor_from_accel_2 * sensor_axis_sensor_2);
                                        // convert to degrees
                                        inclination_angle = Math.toDegrees(inclination_angle);
                                        inclination_angle_from_accel = Math
                                                .toDegrees(inclination_angle_from_accel);

                                        if (inclination_angle > threshold_L && MotorToggle_state == true) {
                                            motor_status = 1;
                                            //board.getModule(Haptic.class).startBuzzer;
                                            metawear.getModule(Haptic.class).startBuzzer((short) 40);
                                        } else {
                                            motor_status = 0;
                                        }

                                        Log.i("MainActivity", Integer.toString(motor_status));
                                        Log.i("MainActivity", Double.toString(inclination_angle));
                                        csv_entry = csv_entry + time_stamp + "," + inclination_angle + ","
                                                + MotorToggle_state + "," + motor_status + ","
                                                + inclination_angle_from_accel + "," + threshold_L + "," + alpha
                                                + "," + accel_string_x + "," + accel_string_y + ","
                                                + accel_string_z + "," + gyro_string_x + "," + gyro_string_y
                                                + "," + gyro_string_z + "\n";
                                    }
                                }
                            }
                        });
                    }
                }).continueWith(new Continuation<Route, Void>() {
                    @Override
                    public Void then(Task<Route> task) throws Exception {
                        gyroscope.angularVelocity().start();
                        gyroscope.start();

                        currentTime = System.currentTimeMillis();
                        previousTime = currentTime;
                        totalTime = 0;
                        return null;
                    }
                });
            } else {
                // Stop all activity
                Log.i("MainActivity", "Stopped");
                ProgramState_status = false;
                accelerometer.stop();
                accelerometer.acceleration().stop();
                gyroscope.stop();
                gyroscope.angularVelocity().stop();
                ProgramState_text.setText("Saved previous data, Ready to Start");

                filename = FileName_text.getText().toString();

                file = new File(ctx.getExternalFilesDir(null), filename);
                try {
                    OutputStream os = new FileOutputStream(file);
                    os.write(csv_entry.getBytes());
                    os.close();
                    Log.i("MainActivity", "File is created as..." + filename);
                } catch (IOException e) {
                    Log.i("MainActivity", "File NOT created ...!");
                    e.printStackTrace();
                }

                // Reinitialize CSV Entry
                csv_entry = "time" + "," + "inclination angle" + "," + "feedback toggle" + "," + "motor status"
                        + "," + "inclination angle from accelerometers" + "," + "threshold" + "," + "alpha"
                        + "," + "accelerometer_x" + "," + "accelerometer_y" + "," + "acceleromter_z" + ","
                        + "gyroscope_x" + "," + "gyroscope_y" + "," + "gyroscope_z" + "\n" + "sec" + "," + "deg"
                        + "," + "binary" + "," + "binary" + "," + "deg" + "," + "deg" + "," + " " + "," + "g"
                        + "," + "g" + "," + "g" + "," + "deg/sec" + "," + "deg/sec" + "," + "deg/sec" + "\n";
                ProgramState_text.setText("Data Saved and Cleared");

                // Ensure the first loop of next trial goes thru accel first
                initial_accel_loop = 1;

                // Next Trial Increment
                TrialNumber_int = TrialNumber_int + 1;
                TrialNumber.setText(TrialNumber_int.toString());
            }
        }
    });
}

From source file:blusunrize.immersiveengineering.client.ClientProxy.java

@Override
public void preInit() {
    Framebuffer fb = ClientUtils.mc().getFramebuffer();
    if (OpenGlHelper.framebufferSupported && IEConfig.stencilBufferEnabled && !fb.isStencilEnabled()) {
        stencilBufferEnabled = fb.enableStencil();//Enabling FBO stencils
    }//w  ww  . jav a  2s .c  om
    ModelLoaderRegistry.registerLoader(IEOBJLoader.instance);
    OBJLoader.INSTANCE.addDomain("immersiveengineering");
    IEOBJLoader.instance.addDomain("immersiveengineering");
    MinecraftForge.EVENT_BUS.register(this);
    MinecraftForge.EVENT_BUS.register(ImmersiveModelRegistry.instance);

    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemBullet, 1, 2),
            new ImmersiveModelRegistry.ItemModelReplacement() {
                @Override
                public IBakedModel createBakedModel(IBakedModel existingModel) {
                    return new ModelItemDynamicOverride(existingModel, null);
                }
            });
    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemShader),
            new ImmersiveModelRegistry.ItemModelReplacement() {
                @Override
                public IBakedModel createBakedModel(IBakedModel existingModel) {
                    return new ModelItemDynamicOverride(existingModel, null);
                }
            });

    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemTool, 1, 2),
            new ImmersiveModelRegistry.ItemModelReplacement_OBJ(
                    "immersiveengineering:models/item/tool/voltmeter.obj", false)
                            .setTransformations(TransformType.FIRST_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(-.25, .375, .3125).rotate(-Math.PI * .5, 0, 1, 0))
                            .setTransformations(TransformType.FIRST_PERSON_LEFT_HAND,
                                    new Matrix4().translate(-.25, .375, -.625).rotate(-Math.PI * .5, 0, 1, 0))
                            .setTransformations(TransformType.THIRD_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(-0.25, .125, .25).scale(.625f, .625f, .625f)
                                            .rotate(-Math.PI * .375, 0, 1, 0))
                            .setTransformations(TransformType.THIRD_PERSON_LEFT_HAND,
                                    new Matrix4().translate(-0.5, .125, -.3125).scale(.625f, .625f, .625f)
                                            .rotate(-Math.PI * .375, 0, 1, 0))
                            .setTransformations(TransformType.FIXED,
                                    new Matrix4().translate(-.5, .5, -.5).scale(1, 1, 1).rotate(Math.PI, 0, 1,
                                            0))
                            .setTransformations(TransformType.GUI,
                                    new Matrix4().translate(0, .5, 0).scale(1.125, 1.125, 1.125)
                                            .rotate(-Math.PI * .25, 0, 1, 0))
                            .setTransformations(TransformType.GROUND,
                                    new Matrix4().translate(.25, .25, .25).scale(.5, .5, .5)));

    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemToolbox),
            new ImmersiveModelRegistry.ItemModelReplacement_OBJ(
                    "immersiveengineering:models/item/toolbox.obj", false)
                            .setTransformations(TransformType.FIRST_PERSON_RIGHT_HAND,
                                    new Matrix4().scale(.375, .375, .375).translate(-.75, 1.25, .3125)
                                            .rotate(-Math.PI * .75, 0, 1, 0))
                            .setTransformations(TransformType.FIRST_PERSON_LEFT_HAND,
                                    new Matrix4().scale(.375, .375, .375).translate(-.125, 1.25, .9375)
                                            .rotate(Math.PI * .25, 0, 1, 0))
                            .setTransformations(TransformType.THIRD_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(-.25, .1875, .3125).scale(.625, .625, .625)
                                            .rotate(Math.PI, 0, 1, 0).rotate(-Math.PI * .5, 1, 0, 0))
                            .setTransformations(TransformType.THIRD_PERSON_LEFT_HAND,
                                    new Matrix4().translate(-.25, -.4375, .3125).scale(.625, .625, .625)
                                            .rotate(Math.PI * .5, 1, 0, 0))
                            .setTransformations(TransformType.FIXED,
                                    new Matrix4().translate(.5, .875, -.5).scale(1, 1, 1).rotate(Math.PI * .5,
                                            0, 1, 0))
                            .setTransformations(TransformType.GUI,
                                    new Matrix4().translate(-.625, .75, 0).scale(.875, .875, .875)
                                            .rotate(-Math.PI * .6875, 0, 1, 0))
                            .setTransformations(TransformType.GROUND,
                                    new Matrix4().translate(.25, .5, .25).scale(.5, .5, .5)));

    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemRevolver, 1, 0),
            new ImmersiveModelRegistry.ItemModelReplacement_OBJ(
                    "immersiveengineering:models/item/revolver.obj", true)
                            .setTransformations(TransformType.FIRST_PERSON_RIGHT_HAND,
                                    new Matrix4().rotate(Math.toRadians(-90), 0, 1, 0).scale(.1875, .25, .25)
                                            .translate(.25, .25, .5))
                            .setTransformations(TransformType.FIRST_PERSON_LEFT_HAND,
                                    new Matrix4().rotate(Math.toRadians(90), 0, 1, 0).scale(.1875, .25, .25)
                                            .translate(-.3, .25, .5))
                            .setTransformations(TransformType.THIRD_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(-.125, .0625, -.03125).scale(.125, .125, .125)
                                            .rotate(Math.toRadians(-90), 0, 1, 0)
                                            .rotate(Math.toRadians(-10), 0, 0, 1))
                            .setTransformations(TransformType.THIRD_PERSON_LEFT_HAND,
                                    new Matrix4().translate(.0, .0625, -.03125).scale(.125, .125, .125)
                                            .rotate(Math.toRadians(90), 0, 1, 0)
                                            .rotate(Math.toRadians(10), 0, 0, 1))
                            .setTransformations(TransformType.GUI,
                                    new Matrix4().translate(.1875, -.0781225, -.15625).scale(.2, .2, .2)
                                            .rotate(Math.toRadians(-40), 0, 1, 0)
                                            .rotate(Math.toRadians(-35), 0, 0, 1))
                            .setTransformations(TransformType.FIXED,
                                    new Matrix4().translate(-.375, -.25, -.0625).scale(.1875, .1875, .1875)
                                            .rotate(Math.PI, 0, 1, 0).rotate(Math.toRadians(-40), 0, 0, 1))
                            .setTransformations(TransformType.GROUND,
                                    new Matrix4().translate(.125, 0, .0625).scale(.125, .125, .125)));
    IEContent.itemRevolver.setTileEntityItemStackRenderer(ItemRendererIEOBJ.INSTANCE);

    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemDrill, 1, 0),
            new ImmersiveModelRegistry.ItemModelReplacement_OBJ(
                    "immersiveengineering:models/item/drill/drill_diesel.obj", true)
                            .setTransformations(TransformType.FIRST_PERSON_RIGHT_HAND,
                                    new Matrix4().scale(.375, .4375, .375).translate(-.25, 1, .5)
                                            .rotate(Math.PI * .5, 0, 1, 0))
                            .setTransformations(TransformType.FIRST_PERSON_LEFT_HAND,
                                    new Matrix4().scale(-.375, .4375, .375).translate(.25, 1, .5)
                                            .rotate(-Math.PI * .5, 0, 1, 0))
                            .setTransformations(TransformType.THIRD_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(.0625, .9375, .25).scale(.75, .75, .75)
                                            .rotate(Math.PI * .75, 0, 1, 0).rotate(Math.PI * .375, 0, 0, 1)
                                            .rotate(-Math.PI * .25, 1, 0, 0))
                            .setTransformations(TransformType.THIRD_PERSON_LEFT_HAND,
                                    new Matrix4().translate(.0625, .9375, .25).scale(-.75, .75, .75)
                                            .rotate(-Math.PI * .75, 0, 1, 0).rotate(-Math.PI * .375, 0, 0, 1)
                                            .rotate(-Math.PI * .25, 1, 0, 0))
                            .setTransformations(TransformType.FIXED,
                                    new Matrix4().translate(.1875, .0625, .15625).scale(.4375, .4375, .4375)
                                            .rotate(-Math.PI * .25, 0, 0, 1))
                            .setTransformations(TransformType.GUI,
                                    new Matrix4().translate(-.5, .25, 0).scale(.75, .75, .75)
                                            .rotate(-Math.PI * .6875, 0, 1, 0).rotate(-Math.PI * .125, 0, 0, 1))
                            .setTransformations(TransformType.GROUND,
                                    new Matrix4().translate(.125, .25, .25).scale(.5, .5, .5)));
    IEContent.itemDrill.setTileEntityItemStackRenderer(ItemRendererIEOBJ.INSTANCE);

    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemFluorescentTube, 1, 0),
            new ImmersiveModelRegistry.ItemModelReplacement_OBJ(
                    "immersiveengineering:models/item/fluorescent_tube.obj", true)
                            .setTransformations(TransformType.FIRST_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(.2, .1, 0).rotate(-Math.PI / 3, 1, 0, 0))
                            .setTransformations(TransformType.FIRST_PERSON_LEFT_HAND,
                                    new Matrix4().translate(.2, .1, 0).rotate(-Math.PI / 3, 1, 0, 0))
                            .setTransformations(TransformType.THIRD_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(0, .5, .1))
                            .setTransformations(TransformType.THIRD_PERSON_LEFT_HAND,
                                    new Matrix4().translate(0, .5, .1))
                            .setTransformations(TransformType.FIXED, new Matrix4())
                            .setTransformations(TransformType.GUI,
                                    new Matrix4().rotate(-Math.PI / 4, 0, 0, 1).rotate(Math.PI / 8, 0, 1, 0))
                            .setTransformations(TransformType.GROUND,
                                    new Matrix4().scale(.5, .5, .5).translate(0, .5, 0)));
    IEContent.itemFluorescentTube.setTileEntityItemStackRenderer(ItemRendererIEOBJ.INSTANCE);

    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemChemthrower, 1, 0),
            new ImmersiveModelRegistry.ItemModelReplacement_OBJ(
                    "immersiveengineering:models/item/chemthrower.obj", true)
                            .setTransformations(TransformType.FIRST_PERSON_RIGHT_HAND,
                                    new Matrix4().scale(.375, .375, .375).translate(-.25, 1, .5)
                                            .rotate(Math.PI * .5, 0, 1, 0))
                            .setTransformations(TransformType.FIRST_PERSON_LEFT_HAND,
                                    new Matrix4().scale(-.375, .375, .375).translate(-.25, 1, .5)
                                            .rotate(-Math.PI * .5, 0, 1, 0))
                            .setTransformations(TransformType.THIRD_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(0, .75, .1875).scale(.5, .5, .5)
                                            .rotate(Math.PI * .75, 0, 1, 0).rotate(Math.PI * .375, 0, 0, 1)
                                            .rotate(-Math.PI * .25, 1, 0, 0))
                            .setTransformations(TransformType.THIRD_PERSON_LEFT_HAND,
                                    new Matrix4().translate(0, .75, .1875).scale(.5, -.5, .5)
                                            .rotate(Math.PI * .75, 0, 1, 0).rotate(Math.PI * .625, 0, 0, 1)
                                            .rotate(-Math.PI * .25, 1, 0, 0))
                            .setTransformations(TransformType.FIXED,
                                    new Matrix4().translate(.125, .125, -.25).scale(.3125, .3125, .3125)
                                            .rotate(Math.PI, 0, 1, 0).rotate(Math.PI * .25, 0, 0, 1))
                            .setTransformations(TransformType.GUI,
                                    new Matrix4().translate(-.1875, .3125, 0).scale(.4375, .4375, .4375)
                                            .rotate(-Math.PI * .6875, 0, 1, 0).rotate(-Math.PI * .125, 0, 0, 1))
                            .setTransformations(TransformType.GROUND,
                                    new Matrix4().translate(0, .25, .125).scale(.25, .25, .25)));
    IEContent.itemChemthrower.setTileEntityItemStackRenderer(ItemRendererIEOBJ.INSTANCE);

    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemRailgun, 1, 0),
            new ImmersiveModelRegistry.ItemModelReplacement_OBJ("immersiveengineering:models/item/railgun.obj",
                    true)//TODO add the fancy render back?
                            .setTransformations(TransformType.FIRST_PERSON_RIGHT_HAND,
                                    new Matrix4().scale(.125, .125, .125).translate(-.5, 1.5, .5)
                                            .rotate(Math.PI * .46875, 0, 1, 0))
                            .setTransformations(TransformType.FIRST_PERSON_LEFT_HAND,
                                    new Matrix4().scale(.125, .125, .125).translate(-1.75, 1.625, .875)
                                            .rotate(-Math.PI * .46875, 0, 1, 0))
                            .setTransformations(TransformType.THIRD_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(.0625, .5, -.3125).scale(.1875, .1875, .1875)
                                            .rotate(Math.PI * .53125, 0, 1, 0).rotate(Math.PI * .25, 0, 0, 1))
                            .setTransformations(TransformType.THIRD_PERSON_LEFT_HAND,
                                    new Matrix4().translate(-.1875, .5, -.3125).scale(.1875, .1875, .1875)
                                            .rotate(-Math.PI * .46875, 0, 1, 0).rotate(-Math.PI * .25, 0, 0, 1))
                            .setTransformations(TransformType.FIXED,
                                    new Matrix4().translate(.1875, .0625, .0625).scale(.125, .125, .125)
                                            .rotate(-Math.PI * .25, 0, 0, 1))
                            .setTransformations(TransformType.GUI,
                                    new Matrix4().translate(-.1875, 0, 0).scale(.1875, .1875, .1875)
                                            .rotate(-Math.PI * .6875, 0, 1, 0)
                                            .rotate(-Math.PI * .1875, 0, 0, 1))
                            .setTransformations(TransformType.GROUND,
                                    new Matrix4().translate(.125, .125, .0625).scale(.125, .125, .125)));
    IEContent.itemRailgun.setTileEntityItemStackRenderer(ItemRendererIEOBJ.INSTANCE);

    ImmersiveModelRegistry.instance.registerCustomItemModel(new ItemStack(IEContent.itemShield),
            new ImmersiveModelRegistry.ItemModelReplacement_OBJ(
                    "immersiveengineering:models/item/shield.obj", true)
                            .setTransformations(TransformType.FIRST_PERSON_RIGHT_HAND,
                                    new Matrix4().rotate(Math.toRadians(90), 0, 1, 0).rotate(.1, 1, 0, 0)
                                            .translate(.5, .125, .5))
                            .setTransformations(TransformType.FIRST_PERSON_LEFT_HAND,
                                    new Matrix4().rotate(Math.toRadians(-90), 0, 1, 0).rotate(-.1, 1, 0, 0)
                                            .translate(-.5, .125, .5))
                            .setTransformations(TransformType.THIRD_PERSON_RIGHT_HAND,
                                    new Matrix4().translate(.59375, .375, .75))
                            .setTransformations(TransformType.THIRD_PERSON_LEFT_HAND,
                                    new Matrix4().rotate(3.14159, 0, 1, 0).translate(-.59375, .375, .25))
                            .setTransformations(TransformType.FIXED,
                                    new Matrix4().rotate(1.57079, 0, 1, 0).scale(.75f, .75f, .75f)
                                            .translate(.375, .5, .5))
                            .setTransformations(TransformType.GUI,
                                    new Matrix4().translate(-.375, .375, 0).scale(.75, .625, .75)
                                            .rotate(-2.35619, 0, 1, 0).rotate(0.13089, 0, 0, 1))
                            .setTransformations(TransformType.GROUND,
                                    new Matrix4().translate(.125, .125, .125).scale(.25, .25, .25)));
    IEContent.itemShield.setTileEntityItemStackRenderer(ItemRendererIEOBJ.INSTANCE);

    RenderingRegistry.registerEntityRenderingHandler(EntityRevolvershot.class,
            new IRenderFactory<EntityRevolvershot>() {
                @Override
                public Render createRenderFor(RenderManager manager) {
                    return new EntityRenderRevolvershot(manager);
                }
            });
    RenderingRegistry.registerEntityRenderingHandler(EntitySkylineHook.class,
            new IRenderFactory<EntitySkylineHook>() {
                @Override
                public Render createRenderFor(RenderManager manager) {
                    return new EntityRenderNone(manager);
                }
            });
    RenderingRegistry.registerEntityRenderingHandler(EntityChemthrowerShot.class,
            new IRenderFactory<EntityChemthrowerShot>() {
                @Override
                public Render createRenderFor(RenderManager manager) {
                    return new EntityRenderChemthrowerShot(manager);
                }
            });
    RenderingRegistry.registerEntityRenderingHandler(EntityRailgunShot.class,
            new IRenderFactory<EntityRailgunShot>() {
                @Override
                public Render createRenderFor(RenderManager manager) {
                    return new EntityRenderRailgunShot(manager);
                }
            });
    RenderingRegistry.registerEntityRenderingHandler(EntityIEExplosive.class,
            new IRenderFactory<EntityIEExplosive>() {
                @Override
                public Render createRenderFor(RenderManager manager) {
                    return new EntityRenderIEExplosive(manager);
                }
            });
    RenderingRegistry.registerEntityRenderingHandler(EntityFluorescentTube.class,
            new IRenderFactory<EntityFluorescentTube>() {
                @Override
                public Render createRenderFor(RenderManager manager) {
                    return new EntityRenderFluorescentTube(manager);
                }
            });
    ModelLoaderRegistry.registerLoader(new ConnLoader());
    ModelLoaderRegistry.registerLoader(new FeedthroughLoader());
    ModelLoaderRegistry.registerLoader(new ModelConfigurableSides.Loader());
    ModelLoaderRegistry.registerLoader(new MultiLayerLoader());
}

From source file:business.ImageManager.java

private Path2D.Double createArrow() {
    int length = this.getYellowBall().getIconWidth() - 5;
    int barb = this.getYellowBall().getIconWidth() / 5;
    double angle = Math.toRadians(20);
    Path2D.Double path = new Path2D.Double();
    path.moveTo(-length / 2, 0);/*from w  w  w.  j  a va2  s. c om*/
    path.lineTo(length / 2, 0);
    double x = length / 2 - barb * Math.cos(angle);
    double y = barb * Math.sin(angle);
    path.lineTo(x, y);
    x = length / 2 - barb * Math.cos(-angle);
    y = barb * Math.sin(-angle);
    path.moveTo(length / 2, 0);
    path.lineTo(x, y);
    return path;
}

From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java

public void createSignatureRectangle(PDSignatureField signatureField, PDFAsVisualSignatureDesigner properties,
        float degrees) throws IOException {

    PDRectangle rect = new PDRectangle();

    Point2D upSrc = new Point2D.Float();
    upSrc.setLocation(properties.getxAxis() + properties.getWidth(),
            properties.getPageHeight() - properties.getyAxis());

    Point2D llSrc = new Point2D.Float();
    llSrc.setLocation(properties.getxAxis(),
            properties.getPageHeight() - properties.getyAxis() - properties.getHeight());

    rect.setUpperRightX((float) upSrc.getX());
    rect.setUpperRightY((float) upSrc.getY());
    rect.setLowerLeftY((float) llSrc.getY());
    rect.setLowerLeftX((float) llSrc.getX());
    logger.debug("orig rectangle of signature has been created: {}", rect.toString());

    AffineTransform transform = new AffineTransform();
    transform.setToIdentity();//  w w  w.  j  a va 2 s  . c o m
    if (degrees % 360 != 0) {
        transform.setToRotation(Math.toRadians(degrees), llSrc.getX(), llSrc.getY());
    }

    Point2D upDst = new Point2D.Float();
    transform.transform(upSrc, upDst);

    Point2D llDst = new Point2D.Float();
    transform.transform(llSrc, llDst);

    float xPos = properties.getxAxis();
    float yPos = properties.getPageHeight() - properties.getyAxis();
    logger.debug("POS {} x {}", xPos, yPos);
    logger.debug("SIZE {} x {}", properties.getWidth(), properties.getHeight());
    // translate according to page! rotation
    int pageRotation = properties.getPageRotation();
    AffineTransform translate = new AffineTransform();
    switch (pageRotation) {
    case 90:
        translate.setToTranslation(
                properties.getPageHeight() - (properties.getPageHeight() - properties.getyAxis())
                        - properties.getxAxis() + properties.getHeight(),
                properties.getxAxis() + properties.getHeight()
                        - (properties.getPageHeight() - properties.getyAxis()));
        break;
    case 180:
        // translate.setToTranslation(properties.getPageWidth() -
        // properties.getxAxis() - properties.getxAxis(),
        // properties.getPageHeight() - properties.getyAxis() +
        // properties.getHeight());
        translate.setToTranslation(properties.getPageWidth() - 2 * xPos,
                properties.getPageHeight() - 2 * (yPos - properties.getHeight()));
        break;
    case 270:
        translate.setToTranslation(-properties.getHeight() + yPos - xPos,
                properties.getPageWidth() - (yPos - properties.getHeight()) - xPos);
        break;
    }

    translate.transform(upDst, upDst);
    translate.transform(llDst, llDst);

    rect.setUpperRightX((float) upDst.getX());
    rect.setUpperRightY((float) upDst.getY());
    rect.setLowerLeftY((float) llDst.getY());
    rect.setLowerLeftX((float) llDst.getX());
    logger.debug("rectangle of signature has been created: {}", rect.toString());
    signatureField.getWidget().setRectangle(rect);
    getStructure().setSignatureRectangle(rect);
    logger.debug("rectangle of signature has been created");
}

From source file:org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.java

private AffineTransform calculateMatrix(PDRectangle bbox, int rotation) {
    if (rotation == 0) {
        return new AffineTransform();
    }//w  w w . j a  v a  2 s.  c o m
    float tx = 0, ty = 0;
    switch (rotation) {
    case 90:
        tx = bbox.getUpperRightY();
        break;
    case 180:
        tx = bbox.getUpperRightY();
        ty = bbox.getUpperRightX();
        break;
    case 270:
        ty = bbox.getUpperRightX();
        break;
    default:
        break;
    }
    Matrix matrix = Matrix.getRotateInstance(Math.toRadians(rotation), tx, ty);
    return matrix.createAffineTransform();

}

From source file:biz.bokhorst.bpt.BPTService.java

public double distanceM(double userLat, double userLng, double venueLat, double venueLng) {
    double latDistance = Math.toRadians(userLat - venueLat);
    double lngDistance = Math.toRadians(userLng - venueLng);
    double a = (Math.sin(latDistance / 2) * Math.sin(latDistance / 2)) + (Math.cos(Math.toRadians(userLat)))
            * (Math.cos(Math.toRadians(venueLat))) * (Math.sin(lngDistance / 2)) * (Math.sin(lngDistance / 2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return 6371 * 1000 * c;
}