寻找转折点
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