package com.tofly.ghrq_route.common.util.degree;

import android.util.Log;

import com.esri.arcgisruntime.geometry.AngularUnit;
import com.esri.arcgisruntime.geometry.AngularUnitId;
import com.esri.arcgisruntime.geometry.Point;

/**
 * Created by li on 2016/8/29.
 */
public class DegreeUtil {
    //传入点获取角度
    public static double MeasuringDegree(Point pointC, Point pointB, Point pointA,
                                         AngularUnit angularUnite) {
        double bcLen;
        double baLen;
        double acLen;
        double cX = pointC.getX();
        double cY = pointC.getY();
        double bX = pointB.getX();
        double bY = pointB.getY();
        double aX = pointA.getX();
        double aY = pointA.getY();
        double absBCX = Math.abs(cX - bX);
        double absBCY = Math.abs(cY - bY);
        double absBAX = Math.abs(bX - aX);
        double absBAY = Math.abs(bY - aY);
        double absACX = Math.abs(cX - aX);
        double absACY = Math.abs(cY - aY);
        acLen = Math.sqrt((absACX * absACX) + (absACY * absACY));
        bcLen = Math.sqrt((absBCX * absBCX) + (absBCY * absBCY));
        baLen = Math.sqrt((absBAX * absBAX) + (absBAY * absBAY));
//        BigDecimal bc = new BigDecimal(bcLen);
//        double a = bc.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//        BigDecimal ba = new BigDecimal(baLen);
//        double c = ba.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//        BigDecimal ac = new BigDecimal(acLen);
//        double b = ac.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//
//        double aa = a * a;
        double aa = bcLen * bcLen;
//        double cc = c * c;
        double cc = baLen * baLen;
//        double bb = b * b;
        double bb = acLen * acLen;
        double cosB = (aa + cc - bb) / (2 * bcLen * baLen);
        double mResult = Math.acos(cosB)*(180/Math.PI);
        Log.w("TAG", "draw: cosB = " + cosB);
        Log.w("TAG", "draw: mResult = " + mResult);
        AngularUnitId id = angularUnite.getAngularUnitId();
        if (id == AngularUnitId.RADIANS) {
            mResult = Math.toRadians(mResult);
        }
        return mResult;
//        String unit = angularUnite.getDisplayName();
//        angularUnite.
//        switch (unit){
//            case AngularUnit.Code.RADIAN:
//        }
    }
}
