package com.base.orbit.utils;

import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


@Component
public class DistanceCount {

    public static double Re = 6378;

    public List<Double> distanceVal(List<Double> elevations, double h) {
        List<Double> distances = new ArrayList<>();
        for (Double elevation : elevations) {
            /*星地距离计算*/
            double elevationrad = Math.toRadians(elevation);
            double d = Math.sqrt(Math.pow(Re, 2) * Math.pow(Math.sin(elevationrad), 2) + 2 * h * Re + Math.pow(h, 2)) - Re * Math.sin(elevationrad);
            BigDecimal bigDecimal = new BigDecimal(d);
            double val = bigDecimal.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
            distances.add(val);
        }
        return distances;
    }
}
