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

#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}

package controller.com.codermart.controller;

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

        /**
 * 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();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < shapeWindowsCordination.length(); i++) {
            char c = shapeWindowsCordination.charAt(i);
            if (Character.isDigit(c)){
                stringBuilder.append(Integer.valueOf(c));
            }else if (",".equals(c)){
                stringBuilder.append(" ");
                continue;
            }
        }
        String s = stringBuilder.toString();
        String[] split = s.split("\\s");
        ArrayList<Integer> integers = new ArrayList<>();
        for (int i = 0; i < split.length; i++) {
            integers.add(Integer.valueOf(split[i]));
        }
        StringBuilder stringBuilder1 = new StringBuilder();
        for (int i = 0; i < shapeWindowsCordination1.length(); i++) {
            char c = shapeWindowsCordination.charAt(i);
            if (Character.isDigit(c)){
                stringBuilder1.append(Integer.valueOf(c));
            }else if (",".equals(c)){
                stringBuilder.append(" ");
                continue;
            }
        }
        String s1 = stringBuilder1.toString();
        String[] split1 = s1.split("\\s");
        ArrayList<Integer> integers1 = new ArrayList<>();
        for (int i = 0; i < split1.length; i++) {
            integers1.add(Integer.valueOf(split1[i]));
        }
        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<Double> 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<Double>() {
            @Override
            public int compare(Double o1, Double o2) {
                if(o1>o2){
                    return -1;
                }else if(o1<o2){
                    return 1;
                }else {
                    return 0;
                }
            }
        });
        Double minDistance = doubles.get(0);
        return minDistance;
    }
}

/**
 * 圆形、矩形、六边形、五边形、跑道形/胶囊形
 */
enum ShapeEnum{
    CIRCLER(1,"圆形",""),
    RECTANGLE(2,"矩形",""),
    SIXEDGESHAQUARE(3,"六边形",""),
    FIVEEDGESHAPE(4,"五边形",""),
    RUNNINGCIRCLE(5,"跑道形","")
    ;

    ShapeEnum(int index, String name, String desc) {
        this.index = index;
        this.name = name;
        this.desc = desc;
    }

    private int index;
    private String name;
    private String desc;

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
class Windows{
    private String id;
    private String windowsCordination; // 所定义的视窗窗口windows的坐标位置 (*,*)

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getWindowsCordination() {
        return windowsCordination;
    }

    public void setWindowsCordination(String windowsCordination) {
        this.windowsCordination = windowsCordination;
    }
}

class Shape{
    private String id;
    private String name; //图形的形状
    private String shapeWindowsCordination; // 图形的形状放在视窗windows中的相对坐标 "(1,3)" , 视窗矩形的坐标

    private String windows_id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getWindows_id() {
        return windows_id;
    }

    public void setWindows_id(String windows_id) {
        this.windows_id = windows_id;
    }

    public String getShapeWindowsCordination() {
        return shapeWindowsCordination;
    }

    public void setShapeWindowsCordination(String shapeWindowsCordination) {
        this.shapeWindowsCordination = shapeWindowsCordination;
    }
}

print('Hello world!')
#我的工作日记##晒一晒你收到的礼盒##牛客创作赏金赛##辞职之后最想做的一件事##Offer比较,求稳定还是求发展#
Java技术 文章被收录于专栏

JavaEE技术 编程开发经验 企业通用技术

全部评论

相关推荐

来,说点可能被同行“骂”的大实话。🙊当初接数字马力Offer时,朋友都说:“蚂蚁的“内包”公司?你想清楚啊!”但入职快一年后的今天,我反而对他有了不一样的看法!🔹&nbsp;是偏见?还是信息差!之前没入职之前外面都在说什么岗位低人一等这类。实际上:这种情况不可至否,不能保证每个团队都是其乐融融。但我在的部门以及我了解的周边同事都还是十分好相处的~和蚂蚁师兄师姐之间也经常开一些小玩笑。总之:身份是蚂蚁公司给的,地位是自己挣的(一个傲娇女孩的自述)。🔹&nbsp;待遇?玩的就是真实!试用期工资全额发!六点下班跑得快(早9晚6或者早10晚7,动态打卡),公积金顶格交。别听那些画饼的,到手的钱和下班的时间才是真的(都是牛马何必难为牛马)。🔹&nbsp;能不能学到技术?来了就“后悔”!我们拥有权限直通蚂蚁知识库,技术栈多到学不完。说“学不到东西”的人,来了可能后悔——后悔来晚了(哈哈哈哈,可以不学但是不能没有)!💥&nbsp;内推地址:https://app.mokahr.com/su/ueoyhg❗我的内推码:NTA6Nvs走我的内推,可以直达业务部门,面试流程更快速,进度可查!今天新放HC,之前挂过也能再战!秋招已经正式开始啦~机会就摆在这,敢不敢来试一试呢?(和我一样,做个勇敢的女孩)
注意格局:去年超发意向是忘了
帮你内推|数字马力 校招
点赞 评论 收藏
分享
09-13 17:25
亲切的00后在笔试:我也遇到了,所以我早他一步查看图片
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务