get Degree By Point - Android Graphics

Android examples for Graphics:Path Point

Description

get Degree By Point

Demo Code


//package com.java2s;

public class Main {
    public static float getDegreeByPoint(double fromPointX,
            double fromPointY, double toPointX, double toPointY) {
        double x = Math.abs(toPointX) - Math.abs(fromPointX);
        double y = Math.abs(toPointY) - Math.abs(fromPointY);
        double temp = Math.atan2(Math.abs(y), Math.abs(x));
        double dushu;
        dushu = Math.toDegrees(temp);
        if (x > 0 && y > 0) {
            dushu = 180 - dushu;//w  w w .  jav  a  2  s. c o  m
        } else if (x < 0 && y < 0) {
            dushu = 360 - dushu;
        } else if (x > 0 && y < 0) {
            dushu = 180 + dushu;
        }
        return (float) dushu;
    }
}

Related Tutorials