get Line Degrees - Android java.lang

Android examples for java.lang:Math Geometry

Description

get Line Degrees

Demo Code


//package com.java2s;

public class Main {

    public static float getLineDegrees(float startX, float startY,
            float endX, float endY) {
        return (float) (Math
                .toDegrees(getRadian(startX, startY, endX, endY)));
    }//ww  w.j  a v a2s  .c  o m

    public static double getRadian(float x, float y, float centerX,
            float centerY) {
        double radian = 0;
        y -= centerY;
        x -= centerX;
        double delt = Math.abs(y / x);
        if (y > 0 && x > 0) {
            radian = Math.atan(delt);
        } else if (y > 0 && x < 0) {
            radian = Math.PI - Math.atan(delt);
        } else if (y < 0 && x < 0) {
            radian = Math.PI + Math.atan(delt);
        } else if (y < 0 && x > 0) {
            radian = 2 * Math.PI - Math.atan(delt);
        }
        return radian;
        // return Math.atan2(x, y);
    }
}

Related Tutorials