首页 > 其他分享 >寻找转折点

寻找转折点

时间:2023-08-02 19:22:04浏览次数:32  
标签:List list1 寻找 转折点 add new RoutePoint 90

寻找转折点

package com.vfsd.test;

import java.util.ArrayList;
import java.util.List;

import com.vfsd.core.RoutePoint;

public class FindCornerPoint {
    
    public static void main(String[] args) {
        List<RoutePoint> list1 = new ArrayList<RoutePoint>();
        
        RoutePoint point1 = new RoutePoint(1,1,1,90);
        RoutePoint point2 = new RoutePoint(2,1,2,90);
        RoutePoint point3 = new RoutePoint(3,1,3,90);
        RoutePoint point4 = new RoutePoint(4,1,4,90);
        
        RoutePoint point5 = new RoutePoint(5,2,4,90);
        RoutePoint point6 = new RoutePoint(6,2,5,90);
        RoutePoint point7 = new RoutePoint(7,2,6,90);
        RoutePoint point8 = new RoutePoint(8,2,7,90);
        
        
        RoutePoint point9 = new RoutePoint(9,3,7,90);
        RoutePoint point10 = new RoutePoint(10,3,8,90);
        RoutePoint point11 = new RoutePoint(11,3,9,90);
        RoutePoint point12 = new RoutePoint(12,4,9,90);
        
        RoutePoint point13 = new RoutePoint(13,5,9,90);
        RoutePoint point14 = new RoutePoint(14,5,10,90);
        RoutePoint point15 = new RoutePoint(15,5,11,90);
        RoutePoint point16 = new RoutePoint(16,6,11,90);
        
        RoutePoint point17 = new RoutePoint(17,7,11,90);
        RoutePoint point18 = new RoutePoint(18,7,12,90);
        RoutePoint point19 = new RoutePoint(19,8,12,90);
        RoutePoint point20 = new RoutePoint(20,9,12,90);
        
        RoutePoint point21 = new RoutePoint(21,9,13,90);
        RoutePoint point22 = new RoutePoint(22,9,14,90);
        RoutePoint point23 = new RoutePoint(23,9,15,90);
        RoutePoint point24 = new RoutePoint(24,10,15,90);
        
        
        
        
        list1.add(point1);
        list1.add(point2);
        list1.add(point3);
        list1.add(point4);
        
        list1.add(point5);
        list1.add(point6);
        list1.add(point7);
        list1.add(point8);
        
        
        list1.add(point9);
        list1.add(point10);
        list1.add(point11);
        list1.add(point12);
        
        list1.add(point13);
        list1.add(point14);
        list1.add(point15);
        list1.add(point16);
        
        
        list1.add(point17);
        list1.add(point18);
        list1.add(point19);
        list1.add(point20);
        
        list1.add(point21);
        list1.add(point22);
        list1.add(point23);
        list1.add(point24);
        
        
        List<Integer> listPointID = searchCornerPointID2(list1);
        
        System.out.println(listPointID);
        
    }
    /**
     * 寻找拐点
     * @param list1
     * @return
     */
    public static List<Integer> searchCornerPointID2(List<RoutePoint> list1){
        List<Integer> listPointID = new ArrayList<>();
        
        //       1
        //  4    c    2
        //       3
        //
        int lastDirect=1;
        boolean startC = true;
        int loopCount=0;
        for(int k=1;k<list1.size();k++) {
            RoutePoint lastPoint = list1.get(k-1);
            RoutePoint indexPoint = list1.get(k);
            
            double lastPointX=lastPoint.getX();
            double lastPointY=lastPoint.getY();
            
            double indexPointX=indexPoint.getX();
            double indexPointY=indexPoint.getY();
            
            int indexDirect=-1;
            if(lastPointX==indexPointX && lastPointY>=indexPointY) {
                indexDirect =1;
            }else if(lastPointX==indexPointX && lastPointY<indexPointY) {
                indexDirect =3;
            }else if(lastPointX>=indexPointX && lastPointY==indexPointY) {
                indexDirect =4;
            }else if(lastPointX<indexPointX && lastPointY==indexPointY) {
                indexDirect =2;
            }
            
            System.out.println(k+"  "+lastDirect+"    "+indexDirect);
            
            if(k!=1) {
                if(startC) {
                    //拐点 
                    if(lastDirect != indexDirect) {
                        listPointID.add(k);
                        startC  = false;
                    }
                }else {
                    //if(loopCount>0) {
                        startC=true;
                        loopCount=0;
                    //}
                    //loopCount++;
                }
                
                
            }
            
            lastDirect = indexDirect;
            
        }
        
        return listPointID;
    }
    
    
    
}

 

 

 

##################

标签:List,list1,寻找,转折点,add,new,RoutePoint,90
From: https://www.cnblogs.com/herd/p/17601558.html

相关文章

  • 【题解】Luogu[P2296] [NOIP2014 提高组] 寻找道路
    Link很简单的一道图论题。要在一个有向图上找一条\(s\)到\(t\)的最短路,要求这条路径上的所有点都满足:该点的所有出边所连点都能到达终点\(t\)。看上去很乱,我们简单分解一下,先在所有点中找到与终点有路径的点集\(A\)进行标记,再再所有点中找到其所有出边所连点都被打上标......
  • 算法 | 就地逆置、双指针快速寻找中间节点
    2019年真题设线性表L=(a1,a2,a3,...,an-2,an-1,an)采用带头节点的单链表保存,链表中的结点定义如下:(代码1)设计一个空间复杂度为O(1)且时间上尽可能高效的算法,重新排列L中的各结,得到线性表L’=(a1,an,a2,an-1,a3,an-2,...)。//代码1//langCtypedefstr......
  • 五分钟教你使用GitHub寻找优质项目
    https://www.cnblogs.com/Can-daydayup/p/17581307.html 思维导航前言首先解决访问慢的问题GitHub热门栏目GitHub上直接搜项目GitHub搜索小技巧前言经常会有同学会问如何使用GitHub找到自己想要的项目,今天咱们就出一期快速入门教程五分钟教你使用GitHub寻找优质项......
  • SpringBoot 启动流程分析(寻找扩展点)
    1、SpringBootmaven依赖版本<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation=......
  • LC 4、寻找两个正序数组的中位数
    LC4、寻找两个正序数组的中位数题目描述这是LeetCode4、寻找两个正序数组的中位数,难度为困难给定两个大小分别为m和n的正序(从小到大)数组nums1和nums2。请你找出并返回这两个正序数组的「中位数」。示例:输入:nums1=[1,3],nums2=[2]输出:2.00000解释:合并数......
  • rola-ip关停给企业带来哪些损失?急需寻找替代代理商解困
    rola-ip的网站已经连续几天都无法打开了,服务商已经跑路的消息传得沸沸扬扬,这给很多正在使用代理服务进行业务的用户带来很大的困扰。毫无预兆地突然消失,让许多企业急需寻找到可以接替它继续服务的代理商。rola-ip突然跑路,可能会给企业带来许多不便,如公司业务中断、数据连接变慢、信......
  • 寻找数组中重复的数字
    寻找数组中重复的数字​ 给定一个包含n+1个整数的数组nums,其数字都在[1,n]范围内(包括1和n),可知至少存在一个重复的整数。假设nums只有一个重复的整数,返回这个重复的数。1<=n<=\(10^5\)nums.length==n+11<=nums[i]<=nnums中只有一个整数出......
  • 寻找解析注解的类
    1、直接搜索"注解名.class"以若依项目为例,我要寻找如下注解的解析情况/***自定义注解防止表单重复提交**@authorruoyi**/@Target(ElementType.METHOD)@Retention(RetentionPolicy.RUNTIME)@Documentedpublic@interfaceRepeatSubmit{/***间隔......
  • 五分钟教你使用GitHub寻找优质项目
    前言经常会有同学会问如何使用GitHub找到自己想要的项目,今天咱们就出一期快速入门教程五分钟教你使用GitHub寻找优质项目。GitHub作为世界上最大的项目开源平台之一,上面有着无数优质的开源项目。善于使用它能够让你获得很多意想不到的惊喜。首先解决访问慢的问题FastGithub是Gi......
  • 寻找矩阵的极小值
    title:寻找矩阵的极小值date:2023-07-2420:44:49tags:-c/c++categories:-算法-笔试top:寻找矩阵的极小值题目来自acwing题目(点击跳转)给定一个n×n的矩阵,矩阵中包含n×n个互不相同的整数。定义极小值:如果一个数的值比与它相邻的所有数字的值都小,则这个数值......