@@ -18,7 +18,6 @@ public static void main(String[] args) {
1818 double [] planeIndexes = calcThePlane (pointArr );
1919 Point pointD = new Point (1 , -5 , 1 );
2020 Point pointE = new Point (2 , -5 , 1 );
21- // Point pointE = new Point(-6.29,1.07,-3.2);
2221
2322 int sideDecision = areTwoPointsSameSide (pointD , pointE , planeIndexes );
2423 if (sideDecision == -1 )
@@ -27,7 +26,6 @@ else if (sideDecision == 1)
2726 System .out .println ("Są po tej samej stronie" );
2827 else
2928 System .out .println ("Jeden z punktów leży na płaszczyźnie" );
30-
3129 }
3230
3331 public static double [] calcThePlane (List <Point > points ) {
@@ -51,7 +49,7 @@ public static int areTwoPointsSameSide(Point firstPoint, Point secPoint, double[
5149 double firstValue = firstPoint .x * planeIndexes [0 ] + firstPoint .y * planeIndexes [1 ] + firstPoint .z * planeIndexes [2 ] + planeIndexes [3 ];
5250 double secValue = secPoint .x * planeIndexes [0 ] + secPoint .y * planeIndexes [1 ] + secPoint .z * planeIndexes [2 ] + planeIndexes [3 ];
5351
54- if (java . lang . Math .abs (firstValue ) < 10 || java . lang . Math .abs (secValue ) < 10 ) {
52+ if (Math .abs (firstValue ) < 10 || Math .abs (secValue ) < 10 ) {
5553 return 0 ;
5654 }
5755 if (firstValue * secValue > 0 ) {
@@ -71,13 +69,13 @@ public static int areFaceAndPointSameSide(Face face, Point point, double[] plane
7169 long zeroCount = Arrays .stream (sameSides ).filter (i -> i == 0 ).count ();
7270
7371 if (zeroCount == 4 ) {
74- return 0 ; // w plaszczyznie
72+ return 0 ;
7573 } else if (sameCount == 4 || (zeroCount > 0 && sameCount > oppositeCount )) {
7674 return 1 ;
7775 } else if (oppositeCount == 4 || (zeroCount > 0 && oppositeCount > sameCount )) {
7876 return -1 ;
7977 } else {
80- return -10 ; // do podzialu
78+ return -10 ;
8179 }
8280 }
8381
@@ -86,12 +84,16 @@ public static Face[] divideFace(Point[] oneSidePoints, Point[] secSidePoints, do
8684 Point firstPoint = findPoint (orderedPoints [0 ], orderedPoints [1 ], planeIndexes );
8785 Point secPoint = findPoint (orderedPoints [2 ], orderedPoints [3 ], planeIndexes );
8886
89- System .out .println ("Pierwsza ściana: " + oneSidePoints [0 ] + " " + oneSidePoints [1 ] + " " + secPoint + " " + firstPoint );
90- System .out .println ("Druga ściana: " + secSidePoints [0 ] + " " + secSidePoints [1 ] + " " + secPoint + " " + firstPoint );
91- System .out .println ();
87+ Face firstFace = new Face (oneSidePoints [0 ], oneSidePoints [1 ], firstPoint , secPoint );
88+ Face secFace = new Face (secSidePoints [0 ], secSidePoints [1 ], firstPoint , secPoint );
89+
90+ if (pointsDistance (oneSidePoints [1 ], secPoint ) < pointsDistance (oneSidePoints [1 ], firstPoint )) {
91+ firstFace = new Face (oneSidePoints [0 ], oneSidePoints [1 ], secPoint , firstPoint );
92+ }
93+ if (pointsDistance (secSidePoints [1 ], secPoint ) < pointsDistance (secSidePoints [1 ], firstPoint )) {
94+ secFace = new Face (secSidePoints [0 ], secSidePoints [1 ], secPoint , firstPoint );
95+ }
9296
93- Face firstFace = new Face (oneSidePoints [0 ], oneSidePoints [1 ], secPoint , firstPoint );
94- Face secFace = new Face (secSidePoints [0 ], secSidePoints [1 ], secPoint , firstPoint );
9597 return new Face []{firstFace , secFace };
9698 }
9799
@@ -107,8 +109,8 @@ private static Point findPoint(Point firstPoint, Point secPoint, double[] planeI
107109 private static Point [] determinePointPairs (Point [] oneSidePoints , Point [] secSidePoints ) {
108110 double [] firstVector = calculateVector (oneSidePoints [0 ], secSidePoints [0 ]);
109111 double [] secVector = calculateVector (oneSidePoints [0 ], secSidePoints [1 ]);
110- double firstVectorLength = java . lang . Math .sqrt (firstVector [0 ] * firstVector [0 ] + firstVector [1 ] * firstVector [1 ] + firstVector [2 ] * firstVector [2 ]);
111- double secVectorLength = java . lang . Math .sqrt (secVector [0 ] * secVector [0 ] + secVector [1 ] * secVector [1 ] + secVector [2 ] * secVector [2 ]);
112+ double firstVectorLength = Math .sqrt (firstVector [0 ] * firstVector [0 ] + firstVector [1 ] * firstVector [1 ] + firstVector [2 ] * firstVector [2 ]);
113+ double secVectorLength = Math .sqrt (secVector [0 ] * secVector [0 ] + secVector [1 ] * secVector [1 ] + secVector [2 ] * secVector [2 ]);
112114
113115 if (firstVectorLength < secVectorLength ) {
114116 return new Point []{oneSidePoints [0 ], secSidePoints [0 ], oneSidePoints [1 ], secSidePoints [1 ]};
@@ -119,4 +121,9 @@ private static Point[] determinePointPairs(Point[] oneSidePoints, Point[] secSid
119121 private static double [] calculateVector (Point firstPoint , Point secPoint ) {
120122 return new double []{firstPoint .x - secPoint .x , firstPoint .y - secPoint .y , firstPoint .z - secPoint .z };
121123 }
124+
125+ private static double pointsDistance (Point a , Point b ) {
126+ double [] vector = calculateVector (a , b );
127+ return Math .sqrt (Arrays .stream (vector ).map (v -> v * v ).sum ());
128+ }
122129}
0 commit comments