Example usage for java.lang Math cos

List of usage examples for java.lang Math cos

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double cos(double a) 

Source Link

Document

Returns the trigonometric cosine of an angle.

Usage

From source file:geogebra.kernel.EquationSolver.java

final public int solveCubic(double eqn[], double res[]) {

    int roots = 0;
    double d = eqn[3];
    if (Math.abs(d) < kernel.EPSILON) {
        // The cubic has degenerated to quadratic (or line or ...).
        return solveQuadratic(eqn, res);
    }/*  w  w  w .j a v a2  s. c o m*/
    double a = eqn[2] / d;
    double b = eqn[1] / d;
    double c = eqn[0] / d;
    double q = (a * a - 3 * b); //D(q) = 2aD(a) + 3D(b)
    double r = (2 * a * a * a - 9 * a * b + 27 * c); // D(r) = (3aa-9b)D(a) - 9aD(b) + 27D(c)

    double Q = q / 9; //D(Q) = D(q)/9
    double R = r / 54;

    double Q3 = Q * Q * Q;
    double R2 = R * R;

    double CR2 = 729 * r * r; // D(CR2) = 729*2rD(r)    ( |1458r(3aa-9b) - 8748q*2a| + |-9a*1458r -8748q*3| + |27*1458r| )*kernel.EPSILON 
    double CQ3 = 2916 * q * q * q; //D(CQ3) = 2916*3qD(q)  (D(root) ~ D(2sqrt(Q))= -1/sqrt(Q)  D(Q), |D(root)| |2a+3|/sqrt(9q) *kernel.EPSILON

    //Application.debug("Q = "+Q+" R = "+R+" Q3 = "+Q3+" R2 = "+R2+" CR2 = "+CR2+" CQ3 = "+CQ3);

    //Application.debug(Math.abs(CR2 - CQ3)+"");

    if (Math.abs(R) < kernel.EPSILON && Math.abs(Q) < kernel.EPSILON) // if (R == 0 && Q == 0)
    {
        res[roots++] = -a / 3;
        res[roots++] = -a / 3;
        res[roots++] = -a / 3;
        return 3;
    }
    // Michael Borcherds changed to check CR2 equal to CQ3 to first 8 significant digits
    // important for eg y=(ax-b)^2(cx-d)
    // |D(CR2-CQ3)|< (|r(aa-3b) - 4qa| + |-3ar -6q| + |9r|)*13122*sqrt(q) / |2a+3| *kernel.EPSILON
    // for simplicity, it (may be)  about 10* max(CR2,CR3)/|2a+3| * kernel.EPSILON
    //else if (Math.abs(CR2 - CQ3) < Math.max(CR2, CQ3) * kernel.EPSILON) // else if (CR2 == CQ3)
    else if (Math.abs(CR2 - CQ3) < Math.max(CR2, CQ3) * 10 / Math.max(1, Math.abs(2 * a + 3)) * kernel.EPSILON) // else if (CR2 == CQ3) 
    {
        // this test is actually R2 == Q3, written in a form suitable
        //     for exact computation with integers 

        // Due to finite precision some double roots may be missed, and
        //     considered to be a pair of complex roots z = x +/- kernel.EPSILON i
        //     close to the real axis. 

        double sqrtQ = Math.sqrt(Q);

        if (R > 0) {
            res[roots++] = -2 * sqrtQ - a / 3;
            res[roots++] = sqrtQ - a / 3;
            res[roots++] = sqrtQ - a / 3;
        } else {
            res[roots++] = -sqrtQ - a / 3;
            res[roots++] = -sqrtQ - a / 3;
            res[roots++] = 2 * sqrtQ - a / 3;
        }
        return 3;
    } else if (CR2 < CQ3) // equivalent to R2 < Q3 
    {
        double sqrtQ = Math.sqrt(Q);
        double sqrtQ3 = sqrtQ * sqrtQ * sqrtQ;
        double theta = Math.acos(R / sqrtQ3);
        double norm = -2 * sqrtQ;
        res[roots++] = norm * Math.cos(theta / 3) - a / 3;
        res[roots++] = norm * Math.cos((theta + 2.0 * Math.PI) / 3) - a / 3;
        res[roots++] = norm * Math.cos((theta - 2.0 * Math.PI) / 3) - a / 3;

        // GeoGebra addition
        //TODO: find a better way to deal with this
        if (res != eqn) //if res has the same reference as eqn, it's not possible to fix roots
            fixRoots(res, eqn);

        return 3;
    } else {
        double sgnR = (R >= 0 ? 1 : -1);
        double A = -sgnR * Math.pow(Math.abs(R) + Math.sqrt(R2 - Q3), 1.0 / 3.0);
        double B = Q / A;
        res[roots++] = A + B - a / 3;
        return 1;
    }
}

From source file:com.ibm.bi.dml.runtime.functionobjects.Builtin.java

public double execute(double in) throws DMLRuntimeException {
    switch (bFunc) {
    case SIN:/*w w  w  .  j  ava  2s .  c  o m*/
        return FASTMATH ? FastMath.sin(in) : Math.sin(in);
    case COS:
        return FASTMATH ? FastMath.cos(in) : Math.cos(in);
    case TAN:
        return FASTMATH ? FastMath.tan(in) : Math.tan(in);
    case ASIN:
        return FASTMATH ? FastMath.asin(in) : Math.asin(in);
    case ACOS:
        return FASTMATH ? FastMath.acos(in) : Math.acos(in);
    case ATAN:
        return Math.atan(in); //faster in Math
    case CEIL:
        return FASTMATH ? FastMath.ceil(in) : Math.ceil(in);
    case FLOOR:
        return FASTMATH ? FastMath.floor(in) : Math.floor(in);
    case LOG:
        //if ( in <= 0 )
        //   throw new DMLRuntimeException("Builtin.execute(): logarithm can only be computed for non-negative numbers (input = " + in + ").");
        // for negative numbers, Math.log will return NaN
        return FASTMATH ? FastMath.log(in) : Math.log(in);
    case LOG_NZ:
        return (in == 0) ? 0 : FASTMATH ? FastMath.log(in) : Math.log(in);

    case ABS:
        return Math.abs(in); //no need for FastMath

    case SQRT:
        //if ( in < 0 )
        //   throw new DMLRuntimeException("Builtin.execute(): squareroot can only be computed for non-negative numbers (input = " + in + ").");
        return Math.sqrt(in); //faster in Math

    case PLOGP:
        if (in == 0.0)
            return 0.0;
        else if (in < 0)
            return Double.NaN;
        else
            return (in * (FASTMATH ? FastMath.log(in) : Math.log(in)));

    case EXP:
        return FASTMATH ? FastMath.exp(in) : Math.exp(in);

    case ROUND:
        return Math.round(in); //no need for FastMath

    case SPROP:
        //sample proportion: P*(1-P)
        return in * (1 - in);

    case SIGMOID:
        //sigmoid: 1/(1+exp(-x))
        return FASTMATH ? 1 / (1 + FastMath.exp(-in)) : 1 / (1 + Math.exp(-in));

    case SELP:
        //select positive: x*(x>0)
        return (in > 0) ? in : 0;

    default:
        throw new DMLRuntimeException("Builtin.execute(): Unknown operation: " + bFunc);
    }
}

From source file:geogebra.common.kernel.EquationSolver.java

final public int solveCubic(double eqn[], double res[], double eps) {

    int roots = 0;
    double d = eqn[3];
    if (Math.abs(d) < eps) {
        // The cubic has degenerated to quadratic (or line or ...).
        return solveQuadratic(eqn, res, eps);
    }//from  w w w.j a  v  a  2 s.  co m
    double a = eqn[2] / d;
    double b = eqn[1] / d;
    double c = eqn[0] / d;
    double q = (a * a - 3 * b); // D(q) = 2aD(a) + 3D(b)
    double r = (2 * a * a * a - 9 * a * b + 27 * c); // D(r) = (3aa-9b)D(a)
    // - 9aD(b) + 27D(c)

    double Q = q / 9; // D(Q) = D(q)/9
    double R = r / 54;

    double Q3 = Q * Q * Q;
    double R2 = R * R;

    double CR2 = 729 * r * r; // D(CR2) = 729*2rD(r) ( |1458r(3aa-9b) -
    // 8748q*2a| + |-9a*1458r -8748q*3| +
    // |27*1458r| )*kernel.STANDARD_PRECISION
    double CQ3 = 2916 * q * q * q; // D(CQ3) = 2916*3qD(q) (D(root) ~
    // D(2sqrt(Q))= -1/sqrt(Q) D(Q),
    // |D(root)| |2a+3|/sqrt(9q)
    // *kernel.STANDARD_PRECISION

    // Application.debug("Q = "+Q+" R = "+R+" Q3 = "+Q3+" R2 = "+R2+" CR2 = "+CR2+" CQ3 = "+CQ3);

    // Application.debug(Math.abs(CR2 - CQ3)+"");

    if (Math.abs(R) < Kernel.STANDARD_PRECISION && Math.abs(Q) < Kernel.STANDARD_PRECISION) // if
    // (R
    // ==
    // 0
    // &&
    // Q
    // ==
    // 0)
    {
        res[roots++] = -a / 3;
        res[roots++] = -a / 3;
        res[roots++] = -a / 3;
        return 3;
    }
    // Michael Borcherds changed to check CR2 equal to CQ3 to first 8
    // significant digits
    // important for eg y=(ax-b)^2(cx-d)
    // |D(CR2-CQ3)|< (|r(aa-3b) - 4qa| + |-3ar -6q| + |9r|)*13122*sqrt(q) /
    // |2a+3| *kernel.STANDARD_PRECISION
    // for simplicity, it (may be) about 10* max(CR2,CR3)/|2a+3| *
    // kernel.STANDARD_PRECISION
    // else if (Math.abs(CR2 - CQ3) < Math.max(CR2, CQ3) *
    // kernel.STANDARD_PRECISION)
    // // else if (CR2 == CQ3)
    else if (Math.abs(CR2 - CQ3) < Math.max(CR2, CQ3) * 10 / Math.max(1, Math.abs(2 * a + 3))
            * Kernel.STANDARD_PRECISION) // else
    // if
    // (CR2
    // ==
    // CQ3)
    {
        // this test is actually R2 == Q3, written in a form suitable
        // for exact computation with integers

        // Due to finite precision some double roots may be missed, and
        // considered to be a pair of complex roots z = x +/-
        // kernel.STANDARD_PRECISION
        // i
        // close to the real axis.

        double sqrtQ = Math.sqrt(Q);

        if (R > 0) {
            res[roots++] = -2 * sqrtQ - a / 3;
            res[roots++] = sqrtQ - a / 3;
            res[roots++] = sqrtQ - a / 3;
        } else {
            res[roots++] = -sqrtQ - a / 3;
            res[roots++] = -sqrtQ - a / 3;
            res[roots++] = 2 * sqrtQ - a / 3;
        }
        return 3;
    } else if (CR2 < CQ3) // equivalent to R2 < Q3
    {
        double sqrtQ = Math.sqrt(Q);
        double sqrtQ3 = sqrtQ * sqrtQ * sqrtQ;
        double theta = Math.acos(R / sqrtQ3);
        double norm = -2 * sqrtQ;
        res[roots++] = norm * Math.cos(theta / 3) - a / 3;
        res[roots++] = norm * Math.cos((theta + 2.0 * Math.PI) / 3) - a / 3;
        res[roots++] = norm * Math.cos((theta - 2.0 * Math.PI) / 3) - a / 3;

        // GeoGebra addition
        // TODO: find a better way to deal with this
        if (res != eqn) // if res has the same reference as eqn, it's not
            // possible to fix roots
            fixRoots(res, eqn);

        return 3;
    } else {
        double sgnR = (R >= 0 ? 1 : -1);
        double A = -sgnR * Math.pow(Math.abs(R) + Math.sqrt(R2 - Q3), 1.0 / 3.0);
        double B = Q / A;
        res[roots++] = A + B - a / 3;
        return 1;
    }
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.Control.java

protected boolean isWithinWithRotation(Point position) {
    // topleft, topright, bottomright, bottomleft
    // get points centered at (0, 0)
    Size size = getSize();/*  www  . j  a va 2s  . c  o m*/
    Point[] points = new Point[4];
    points[0] = new Point(-1 * (size.getWidth() / 2.0f), (size.getHeight() / 2.0f));
    points[1] = new Point((size.getWidth() / 2.0f), (size.getHeight() / 2.0f));
    points[2] = new Point((size.getWidth() / 2.0f), -1 * (size.getHeight() / 2.0f));
    points[3] = new Point(-1 * (size.getWidth() / 2.0f), -1 * (size.getHeight() / 2.0f));
    /*
    log.info("Vertices:");
    for(int i = 0; i < points.length; i++) {
    log.info("\t"+points[i].toString());
    }
    */

    // rotate at (0, 0)
    double rotationInDegree = getRotation();
    double rotationInRadian = Math.toRadians(rotationInDegree);
    for (Point point : points) {
        double rotatedX = (point.getX() * Math.cos(rotationInRadian))
                - (point.getY() * Math.sin(rotationInRadian));
        double rotatedY = (point.getX() * Math.sin(rotationInRadian))
                + (point.getY() * Math.cos(rotationInRadian));
        point.set((float) rotatedX, (float) rotatedY);
    }
    /*
    log.info("Rotated Vertices:");
    for(int i = 0; i < points.length; i++) {
    log.info("\t"+points[i].toString());
    }
    */

    // check to see if position is above or below the slope of sides of
    // this rectangle
    DisplayMode displayMode = windowManager.getDisplayManager().getCurrentDisplayMode();
    Point center = getOpenGlPosition();
    Point centeredPosition = OpenGlUtility
            .getOpenGlPosition(new Size(displayMode.getWidth(), displayMode.getHeight()), position);
    //log.info("Position GL: "+centeredPosition.toString());
    centeredPosition.minus(center);
    //log.info("Center: "+center.toString());
    //log.info("Position: "+position.toString());
    //log.info("Centered: "+centeredPosition.toString());

    boolean[] results = new boolean[points.length];
    for (int i = 0; i < points.length; i++) {
        Point target1 = points[i];
        Point target2 = points[((i + 1) % points.length)];
        Point target3 = points[((i + 2) % points.length)];

        double targetValue = (centeredPosition.getY() - target1.getY());
        if (target2.getX() != target1.getX()) {
            targetValue = (centeredPosition.getY() - target1.getY())
                    - ((target2.getY() - target1.getY()) / (target2.getX() - target1.getX()))
                            * (centeredPosition.getX() - target1.getX());
        }
        double testValue = (target3.getY() - target1.getY());
        if (target2.getX() != target1.getX()) {
            testValue = (target3.getY() - target1.getY())
                    - ((target2.getY() - target1.getY()) / (target2.getX() - target1.getX()))
                            * (target3.getX() - target1.getX());
        }
        //log.info("target: "+targetValue+", test: "+testValue);

        results[i] = (targetValue == 0.0);
        if (((targetValue > 0.0) && (testValue > 0.0)) || ((targetValue < 0.0) && (testValue < 0.0))) {
            results[i] = true;
        }
    }
    /*
    log.info("Results:");
    for(int i = 0; i < results.length; i++) {
    log.info("\t"+results[i]);
    }
    */

    boolean isWithin = true;
    for (boolean result : results) {
        if (!result) {
            isWithin = false;
            break;
        }
    }
    /*
    float[] results = new float[points.length];
    for(int i = 0; i < points.length; i++) {
    Point target1 = points[i];
    Point target2 = points[((i + 1) % points.length)];
            
    float targetValue = (centeredPosition.getY() - target1.getY());
    if(target2.getX() != target1.getX()) {
        targetValue = (centeredPosition.getY() - target1.getY()) -
            ((target2.getY() - target1.getY()) / (target2.getX() - target1.getX())) *
            (centeredPosition.getX() - target1.getX());
    }
    results[i] = targetValue;
    }
    log.info("Results:");
    for(int i = 0; i < results.length; i++) {
    log.info("\t"+results[i]);
    }
            
    boolean isWithin = false;
    for(float result : results) {
    if(result == 0.0f) {
        isWithin = true;
        break;
    }
    }
    if(!isWithin) {
    int numberOfAboves = 0;
    for(float result : results) {
        if(result > 0.0f) {
            numberOfAboves += 1;
        }
    }
    if(numberOfAboves == 2) {
        isWithin = true;
    }
    }
    */

    //log.info("isWithin: "+isWithin);

    return isWithin;
}

From source file:com.oncore.calorders.core.utils.FormatHelper.java

public static Double getGpsDistance(Double lat1, Double lon1, Double lat2, Double lon2) {
    Double distance;//w w w. ja va2  s.c o m

    if (lat1 == null || lon1 == null || lat2 == null || lon2 == null) {
        //throw new IllegalArgumentException("Coordinates passed can not be null");
        distance = 1000d;
    } else {

        double radius = 6371 * 0.621371;
        double dLat = (lat2 - lat1) * Math.PI / 180;
        double dLon = (lon2 - lon1) * Math.PI / 180;

        double arc = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 * Math.PI / 180)
                * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLon / 2) * Math.sin(dLon / 2);

        double curve = 2 * Math.atan2(Math.sqrt(arc), Math.sqrt(1 - arc));

        distance = radius * curve;

    }

    return distance;
}

From source file:electrical_parameters.Carson.java

public void calcRg() {
    //        this.Rg = this.Dik.copy();
    //        this.Rg = clearMatrix(this.Rg);
    double[] b;//from w ww .  j  av  a2s  . c  o m
    double[] c;
    double[] d;
    double kik_rg;
    double fik;

    b = b();
    c = c();
    d = d();
    calckik();

    for (int i = 0; i < this.kik.getRowDimension(); i++) {
        for (int j = 0; j < this.kik.getColumnDimension(); j++) {
            fik = this.Fik.getEntry(i, j);
            kik_rg = this.kik.getEntry(i, j);
            this.Rg.setEntry(i, j, (4e-4) * omega * (Math.PI / 8 - b[0] * kik_rg * Math.cos(fik)
                    + b[1] * ((c[1] - Math.log(kik_rg)) * pow(kik_rg, 2) * Math.cos(2 * fik)
                            + fik * pow(kik_rg, 2) * Math.sin(2 * fik))
                    + b[2] * pow(kik_rg, 3) * Math.cos(3 * fik) - d[3] * pow(kik_rg, 4) * Math.cos(4 * fik)
                    - b[4] * kik_rg * Math.cos(fik)
                    + b[5] * ((c[5] - Math.log(kik_rg)) * pow(kik_rg, 2) * Math.cos(2 * fik)
                            + fik * pow(kik_rg, 2) * Math.sin(2 * fik))
                    + b[6] * pow(kik_rg, 3) * Math.cos(3 * fik) - d[7] * pow(kik_rg, 4) * Math.cos(4 * fik)));
        }
    }
}

From source file:ddf.catalog.source.opensearch.impl.OpenSearchParserImpl.java

/**
 * Takes in a point radius search and converts it to a (rough approximation) bounding box.
 *
 * @param lon latitude in decimal degrees (WGS-84)
 * @param lat longitude in decimal degrees (WGS-84)
 * @param radius radius, in meters/*from   ww  w .j  av a2 s .co m*/
 * @return Array of bounding box coordinates in the following order: West South East North. Also
 *     described as minX, minY, maxX, maxY (where longitude is the X-axis, and latitude is the
 *     Y-axis).
 */
private double[] createBBoxFromPointRadius(double lon, double lat, double radius) {
    double minX;
    double minY;
    double maxX;
    double maxY;

    double lonDifference = radius / (LAT_DEGREE_M * Math.cos(lat));
    double latDifference = radius / LAT_DEGREE_M;
    minX = lon - lonDifference;
    if (minX < MIN_LON) {
        minX += MAX_ROTATION;
    }
    maxX = lon + lonDifference;
    if (maxX > MAX_LON) {
        maxX -= MAX_ROTATION;
    }
    minY = lat - latDifference;
    if (minY < MIN_LAT) {
        minY = Math.abs(minY + MAX_LAT) - MAX_LAT;
    }
    maxY = lat + latDifference;
    if (maxY > MAX_LAT) {
        maxY = MAX_LAT - (maxY - MAX_LAT);
    }

    return new double[] { minX, minY, maxX, maxY };
}

From source file:Matrix4x4.java

/**
 * Apply rotation around X axis to this matrix.
 * // w  ww . j ava 2  s .  c  om
 * @param angle  Angle to rotate [radians].
 */
public void rotateX(double angle) {
    Matrix4x4 rotationMatrix = new Matrix4x4();

    double cosAngle = Math.cos(angle);
    double sinAngle = Math.sin(angle);

    rotationMatrix.setElement(1, 1, cosAngle);
    rotationMatrix.setElement(1, 2, sinAngle);
    rotationMatrix.setElement(2, 1, -sinAngle);
    rotationMatrix.setElement(2, 2, cosAngle);

    multiply(rotationMatrix);
}

From source file:org.trade.ui.chart.renderer.PivotRenderer.java

/**
 * Draws the annotation.//  w w w .  j a  v a2 s .co m
 * 
 * @param g2
 *            the graphics device.
 * @param plot
 *            the plot.
 * @param dataArea
 *            the data area.
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param rendererIndex
 *            the renderer index.
 * @param info
 *            the plot rendering info.
 * @param angle
 *            double
 * @param x
 *            double
 * @param y
 *            double
 * @param ledgend
 *            String
 */
public void drawPivotArrow(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis,
        ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info, double angle, double x, double y,
        String ledgend) {

    double tipRadius = DEFAULT_TIP_RADIUS;
    double baseRadius = DEFAULT_BASE_RADIUS;
    double arrowLength = DEFAULT_ARROW_LENGTH;
    double arrowWidth = DEFAULT_ARROW_WIDTH;
    double labelOffset = DEFAULT_LABEL_OFFSET;
    Font font = DEFAULT_FONT;
    Paint paint = DEFAULT_PAINT;
    boolean outlineVisible = false;
    Paint outlinePaint = Color.black;
    Stroke outlineStroke = new BasicStroke(0.5f);

    TextAnchor textAnchor = DEFAULT_TEXT_ANCHOR;
    TextAnchor rotationAnchor = DEFAULT_ROTATION_ANCHOR;
    double rotationAngle = DEFAULT_ROTATION_ANGLE;

    Stroke arrowStroke = new BasicStroke(1.0f);
    Paint arrowPaint = Color.black;

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    double j2DX = domainAxis.valueToJava2D(x, dataArea, domainEdge);
    double j2DY = rangeAxis.valueToJava2D(y, dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        double temp = j2DX;
        j2DX = j2DY;
        j2DY = temp;
    }
    double startX = j2DX + (Math.cos(angle) * baseRadius);
    double startY = j2DY + (Math.sin(angle) * baseRadius);

    double endX = j2DX + (Math.cos(angle) * tipRadius);
    double endY = j2DY + (Math.sin(angle) * tipRadius);

    double arrowBaseX = endX + (Math.cos(angle) * arrowLength);
    double arrowBaseY = endY + (Math.sin(angle) * arrowLength);

    double arrowLeftX = arrowBaseX + (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth);
    double arrowLeftY = arrowBaseY + (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth);

    double arrowRightX = arrowBaseX - (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth);
    double arrowRightY = arrowBaseY - (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth);

    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) endX, (float) endY);
    arrow.lineTo((float) arrowLeftX, (float) arrowLeftY);
    arrow.lineTo((float) arrowRightX, (float) arrowRightY);
    arrow.closePath();

    g2.setStroke(arrowStroke);
    g2.setPaint(arrowPaint);
    Line2D line = new Line2D.Double(startX, startY, endX, endY);
    g2.draw(line);
    g2.fill(arrow);

    // draw the label
    double labelX = j2DX + (Math.cos(angle) * (baseRadius + labelOffset));
    double labelY = j2DY + (Math.sin(angle) * (baseRadius + labelOffset));
    g2.setFont(font);
    Shape hotspot = TextUtilities.calculateRotatedStringBounds(ledgend, g2, (float) labelX, (float) labelY,
            textAnchor, rotationAngle, rotationAnchor);
    g2.setPaint(paint);
    TextUtilities.drawRotatedString(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle,
            rotationAnchor);
    if (outlineVisible) {
        g2.setStroke(outlineStroke);
        g2.setPaint(outlinePaint);
        g2.draw(hotspot);
    }

    // String toolTip = getToolTipText();
    // String url = getURL();
    // if (toolTip != null || url != null) {
    // addEntity(info, hotspot, rendererIndex, toolTip, url);
    // }

}

From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.ImuOCfQuaternion.java

/**
 * Calculates a rotation vector from the gyroscope angular speed values.
 * /*  w w w  .  ja  v a 2  s  . c om*/
 * @param gyroValues
 * @param deltaRotationVector
 * @param timeFactor
 * @see http://developer.android
 *      .com/reference/android/hardware/SensorEvent.html#values
 */
private void getRotationVectorFromGyro() {
    // Calculate the angular speed of the sample
    float magnitude = (float) Math
            .sqrt(Math.pow(vGyroscope[0], 2) + Math.pow(vGyroscope[1], 2) + Math.pow(vGyroscope[2], 2));

    // Normalize the rotation vector if it's big enough to get the axis
    if (magnitude > EPSILON) {
        vGyroscope[0] /= magnitude;
        vGyroscope[1] /= magnitude;
        vGyroscope[2] /= magnitude;
    }

    // Integrate around this axis with the angular speed by the timestep
    // in order to get a delta rotation from this sample over the timestep
    // We will convert this axis-angle representation of the delta rotation
    // into a quaternion before turning it into the rotation matrix.
    float thetaOverTwo = magnitude * dT / 2.0f;
    float sinThetaOverTwo = (float) Math.sin(thetaOverTwo);
    float cosThetaOverTwo = (float) Math.cos(thetaOverTwo);

    vDeltaGyroscope[0] = sinThetaOverTwo * vGyroscope[0];
    vDeltaGyroscope[1] = sinThetaOverTwo * vGyroscope[1];
    vDeltaGyroscope[2] = sinThetaOverTwo * vGyroscope[2];
    vDeltaGyroscope[3] = cosThetaOverTwo;

    // Create a new quaternion object base on the latest rotation
    // measurements...
    quatGyroDelta = new Quaternion(vDeltaGyroscope[3], Arrays.copyOfRange(vDeltaGyroscope, 0, 3));

    // Since it is a unit quaternion, we can just multiply the old rotation
    // by the new rotation delta to integrate the rotation.
    quatGyro = quatGyro.multiply(quatGyroDelta);
}