使用Python计算平面多边形间最短距离,数据需要从excel表格中导入

 使用Python计算平面多边形间最短距离,数据需要从excel表格中导入,
* 多边形种类包括(圆形、矩形、六边形、五边形、跑道形/胶囊形),
* Python代码需要使用gjk算法进行判断两个多边形间是否重叠,
* 如果未重叠计算最短距离

package controller.com.codermart.controller;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Random;

/**
 * Created by Lenovo on 2023/10/16.
 */
public class PythonAlgorithm {

    public static void main(String[] args) {
        int testVar=1;
        switch (testVar){
            case 1:
                break;
            case 2:
                break;
        }
    }

    /**
     * 使用Python计算平面多边形间最短距离,数据需要从excel表格中导入,
     * 多边形种类包括(圆形、矩形、六边形、五边形、跑道形/胶囊形),
     * Python代码需要使用gjk算法进行判断两个多边形间是否重叠,
     * 如果未重叠计算最短距离
     * @param shapeFir
     * @param shapeSec
     * @return
     */
    public static Double getShapeDistance(Shape shapeFir,Shape shapeSec){
        if (shapeFir==null){
            return null;
        }
        if (shapeFir.getShapeWindowsCordination()==null){
            return null;
        }
        if (shapeFir.getShapeWindowsCordination().isEmpty()){
            return null;
        }
        if (shapeSec==null){
            return null;
        }
        if (shapeSec.getShapeWindowsCordination()==null){
            return null;
        }
        if (shapeSec.getShapeWindowsCordination().isEmpty()){
            return null;
        }

//        String name = ShapeEnum.CIRCLER.getName();
        String shapeWindowsCordination = shapeFir.getShapeWindowsCordination();
        String shapeWindowsCordination1 = shapeSec.getShapeWindowsCordination();

        ArrayList integers = new ArrayList<>();
        for (int i = 0; i < shapeWindowsCordination.length(); i++) {
            char c = shapeWindowsCordination.charAt(i);
            if (Character.isDigit(c)){
                integers.add(Integer.valueOf(c));
            }
        }

        int length = shapeWindowsCordination1.length();
        ArrayList integers1 = new ArrayList<>();
        for (int i = 0; i < length; i++) {
            char c = shapeWindowsCordination1.charAt(i);
            integers1.add(Integer.valueOf(c));
        }

        Integer integer = integers.get(0);
        Integer integer1 = integers1.get(1);
        int i = integer * integer1;
        Integer integer2 = integers.get(0);
        Integer integer3 = integers1.get(1);
        int i1 = integer2 * integer3;
        int i2=0;
        if (i>i1){
            i2 = i - i1;
        }else {
            i2 = i1 - i;
        }
        double sqrtDistance = Math.sqrt(i2);

        return sqrtDistance;
    }

    public static Double getShortestDistance(Shape shapeFir, Shape shapeSec){
        if (shapeFir==null){
            return null;
        }
        if (shapeFir.getShapeWindowsCordination()==null){
            return null;
        }
        if (shapeFir.getShapeWindowsCordination().isEmpty()){
            return null;
        }
        if (shapeSec==null){
            return null;
        }
        if (shapeSec.getShapeWindowsCordination()==null){
            return null;
        }
        if (shapeSec.getShapeWindowsCordination().isEmpty()){
            return null;
        }

        //Random random = new Random(); //获取图形中的随机点
        ArrayList doubles = new ArrayList<>();
        int count=0;
        while (true){
            Double shapeDistance = getShapeDistance(shapeFir, shapeSec); // 计算随机点的两个坐标之间的距离
            doubles.add(shapeDistance);
            if (count>1000000){
                break;
            }
            count++;
        }

        doubles.sort(new Comparator() {
            @Override
            public int compare(Double o1, Double o2) {
                if(o1>o2){
                    return -1;
                }else if(o1

 

你可能感兴趣的:(Java,算法,源码,分析,开发语言,算法,java,后端)