//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.base.core.source;

import com.base.core.model.enity.EphData;
import com.base.core.model.enity.SphericalPoint;

public class GlobeMath {
    public static int POINT_LEFT = 0;
    public static int POINT_RIGHT = 1;

    public GlobeMath() {
    }

    public static Position computePositionFromPosition(Position pos, Angle heading, double width, int type) {
        Position posA = null;
        double globeRadius = 0.0D;
        double azimuth = 0.0D;
        LatLon ll = LatLon.ZERO;
        globeRadius = RadiansDic.queryradians(pos.getLatitude().getDegrees());
        double distance = Math.abs(width) / globeRadius;
        if (type == POINT_LEFT) {
            azimuth = heading.radians + 1.5707963267948966D;
        } else if (type == POINT_RIGHT) {
            azimuth = heading.radians - 1.5707963267948966D;
        }

        ll = LatLon.greatCircleEndPosition(pos, azimuth, distance);
        posA = new Position(ll, pos.getAltitude());
        return posA;
    }
    public static LatLon computePositionFromPosition(LatLon pos, Angle heading, double width, int type) {
        double globeRadius = RadiansDic.queryradians(pos.getLatitude().getDegrees());
        double distance = Math.abs(width) / (globeRadius / 1000);
        return computePositionFromPositionByRadWidth(pos, heading, distance, type);
    }
    public static LatLon computePositionFromPositionByRadWidth(LatLon pos, Angle heading, double width, int type) {
        LatLon posA = null;           /* 计算的点 */
        double globeRadius = 0;         /* 地球半径 */
        double azimuth = 0;             /* 方位角 */
        LatLon ll = LatLon.ZERO;
        if (type == POINT_LEFT) {
            /* Vertex1 */
            azimuth = heading.radians + (Math.PI / 2);
        } else if (type == POINT_RIGHT) {
            /* Vertex2 */
            azimuth = heading.radians - (Math.PI / 2);
        }
        posA = LatLon.greatCircleEndPosition(pos, azimuth, width);
        return posA;
    }

    public static double distanceIngeoLatLon(EphData subPoint, SphericalPoint target) {

        double globeRadius = RadiansDic.queryradians(target.getLat());

        double distance = Math.cos((90.0 - subPoint.getLat()) * Math.PI / 180.0)
                * Math.cos((90.0 - target.getLat()) * Math.PI / 180.0)
                + Math.sin((90.0 - subPoint.getLat()) * Math.PI / 180.0)
                * Math.sin((90.0 - target.getLat()) * Math.PI / 180.0)
                * Math.cos(Math.abs(subPoint.getLon() - target.getLon()) * Math.PI / 180.0);
        distance = Math.acos(distance) * globeRadius / 1000;//
        return distance;
    }

}
