Example usage for java.lang Math sin

List of usage examples for java.lang Math sin

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double sin(double a) 

Source Link

Document

Returns the trigonometric sine of an angle.

Usage

From source file:RadialLayout.java

/**
 * This is called when the panel is first displayed, and every time its size
 * changes.//from ww w  .j a  v a2  s  . c  o m
 * Note: You CAN'T assume preferredLayoutSize or minimumLayoutSize will be
 * called -- in the case of applets, at least, they probably won't be.
 *
 * @param  parent  the parent.
 * @see LayoutManager
 */
public void layoutContainer(final Container parent) {
    final Insets insets = parent.getInsets();
    final int maxWidth = parent.getSize().width - (insets.left + insets.right);
    final int maxHeight = parent.getSize().height - (insets.top + insets.bottom);
    final int nComps = parent.getComponentCount();
    int x = 0;
    int y = 0;

    // Go through the components' sizes, if neither preferredLayoutSize nor
    // minimumLayoutSize has been called.
    if (this.sizeUnknown) {
        setSizes(parent);
    }

    if (nComps < 2) {
        final Component c = parent.getComponent(0);
        if (c.isVisible()) {
            final Dimension d = c.getPreferredSize();
            c.setBounds(x, y, d.width, d.height);
        }
    } else {
        double radialCurrent = Math.toRadians(90);
        final double radialIncrement = 2 * Math.PI / nComps;
        final int midX = maxWidth / 2;
        final int midY = maxHeight / 2;
        final int a = midX - this.maxCompWidth;
        final int b = midY - this.maxCompHeight;
        for (int i = 0; i < nComps; i++) {
            final Component c = parent.getComponent(i);
            if (c.isVisible()) {
                final Dimension d = c.getPreferredSize();
                x = (int) (midX - (a * Math.cos(radialCurrent)) - (d.getWidth() / 2) + insets.left);
                y = (int) (midY - (b * Math.sin(radialCurrent)) - (d.getHeight() / 2) + insets.top);

                // Set the component's size and position.
                c.setBounds(x, y, d.width, d.height);
            }
            radialCurrent += radialIncrement;
        }
    }
}

From source file:fr.ritaly.dungeonmaster.audio.SoundSystem.java

private void play(final double angle, final double distance, final AudioClip clip) {

    if (clip == null) {
        throw new IllegalArgumentException("The given audio clip is null");
    }//  w  w  w  .j a v  a2s . c om
    if (!isInitialized()) {
        // On ne lve pas d'erreur pour les tests unitaires
        return;
    }

    if (log.isDebugEnabled()) {
        log.debug("Submitting new task ...");
    }

    executorService.execute(new Runnable() {
        @Override
        public void run() {
            final Sound sound = sounds.get(clip.getSound());

            if (sound == null) {
                throw new IllegalArgumentException("Unsupported sound <" + clip + ">");
            }

            try {
                final Clip clip2 = (Clip) AudioSystem
                        .getLine(new DataLine.Info(Clip.class, sound.getAudioFormat()));

                clip2.addLineListener(new LineListener() {
                    @Override
                    public void update(LineEvent event) {
                        if (event.getType().equals(LineEvent.Type.STOP)) {
                            clip2.close();
                        }
                    }
                });
                clip2.open(sound.getAudioFormat(), sound.getData(), 0, sound.getData().length);

                final DecimalFormat decimalFormat = new DecimalFormat("###.#");

                // Pan dans [-1, +1]
                final FloatControl pan = (FloatControl) clip2.getControl(FloatControl.Type.PAN);

                if (!Double.isNaN(angle)) {

                    final float p = (float) Math.sin(angle);

                    if ((0 <= angle) && (angle <= Math.PI)) {
                        // Son sur la gauche, pan positif
                        pan.setValue(p);
                    } else {
                        // Son sur la droite, pan ngatif
                        pan.setValue(p);
                    }

                    if (log.isDebugEnabled()) {
                        log.debug("Angle = " + decimalFormat.format((angle / Math.PI) * 180) + " / Pan = "
                                + decimalFormat.format(p * 100));
                    }
                } else {
                    pan.setValue(0);
                }

                final double attenuation = Utils.attenuation(distance);

                if (log.isDebugEnabled()) {
                    log.debug("Distance = " + distance + " / Attenuation = "
                            + decimalFormat.format((attenuation * 100)) + "%");
                }

                if (distance != 0) {
                    // Gain dans [-30, 0]
                    final FloatControl gain = (FloatControl) clip2.getControl(FloatControl.Type.MASTER_GAIN);

                    gain.setValue((float) attenuation * -30);
                }

                clip2.loop(0);
            } catch (LineUnavailableException e) {
                throw new RuntimeException(e);
            }
        }
    });

    if (log.isDebugEnabled()) {
        log.debug("Task submitted");
    }
}

From source file:org.jfree.chart.demo.CrossSectionDemo1.java

private static HeatMapDataset createMapDataset() {
    DefaultHeatMapDataset defaultheatmapdataset = new DefaultHeatMapDataset(501, 501, -250D, 250D, -250D, 250D);
    for (int i = 0; i < 501; i++) {
        for (int j = 0; j < 501; j++)
            defaultheatmapdataset.setZValue(i, j, Math.sin(Math.sqrt(i * j) / 10D));

    }/* ww  w.java2  s  .  c o  m*/

    return defaultheatmapdataset;
}

From source file:de.thkwalter.et.schlupfbezifferung.SchlupfbezifferungController.java

/**
 * Diese Methode berechnet das Inversionszentrum (in A). Das Inversionszentrum liegt auf der gedrehten Ortskurve unter 
 * dem Polarwinkel von 315 Grad./* w  w w  .j av a2  s. c o  m*/
 * 
 * @return Das Inversionzentrum (in A)
 */
private Vector2D inversionszentrumBerechnen() {
    // Der Mittelpunkt der gedrehten Ortskurve (in A) wird gelesen.
    Vector2D mittelpunktOrtskurve = this.schlupfbezifferungModell.getOrtskurve().getMittelpunktOrtskurve();
    double m_x = mittelpunktOrtskurve.getX();
    double m_y = mittelpunktOrtskurve.getY();

    // Der Radius der Ortskurve (in A) wird gelesen.
    double r = this.schlupfbezifferungModell.getOrtskurve().getRadiusOrtskurve();

    // Das Inversionszentrum (in A) wird berechnet. 
    double x_0 = m_x + r * Math.cos(7 * Math.PI / 4);
    double y_0 = m_y + r * Math.sin(7 * Math.PI / 4);
    Vector2D inversionszentrum = new Vector2D(x_0, y_0);

    // Das Inversionszentrum (in A) wird zurckgegeben.
    return inversionszentrum;
}

From source file:com.kircherelectronics.accelerationexplorer.filter.ImuLaCfQuaternion.java

public float[] getLinearAcceleration() {
    // values[0]: azimuth, rotation around the Z axis.
    // values[1]: pitch, rotation around the X axis.
    // values[2]: roll, rotation around the Y axis.

    // Find the gravity component of the X-axis
    // = g*-cos(pitch)*sin(roll);
    components[0] = (float) (SensorManager.GRAVITY_EARTH * -Math.cos(fusedOrientation[1])
            * Math.sin(fusedOrientation[2]));

    // Find the gravity component of the Y-axis
    // = g*-sin(pitch);
    components[1] = (float) (SensorManager.GRAVITY_EARTH * -Math.sin(fusedOrientation[1]));

    // Find the gravity component of the Z-axis
    // = g*cos(pitch)*cos(roll);
    components[2] = (float) (SensorManager.GRAVITY_EARTH * Math.cos(fusedOrientation[1])
            * Math.cos(fusedOrientation[2]));

    // Subtract the gravity component of the signal
    // from the input acceleration signal to get the
    // tilt compensated output.
    linearAcceleration[0] = (this.acceleration[0] - components[0]);
    linearAcceleration[1] = (this.acceleration[1] - components[1]);
    linearAcceleration[2] = (this.acceleration[2] - components[2]);

    return linearAcceleration;
}

From source file:Rotation.java

/** Build a rotation from an axis and an angle.
 * <p>We use the convention that angles are oriented according to
 * the effect of the rotation on vectors around the axis. That means
 * that if (i, j, k) is a direct frame and if we first provide +k as
 * the axis and PI/2 as the angle to this constructor, and then
 * {@link #applyTo(Vector3D) apply} the instance to +i, we will get
 * +j.</p>/*from  w w  w.j  av a2s . co  m*/
 * @param axis axis around which to rotate
 * @param angle rotation angle.
 * @exception ArithmeticException if the axis norm is zero
 */
public Rotation(Vector3D axis, double angle) {

    double norm = axis.getNorm();
    if (norm == 0) {
        throw new ArithmeticException("zero norm for rotation axis");
    }

    double halfAngle = -0.5 * angle;
    double coeff = Math.sin(halfAngle) / norm;

    q0 = Math.cos(halfAngle);
    q1 = coeff * axis.getX();
    q2 = coeff * axis.getY();
    q3 = coeff * axis.getZ();

}

From source file:es.udc.gii.common.eaf.benchmark.real_param.cec2005.CEC2005ObjectiveFunction.java

public double F6(double[] x) {
    double temp1, temp2, res = 0;

    for (int i = 0; i < x.length - 1; i++) {
        temp1 = Math.pow((Math.sin(Math.sqrt(Math.pow(x[i], 2) + Math.pow(x[i + 1], 2)))), 2);
        temp2 = 1.0 + 0.001 * (Math.pow(x[i], 2) + Math.pow(x[i + 1], 2));
        res += 0.5 + (temp1 - 0.5) / (Math.pow(temp2, 2));
    }/*w ww  .j a va2 s  .  c o  m*/

    temp1 = Math.pow((Math.sin(Math.sqrt(Math.pow(x[x.length - 1], 2) + Math.pow(x[0], 2)))), 2);
    temp2 = 1.0 + 0.001 * (Math.pow(x[x.length - 1], 2) + Math.pow(x[0], 2));
    res += 0.5 + (temp1 - 0.5) / (Math.pow(temp2, 2));

    return res;
}

From source file:es.emergya.geo.util.Lambert.java

/**
 * Initializes from geographic coordinates. Note that reference ellipsoid
 * used by Lambert is the Clark ellipsoid.
 *
 * @param lat latitude in grad//from   ww  w  .  j a v a  2 s  . c o  m
 * @param lon longitude in grad
 * @param Xs  false east (coordinate system origin) in meters
 * @param Ys  false north (coordinate system origin) in meters
 * @param c   projection constant
 * @param n   projection exponent
 * @return EastNorth projected coordinates in meter
 */
private EastNorth ConicProjection(double lat, double lon, double Xs, double Ys, double c, double n) {
    double eslt = Ellipsoid.clarke.e * Math.sin(lat);
    double l = Math.log(Math.tan(Math.PI / 4.0 + (lat / 2.0))
            * Math.pow((1.0 - eslt) / (1.0 + eslt), Ellipsoid.clarke.e / 2.0));
    double east = Xs + c * Math.exp(-n * l) * Math.sin(n * (lon - lg0));
    double north = Ys - c * Math.exp(-n * l) * Math.cos(n * (lon - lg0));
    return new EastNorth(east, north);
}

From source file:com.alvermont.terraj.fracplanet.geom.Matrix33.java

/**
 * Get a matrix that represents a rotation around the X axis
 *
 * @param angle The angle of rotation desired (in radians)
 * @return The corresponding rotation matrix
 *///from   ww w.j a va  2  s . c  o m
public static Matrix33 getRotateAboutX(float angle) {
    final Matrix33 mat = new Matrix33();

    final float ca = (float) Math.cos(angle);
    final float sa = (float) Math.sin(angle);

    mat.basis[0] = new SimpleXYZ(1.0f, 0.0f, 0.0f);
    mat.basis[1] = new SimpleXYZ(0.0f, ca, sa);
    mat.basis[2] = new SimpleXYZ(0.0f, -sa, ca);

    return mat;
}

From source file:fr.certu.chouette.validation.checkpoint.AbstractValidation.java

/**
 * @see http://mathforum.org/library/drmath/view/51879.html
 *///w w w.  j  a  va2 s .  c o m
private double computeHaversineFormula(NeptuneLocalizedObject obj1, NeptuneLocalizedObject obj2) {

    double lon1 = Math.toRadians(obj1.getLongitude().doubleValue());
    double lat1 = Math.toRadians(obj1.getLatitude().doubleValue());
    double lon2 = Math.toRadians(obj2.getLongitude().doubleValue());
    double lat2 = Math.toRadians(obj2.getLatitude().doubleValue());

    final double R = 6371008.8;

    double dlon = lon2 - lon1;
    double dlat = lat2 - lat1;

    double a = Math.pow((Math.sin(dlat / 2)), 2)
            + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = R * c;

    return d;
}