Browse Source

修改bug

16s01 4 years ago
parent
commit
8df347fb23
5 changed files with 186 additions and 49 deletions
  1. 35 10
      src/test/Cal.java
  2. 1 1
      src/test/GetPoints.java
  3. 121 30
      src/test/Split.java
  4. 15 7
      src/test/Tool.java
  5. 14 1
      src/test/entity/WholeIndexOccupy.java

+ 35 - 10
src/test/Cal.java

@@ -18,6 +18,9 @@ public class Cal {
         getPoints.getPoints();
 
         ArrayList<Point> realShapePoints = getPoints.realShapePoints;//实际形状的平面坐标
+
+
+
 //        GetPoints getPoints = new GetPoints();//所有待计算点
         ArrayList<Point> allPoints = getPoints.allPoints;//所有待计算点,铲车作业平面坐标
         Split split = new Split();
@@ -30,9 +33,9 @@ public class Cal {
         Double yGap = split.yGap;//纵向上采用的间隔
 
         Double minX = xIndexCorList.get(0);
-        Double maxX = xIndexCorList.get(xIndexCorList.size());
+        Double maxX = xIndexCorList.get(xIndexCorList.size() - 1);
         Double minY = yIndexCorList.get(0);
-        Double maxY = yIndexCorList.get(yIndexCorList.size());
+        Double maxY = yIndexCorList.get(yIndexCorList.size() - 1);
 
 
         ArrayList<Point> pointAfterExclude = new ArrayList<>();//过滤后的所有点的坐标
@@ -56,11 +59,6 @@ public class Cal {
         //占用的网格为1,不占用的网格0
         ArrayList<ArrayList<Integer>> occupyList = changeWholeIndexOccupyToList(wholeIndexOccupy);
 
-//        for (int i = 0 ; i < occupyList.size();i++){
-//
-//
-//
-//        }
 
 
         for (int i = 0; i < pointAfterExclude.size();i++){
@@ -70,12 +68,25 @@ public class Cal {
             Double y = point.getColY();
             Integer xIndex = split.identifyXIndex(x);
             Integer yIndex = split.identifyYIndex(y);
-            ArrayList<Integer> arrayList = occupyList.get(xIndex);
-            arrayList.set(yIndex,0);
-            occupyList.set(xIndex,arrayList);
+
+            if (yIndex < 100 && yIndex >=0){
+
+                ArrayList<Integer> arrayList = occupyList.get(xIndex);
+                arrayList.set(yIndex,0);
+                occupyList.set(xIndex,arrayList);
+
+
+            }
+
+
 
         }
 
+
+
+
+
+
         for (int i = 0 ; i < occupyList.size();i++){
 
             ArrayList<Integer> arrayList = occupyList.get(i);
@@ -133,6 +144,13 @@ public class Cal {
             shape.add(point);
         }
 
+
+        for (int i = 0 ; i < shape.size() ; i++){
+
+            System.out.println(shape.get(i).getColX());
+            System.out.println(shape.get(i).getColY());
+
+        }
         return shape;
 
 
@@ -145,6 +163,9 @@ public class Cal {
 
 
 
+
+
+
     }
 
 
@@ -153,6 +174,8 @@ public class Cal {
 
         ArrayList<OccupyPerX> occupyPerXArrayList = wholeIndexOccupy.getOccupyPerXArrayList();
 
+        System.out.println(occupyPerXArrayList);
+
         Integer numOfGaps = occupyPerXArrayList.size();
 
         ArrayList<ArrayList<Integer>> occupyList = new ArrayList<>();
@@ -179,6 +202,8 @@ public class Cal {
 
             ArrayList<Integer> arrayList = occupyList.get(i);
 
+//            if ()
+
             for (int j = minYIndex ; j < (maxYIndex + 1); j++){
 
                 arrayList.set(j,1);

+ 1 - 1
src/test/GetPoints.java

@@ -35,7 +35,7 @@ public class GetPoints {
 
 
         String realShapeBeginTime = "2020-07-09 15:06:00.000000";
-        String realShapeEndTime = "2020-07-09 11:13:09.000000";
+        String realShapeEndTime = "2020-07-09 15:07:00.000000";
 
         String allPointsBeginTime = "2020-07-12 06:36:00.000000";
         String allPointsEndTime = "2020-07-12 06:40:00.000000";

+ 121 - 30
src/test/Split.java

@@ -26,13 +26,17 @@ public class Split {
     //输入垛位的初始实际形状,形成网格
     public void cal(ArrayList<Point> pointsList){
 
-        double minX = 0.;
+        pointsList.add(pointsList.get(0));
 
-        double minY = 0.;
+        Point point0 = pointsList.get(0);
 
-        double maxX = 0.;
+        double minX = point0.getColX();
 
-        double maxY = 0.;
+        double minY = point0.getColY();
+
+        double maxX = point0.getColX();
+
+        double maxY = point0.getColY();
 
         for (int i = 0 ; i < pointsList.size();i++){
 
@@ -74,11 +78,16 @@ public class Split {
         Point pointC = new Point();
         Point pointD = new Point();
 
+        System.out.println("maxX " + maxX);
+        System.out.println("minX " + minX);
+        System.out.println("maxY " + maxY);
+        System.out.println("minY " + minY);
+
         pointA.setColX(minX);
         pointA.setColY(minY);
 
         pointB.setColX(minX);
-        pointB.setColX(maxY);
+        pointB.setColY(maxY);
 
         pointC.setColX(maxX);
         pointC.setColY(maxY);
@@ -96,9 +105,12 @@ public class Split {
         decideIndex(rectanglePoints);
         getLines(pointsList);
 
+//        System.out.println(wholeIndexOccupy.getOccupyPerXArrayList());
+
 
     }
 
+    //横向纵向划分网格
     public void decideIndex(ArrayList<Point> fourPointsList){
 
         Point pointA = fourPointsList.get(0);
@@ -128,6 +140,11 @@ public class Split {
             minY = minY + yGap;
         }
 
+//        System.out.println(xIndexCorList);
+//
+//        System.out.println(" ");
+//        System.out.println(yIndexCorList);
+
     }
 
     public double  calculateDistance(Point point1,Point point2){
@@ -149,6 +166,7 @@ public class Split {
 
         for (int i = 0 ; i< pointsList.size() - 1;i++){
 
+            //两个点形成直线
             Point pointI = pointsList.get(i);
             Point pointJ = pointsList.get(i + 1);
 
@@ -164,9 +182,9 @@ public class Split {
 //            Double pointJx = pointJ.getColX();
 //            Double pointJy = pointJ.getColY();
 
-//            //该直线起始点的网格位置
-//            Index indexI = identifyIndex(pointI);
-//            Index indexJ = identifyIndex(pointJ);
+            //该直线起始点的网格位置
+            Index indexI = identifyIndex(pointI);
+            Index indexJ = identifyIndex(pointJ);
             lineOccupy(pointI,pointJ,lineParamList);
 
 
@@ -190,57 +208,107 @@ public class Split {
 
         //
         Integer xIndexBegin = indexI.getxIndex();//网格横向起始编号
-        Integer yIndexBegin = indexI.getxIndex();//网格纵向起始编号
+        Integer yIndexBegin = indexI.getyIndex();//网格纵向起始编号
 
         Integer xIndexEnd = indexJ.getxIndex();//网格横向终止编号
-        Integer yIndexEnd = indexJ.getxIndex();//网格纵向终止编号
+        Integer yIndexEnd = indexJ.getyIndex();//网格纵向终止编号
 
+        Integer lineYIndexMax = Math.max(yIndexBegin,yIndexEnd);
+        Integer lineYIndexMin = Math.min(yIndexBegin,yIndexEnd);
 
 
+
+
+        //对该格点跨越的所有横向网格序号作循环
         for (int i = xIndexBegin;i < xIndexEnd + 1; i++){
 
+            //计算该直线(线段)在当前横向的网格内,在纵向的占据情况
+
             Integer minYIndex;
             Integer maxYIndex;
 
-            Double xInputBegin;
-            Double xInputEnd;
+            Double xInputBegin;//网格的起始的横坐标
+            Double xInputEnd;//
+
+            Double yOutBegin;//
+            Double yOutEnd;//
+
+
+
 
-            Double yOutBegin;
-            Double yOutEnd;
 
 
             xInputBegin = xMin + xGap * i;//当前网格的起始横坐标
             xInputEnd = xInputBegin + xGap;//当前网格的终止横坐标
+            OccupyPerX occupyPerX =  new OccupyPerX();
+
+//            if ((Double.POSITIVE_INFINITY == lineParamList.get(0) || Double.NEGATIVE_INFINITY == lineParamList.get(0))){
+//
+//                System.out.println(111111);
+//            }
+            if ((lineParamList.size()!=0) && !(Double.POSITIVE_INFINITY == lineParamList.get(0) || Double.NEGATIVE_INFINITY == lineParamList.get(0))){
+
+                yOutBegin = tool.getLineYValue(xInputBegin,lineParamList);//当前网格的起始纵坐标
+//                if (yOutBegin > lineYIndexMax){
+//
+//                    yOutBegin = lineYIndexMax;
+//                }
 
+                yOutEnd = tool.getLineYValue(xInputEnd,lineParamList);//当前网格的终止纵坐标
+//                System.out.println(lineParamList);
+//                System.out.println("begin x: " + xInputBegin + " y: " + yOutBegin);
+//                System.out.println("end x: " + xInputEnd + " y: " + yOutEnd);
 
-            yOutBegin = tool.getLineYValue(xInputBegin,lineParamList);//当前网格的起始纵坐标
-            yOutEnd = tool.getLineYValue(xInputEnd,lineParamList);//当前网格的终止纵坐标
+                Integer yBeginIndex = identifyYIndex(yOutBegin);
+                Integer yEndIndex = identifyYIndex(yOutEnd);
 
-//            Double yBeginIndexTemp = (yOutBegin - yMin)/yGap;
-//            Integer yBeginIndex = yBeginIndexTemp.intValue();
+//                if (yBeginIndex > lineYIndexMax){
+//
+//                    yBeginIndex = lineYIndexMax;
+//
+//                }
+//
+//                if (yBeginIndex < lineYIndexMin){
+//
+//                    yBeginIndex = ;
+//
+//                }
 
+                yBeginIndex = Math.min(yBeginIndex,lineYIndexMax);
+                yBeginIndex = Math.max(yBeginIndex,lineYIndexMin);
+                yEndIndex = Math.min(yEndIndex,lineYIndexMax);
+                yEndIndex = Math.max(yEndIndex,lineYIndexMin);
 
-            Integer yBeginIndex = identifyYIndex(yOutBegin);
-            Integer yEndIndex = identifyYIndex(yOutEnd);
-            Integer yIndexMax;
-            Integer yIndexMin;
 
+                Integer yIndexMax;
+                Integer yIndexMin;
 
-            if (yBeginIndex > yEndIndex){
+                if (yBeginIndex > yEndIndex){
 
-                yIndexMin = yEndIndex;
-                yIndexMax = yBeginIndex;
+                    yIndexMin = yEndIndex;
+                    yIndexMax = yBeginIndex;
+
+                }
+                else {
+
+                    yIndexMax = yEndIndex;
+                    yIndexMin = yBeginIndex;
+
+                }
+
+                occupyPerX.setMaxYIndex(yIndexMax);
+                occupyPerX.setMinYIndex(yIndexMin);
 
             }
+
             else {
 
-                yIndexMax = yEndIndex;
-                yIndexMin = yBeginIndex;
+                occupyPerX.setMaxYIndex(Math.max(yIndexBegin,yIndexEnd));
+                occupyPerX.setMinYIndex(Math.min(yIndexBegin,yIndexEnd));
 
             }
-            OccupyPerX occupyPerX =  new OccupyPerX();
-            occupyPerX.setMaxYIndex(yIndexMax);
-            occupyPerX.setMinYIndex(yIndexMin);
+
+
             wholeIndexOccupy.setOccupyPerXArrayList(occupyPerX,i);
         }
     }
@@ -266,10 +334,33 @@ public class Split {
         Double xIndexTemp = (pointX - minX) / xGap;
         Double yIndexTemp = (pointY - minY) / yGap;
 
+
+
         Integer xIndex = xIndexTemp.intValue();
         Integer yIndex = yIndexTemp.intValue();
 
+        if (xIndex == 100){
+
+            System.out.println(1111111 + "  " + pointX + " " + xIndexTemp);
+
+        }
+
         Index index = new Index();
+
+        if (xIndex == 100){
+
+            xIndex = xIndex -1;
+
+        }
+
+        if (yIndex == 100){
+
+            yIndex = yIndex -1;
+
+        }
+
+
+
         index.setxIndex(xIndex);
         index.setyIndex(yIndex);
 

+ 15 - 7
src/test/Tool.java

@@ -15,15 +15,23 @@ public class Tool {
         Double y2 = point2.getColY();
 
 
-        Double lineA = (y1 - y2) / (x1 - x2);
-        Double lineB = -1.0;
-        Double lineC = y1 - lineA * x2;
-
+        //////////
+        Double lineA;
+        Double lineB;
+        Double lineC;
         ArrayList<Double> lineParamList = new ArrayList<>();
 
-        lineParamList.add(lineA);
-        lineParamList.add(lineB);
-        lineParamList.add(lineC);
+        /////////
+
+        if (! x1.equals(x2)){
+
+            lineA = (y1 - y2) / (x1 - x2);
+            lineB = -1.0;
+            lineC = y1 - lineA * x2;
+            lineParamList.add(lineA);
+            lineParamList.add(lineB);
+            lineParamList.add(lineC);
+        }
 
         return  lineParamList;
     }

+ 14 - 1
src/test/entity/WholeIndexOccupy.java

@@ -11,7 +11,7 @@ public class WholeIndexOccupy {
         for (int i = 0;i < numberOfGaps;i++){
 
             OccupyPerX occupyPerX = new OccupyPerX();
-            occupyPerX.setMinYIndex(-2);
+            occupyPerX.setMinYIndex(1000);
             occupyPerX.setMaxYIndex(-1);
             occupyPerXArrayList.add(occupyPerX);
 
@@ -70,4 +70,17 @@ public class WholeIndexOccupy {
     }
 
 
+//    public void cleanDirtyData(){
+//
+//        for (int i = 0; i < occupyPerXArrayList.size();i++){
+//
+//
+//            Integer temp = occupyPerXArrayList.get(i);
+//            if ()
+//
+//        }
+
+//    }
+
+
 }