Android 卫星通信计算方位角,仰角,极化角

需求描述: 已知手机的经纬度和高度信息,需要通过公式计算出手机收星的最优方位和仰角,用以调整UI界面显示,以便引导用户实现和当前卫星方位和仰角的对准,达到快速入网的目的。

术语说明

术语 说明
方位角 手机天线在所处位置针对北极的偏转角度,顺时针为正,逆时针为负
仰角 手机天线在所处位置针对地平面的仰角
极化角 天线馈源和电磁波的夹角,方位角和仰角的调节参数
java 复制代码
  /**
     * 计算卫星天线的方位角
     *
     * @param satelliteLongitude 卫星经度
     * @param satelliteLatitude  卫星纬度(或赤纬)
     * @param receiverLongitude  接收地经度
     * @param receiverLatitude   接收地纬度
     * @return 方位角(以弧度为单位)
     */
    public static double calculateAzimuth(double satelliteLongitude, double satelliteLatitude,
                                          double receiverLongitude, double receiverLatitude) {
        // 将角度转换为弧度
        double satLonRad = Math.toRadians(satelliteLongitude);
        double satLatRad = Math.toRadians(satelliteLatitude);
        double recLonRad = Math.toRadians(receiverLongitude);
        double recLatRad = Math.toRadians(receiverLatitude);

        // 计算经度差
        double deltaLambda = satLonRad - recLonRad;

        // 计算方位角
        double azimuthRad = Math.atan2(Math.sin(deltaLambda),
                Math.cos(recLatRad) * Math.tan(satLatRad) - Math.sin(recLatRad) * Math.cos(deltaLambda));

        // 如果需要,将方位角转换为度数
        double azimuthDeg = Math.toDegrees(azimuthRad);

        // 如果需要,将方位角调整到0-360度范围
//        if (azimuthDeg < 0) {
//            azimuthDeg += 360;
//        }

        return azimuthDeg;
    }

    /**
     * 计算卫星仰角
     *
     * @param satLat 卫星纬度(度)
     * @param satLon 卫星经度(度)
     * @param recLat 接收地纬度(度)
     * @param recLon 接收地经度(度)
     * @param satAlt 卫星高度(千米,相对于地球表面)
     * @return 仰角(度)
     */
    public static double calculateElevation(double satLat, double satLon, double recLat, double recLon, double satAlt) {
        // 将角度转换为弧度
        double satLatRad = Math.toRadians(satLat);
        double satLonRad = Math.toRadians(satLon);
        double recLatRad = Math.toRadians(recLat);
        double recLonRad = Math.toRadians(recLon);

        // 地球半径,单位:千米
        double earthRadius = 6371.0;

        // 卫星到地心的距离,单位:千米
        double satelliteToEarthCenter = earthRadius + satAlt;

        // 计算接收地与卫星之间的纬度差和经度差(以弧度为单位)
        double latDiff = satLatRad - recLatRad;
        double lonDiff = satLonRad - recLonRad;

        // 计算仰角(以弧度为单位)
        // 这里使用了一个简化的公式,实际应用中可能需要更复杂的模型
        double elevationRad = Math.asin(Math.sin(latDiff) * Math.cos(satelliteToEarthCenter / earthRadius) +
                Math.cos(recLatRad) * Math.cos(satLatRad) *
                        Math.sin(satelliteToEarthCenter / earthRadius) * Math.cos(lonDiff));

        // 将弧度转换为度数
        double elevationDeg = Math.toDegrees(elevationRad);

//        // 确保仰角在0到90度之间
//        if (elevationDeg < 0) {
//            elevationDeg = 0;
//        } else if (elevationDeg > 90) {
//            elevationDeg = 90;
//        }

        return elevationDeg;
    }

    /**
     * 计算极化角
     *
     * @param azimuth 卫星方位角(度)
     * @param elevation 卫星仰角(度)
     * @return 极化角(度)
     */
    public static double calculatePolarizationAngle(double azimuth, double elevation) {
        // 将角度转换为弧度
        double azimuthRad = Math.toRadians(azimuth);
        double elevationRad = Math.toRadians(elevation);

        // 计算极化角(弧度)
        double polarizationAngleRad = Math.atan2(Math.sin(azimuthRad), Math.tan(elevationRad));

        // 将弧度转换为角度
        double polarizationAngleDeg = Math.toDegrees(polarizationAngleRad);

        // 确保极化角在0到180度之间
//        if (polarizationAngleDeg < 0) {
//            polarizationAngleDeg += 180;
//        } else if (polarizationAngleDeg > 180) {
//            polarizationAngleDeg -= 180;
//        }

        return polarizationAngleDeg;
    }

    /**
     * 将角度转换为弧度
     *
     * @param degrees 角度值
     * @return 弧度值
     */
    public static double toRadians(double degrees) {
        return degrees * Math.PI / 180.0;
    }

    /**
     * 将弧度转换为度数
     *
     * @param radians 弧度值
     * @return 度数值
     */
    public static double toDegrees(double radians) {
        return radians * 180.0 / Math.PI;
    }
相关推荐
我变成萤火虫几秒前
河南萌新联赛2026第(三)场:郑州轻工业大学
数据结构·c++·算法·贪心算法·stl·深度优先·哈希算法
Dr.kangder4 分钟前
嵌入式面试总结(十九)——内存泄露
单片机·算法·面试·职场和发展·架构·硬件架构
Herbert_hwt23 分钟前
【C语言基础】常量、选择结构与运算符全解析
c语言·开发语言·算法
Android-Flutter23 分钟前
android WMS 详解(二)
android·kotlin
Suxing91 小时前
C语言基础分享:从“租房”到“拆迁”,C语言动态内存管理
java·数据结构·算法
游戏开发爱好者81 小时前
App Store 上传 IPA 自动化,.p8 密钥认证与 CI/CD 接入实战
android·运维·ci/cd·小程序·uni-app·自动化·iphone
LuminousCPP1 小时前
单链表专题(四)-刷题复盘篇-LeetCode 138 随机链表复制|原地拷贝法突破复杂指针操作
数据结构·笔记·算法·leetcode·链表
逆境不可逃2 小时前
【LeetCode 912】排序数组——随机化快速排序详解
数据结构·算法·排序算法
Coder-magician2 小时前
《代码随想录》刷题打卡day31:动态规划-背包问题part02
算法·动态规划
薛定e的猫咪2 小时前
从因果视角解决多智能体协作:细读 SCIC 算法
算法