已知A,B点,以及平移距离,求AB向量垂直方向的一组航线

public static ArrayList<LatLong> initAbData(double A_lat, double A_lng, double B_lat, double B_lng, double distance, int abpoint_direction) {
        int abpoint_count = 1;
        double yA = MercatorProjection.latitudeToY(A_lat);
        double xA = MercatorProjection.longitudeToX(A_lng);

        double yB = MercatorProjection.latitudeToY(B_lat);
        double xB = MercatorProjection.longitudeToX(B_lng);
        ArrayList<LatLong> latLongs = new ArrayList<>();
        LatLong latLong = new LatLong(A_lat, A_lng);
        LatLong latLong2 = new LatLong(B_lat, B_lng);
        latLongs.add(latLong);
        latLongs.add(latLong2);
        double abpoint_distance = MercatorProjection.getMercatorDistance(latLongs, distance);
        arrayList.clear();
        Vector2D abpoint_vector_ab = new Vector2D(xB - xA, yB - yA);
        Point abpoint_B = new Point(xB, yB);
        Vector2D abpoint_vector_bc_unit = getAbpoint_vector_bc_unit(abpoint_vector_ab);
        Vector2D vector2D = abpoint_vector_bc_unit.multiply(abpoint_direction).multiply(abpoint_distance);
        do {
            getDestinalXY(abpoint_B, abpoint_vector_ab, vector2D, abpoint_count);
            abpoint_count++;
        } while (abpoint_count <= 58);
        latLongs.clear();
        latLongs.add(latLong);
        latLongs.add(latLong2);
        for (Point vector2D1 : arrayList) {
            double longitude = MercatorProjection.xToLongitude(vector2D1.x);
            double latitude = MercatorProjection.yToLatitude(vector2D1.y);
            LatLong latLongAB = new LatLong(latitude, longitude);
            latLongs.add(latLongAB);
//            System.out.println(latitude+"xxx"+longitude);
        }
        return latLongs;
    }

    private static ArrayList<Point> arrayList = new ArrayList<>();
//    private static ArrayList<LatLong> latLongs = new ArrayList<>();
//获取AB方向的一组航线
    private static void getDestinalXY(Point abpoint_B, Vector2D abpoint_vector_ab, Vector2D vector2D, int abpoint_count) {
        if (abpoint_count % 2 != 0) {
            abpoint_B.x += vector2D.x;
            abpoint_B.y += vector2D.y;
            Point pointResult = new Point(abpoint_B.x, abpoint_B.y);
            arrayList.add(pointResult);
        } else {
            double pow = Math.pow(-1, abpoint_count >> 1);
            Vector2D multiply = abpoint_vector_ab.multiply(pow);
            abpoint_B.x += multiply.x;
            abpoint_B.y += multiply.y;
            Point pointResult = new Point(abpoint_B.x, abpoint_B.y);
            arrayList.add(pointResult);
        }
    }
//获取AB垂直方向的单位向量
    private static Vector2D getAbpoint_vector_bc_unit(Vector2D abpoint_vector_ab) {
        // caculate bc vector
        Vector2D ab_vector_vertical = new Vector2D(1.0f, -abpoint_vector_ab.x / abpoint_vector_ab.y);
        Vector2D ab_vector_vertical_unit = ab_vector_vertical.normalize();

        double result = ab_vector_vertical_unit.dotProduct(abpoint_vector_ab);
        if (result != 0) {
            ab_vector_vertical = new Vector2D(-abpoint_vector_ab.y / abpoint_vector_ab.x, 1.0f);
            ab_vector_vertical_unit = ab_vector_vertical.normalize();
        }
        Vector2D abpoint_vector_bc_unit;
        if ((abpoint_vector_ab.x * ab_vector_vertical_unit.y - abpoint_vector_ab.y * ab_vector_vertical_unit.x) > 0) {
            abpoint_vector_bc_unit = ab_vector_vertical_unit;
        } else {
            abpoint_vector_bc_unit = ab_vector_vertical_unit.reverse();
        }
        return abpoint_vector_bc_unit;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值