Package com.sun.j3d.utils.geometry

Source Code of com.sun.j3d.utils.geometry.Numerics

/*     */ package com.sun.j3d.utils.geometry;
/*     */
/*     */ import javax.vecmath.Point2f;
/*     */ import javax.vecmath.Tuple2f;
/*     */
/*     */ class Numerics
/*     */ {
/*     */   static double max3(double a, double b, double c)
/*     */   {
/*  24 */     return b > c ? b : a > b ? c : a > c ? a : c;
/*     */   }
/*     */
/*     */   static double min3(double a, double b, double c)
/*     */   {
/*  30 */     return b < c ? b : a < b ? c : a < c ? a : c;
/*     */   }
/*     */
/*     */   static boolean lt(double a, double eps)
/*     */   {
/*  36 */     return a < -eps;
/*     */   }
/*     */
/*     */   static boolean le(double a, double eps)
/*     */   {
/*  41 */     return a <= eps;
/*     */   }
/*     */
/*     */   static boolean ge(double a, double eps)
/*     */   {
/*  46 */     return a > -eps;
/*     */   }
/*     */
/*     */   static boolean eq(double a, double eps)
/*     */   {
/*  51 */     return (a <= eps) && (a >= -eps);
/*     */   }
/*     */
/*     */   static boolean gt(double a, double eps)
/*     */   {
/*  56 */     return a > eps;
/*     */   }
/*     */
/*     */   static double baseLength(Tuple2f u, Tuple2f v)
/*     */   {
/*  62 */     double x = v.x - u.x;
/*  63 */     double y = v.y - u.y;
/*  64 */     return Math.abs(x) + Math.abs(y);
/*     */   }
/*     */
/*     */   static double sideLength(Tuple2f u, Tuple2f v)
/*     */   {
/*  70 */     double x = v.x - u.x;
/*  71 */     double y = v.y - u.y;
/*  72 */     return x * x + y * y;
/*     */   }
/*     */
/*     */   static boolean inBetween(int i1, int i2, int i3)
/*     */   {
/*  82 */     return (i1 <= i3) && (i3 <= i2);
/*     */   }
/*     */
/*     */   static boolean strictlyInBetween(int i1, int i2, int i3)
/*     */   {
/*  87 */     return (i1 < i3) && (i3 < i2);
/*     */   }
/*     */
/*     */   static double stableDet2D(Triangulator triRef, int i, int j, int k)
/*     */   {
/*     */     double det;
/*     */     double det;
/* 104 */     if ((i == j) || (i == k) || (j == k)) {
/* 105 */       det = 0.0D;
/*     */     }
/*     */     else {
/* 108 */       Point2f numericsHP = triRef.points[i];
/* 109 */       Point2f numericsHQ = triRef.points[j];
/* 110 */       Point2f numericsHR = triRef.points[k];
/*     */       double det;
/* 112 */       if (i < j)
/*     */       {
/*     */         double det;
/* 113 */         if (j < k) {
/* 114 */           det = Basic.det2D(numericsHP, numericsHQ, numericsHR);
/*     */         }
/*     */         else
/*     */         {
/*     */           double det;
/* 115 */           if (i < k)
/* 116 */             det = -Basic.det2D(numericsHP, numericsHR, numericsHQ);
/*     */           else
/* 118 */             det = Basic.det2D(numericsHR, numericsHP, numericsHQ);
/*     */         }
/*     */       }
/*     */       else
/*     */       {
/*     */         double det;
/* 121 */         if (i < k) {
/* 122 */           det = -Basic.det2D(numericsHQ, numericsHP, numericsHR);
/*     */         }
/*     */         else
/*     */         {
/*     */           double det;
/* 123 */           if (j < k)
/* 124 */             det = Basic.det2D(numericsHQ, numericsHR, numericsHP);
/*     */           else
/* 126 */             det = -Basic.det2D(numericsHR, numericsHQ, numericsHP);
/*     */         }
/*     */       }
/*     */     }
/* 130 */     return det;
/*     */   }
/*     */
/*     */   static int orientation(Triangulator triRef, int i, int j, int k)
/*     */   {
/* 142 */     double numericsHDet = stableDet2D(triRef, i, j, k);
/*     */     int ori;
/*     */     int ori;
/* 144 */     if (lt(numericsHDet, triRef.epsilon)) { ori = -1; }
/*     */     else
/*     */     {
/* 145 */       int ori;
/* 145 */       if (gt(numericsHDet, triRef.epsilon)) ori = 1; else
/* 146 */         ori = 0;
/*     */     }
/* 147 */     return ori;
/*     */   }
/*     */
/*     */   static boolean isInCone(Triangulator triRef, int i, int j, int k, int l, boolean convex)
/*     */   {
/* 164 */     boolean flag = true;
/* 165 */     if (convex) {
/* 166 */       if (i != j) {
/* 167 */         int numericsHOri1 = orientation(triRef, i, j, l);
/*     */
/* 169 */         if (numericsHOri1 < 0) flag = false;
/* 170 */         else if (numericsHOri1 == 0) {
/* 171 */           if (i < j) {
/* 172 */             if (!inBetween(i, j, l)) flag = false;
/*     */
/*     */           }
/* 175 */           else if (!inBetween(j, i, l)) flag = false;
/*     */         }
/*     */       }
/*     */
/* 179 */       if ((j != k) && (flag == true)) {
/* 180 */         int numericsHOri2 = orientation(triRef, j, k, l);
/*     */
/* 183 */         if (numericsHOri2 < 0) flag = false;
/* 184 */         else if (numericsHOri2 == 0) {
/* 185 */           if (j < k) {
/* 186 */             if (!inBetween(j, k, l)) flag = false;
/*     */
/*     */           }
/* 189 */           else if (!inBetween(k, j, l)) flag = false;
/*     */         }
/*     */       }
/*     */     }
/*     */     else
/*     */     {
/* 195 */       int numericsHOri1 = orientation(triRef, i, j, l);
/* 196 */       if (numericsHOri1 <= 0) {
/* 197 */         int numericsHOri2 = orientation(triRef, j, k, l);
/* 198 */         if (numericsHOri2 < 0) flag = false;
/*     */       }
/*     */     }
/* 201 */     return flag;
/*     */   }
/*     */
/*     */   static int isConvexAngle(Triangulator triRef, int i, int j, int k, int ind)
/*     */   {
/* 224 */     if (i == j) {
/* 225 */       if (j == k)
/*     */       {
/* 230 */         return 1;
/*     */       }
/*     */
/* 236 */       return 1;
/*     */     }
/*     */
/* 239 */     if (j == k)
/*     */     {
/* 249 */       return -1;
/*     */     }
/*     */
/* 252 */     int numericsHOri1 = orientation(triRef, i, j, k);
/*     */     int angle;
/*     */     int angle;
/* 256 */     if (numericsHOri1 > 0) {
/* 257 */       angle = 1;
/*     */     }
/*     */     else
/*     */     {
/*     */       int angle;
/* 259 */       if (numericsHOri1 < 0) {
/* 260 */         angle = -1;
/*     */       }
/*     */       else
/*     */       {
/* 266 */         Point2f numericsHP = new Point2f();
/* 267 */         Point2f numericsHQ = new Point2f();
/* 268 */         Basic.vectorSub2D(triRef.points[i], triRef.points[j], numericsHP);
/* 269 */         Basic.vectorSub2D(triRef.points[k], triRef.points[j], numericsHQ);
/* 270 */         double numericsHDot = Basic.dotProduct2D(numericsHP, numericsHQ);
/*     */         int angle;
/* 271 */         if (numericsHDot < 0.0D)
/*     */         {
/* 275 */           angle = 0;
/*     */         }
/*     */         else
/*     */         {
/* 283 */           angle = spikeAngle(triRef, i, j, k, ind);
/*     */         }
/*     */       }
/*     */     }
/*     */
/* 288 */     return angle;
/*     */   }
/*     */
/*     */   static boolean pntInTriangle(Triangulator triRef, int i1, int i2, int i3, int i4)
/*     */   {
/* 301 */     boolean inside = false;
/* 302 */     int numericsHOri1 = orientation(triRef, i2, i3, i4);
/* 303 */     if (numericsHOri1 >= 0) {
/* 304 */       numericsHOri1 = orientation(triRef, i1, i2, i4);
/* 305 */       if (numericsHOri1 >= 0) {
/* 306 */         numericsHOri1 = orientation(triRef, i3, i1, i4);
/* 307 */         if (numericsHOri1 >= 0) inside = true;
/*     */       }
/*     */     }
/* 310 */     return inside;
/*     */   }
/*     */
/*     */   static boolean vtxInTriangle(Triangulator triRef, int i1, int i2, int i3, int i4, int[] type)
/*     */   {
/* 327 */     boolean inside = false;
/* 328 */     int numericsHOri1 = orientation(triRef, i2, i3, i4);
/* 329 */     if (numericsHOri1 >= 0) {
/* 330 */       numericsHOri1 = orientation(triRef, i1, i2, i4);
/* 331 */       if (numericsHOri1 > 0) {
/* 332 */         numericsHOri1 = orientation(triRef, i3, i1, i4);
/* 333 */         if (numericsHOri1 > 0) {
/* 334 */           inside = true;
/* 335 */           type[0] = 0;
/*     */         }
/* 337 */         else if (numericsHOri1 == 0) {
/* 338 */           inside = true;
/* 339 */           type[0] = 1;
/*     */         }
/*     */       }
/* 342 */       else if (numericsHOri1 == 0) {
/* 343 */         numericsHOri1 = orientation(triRef, i3, i1, i4);
/* 344 */         if (numericsHOri1 > 0) {
/* 345 */           inside = true;
/* 346 */           type[0] = 2;
/*     */         }
/* 348 */         else if (numericsHOri1 == 0) {
/* 349 */           inside = true;
/* 350 */           type[0] = 3;
/*     */         }
/*     */       }
/*     */     }
/* 354 */     return inside;
/*     */   }
/*     */
/*     */   static boolean segIntersect(Triangulator triRef, int i1, int i2, int i3, int i4, int i5)
/*     */   {
/* 379 */     if ((i1 == i2) || (i3 == i4)) return false;
/* 380 */     if ((i1 == i3) && (i2 == i4)) return true;
/*     */
/* 382 */     if ((i3 == i5) || (i4 == i5)) triRef.identCntr += 1;
/*     */
/* 384 */     int ori3 = orientation(triRef, i1, i2, i3);
/* 385 */     int ori4 = orientation(triRef, i1, i2, i4);
/* 386 */     if (((ori3 == 1) && (ori4 == 1)) || ((ori3 == -1) && (ori4 == -1))) {
/* 387 */       return false;
/*     */     }
/* 389 */     if (ori3 == 0) {
/* 390 */       if (strictlyInBetween(i1, i2, i3)) return true;
/* 391 */       if (ori4 == 0) {
/* 392 */         if (strictlyInBetween(i1, i2, i4)) return true;
/*     */       }
/*     */       else
/* 394 */         return false;
/*     */     }
/* 396 */     else if (ori4 == 0) {
/* 397 */       if (strictlyInBetween(i1, i2, i4)) return true;
/* 398 */       return false;
/*     */     }
/*     */
/* 401 */     int ori1 = orientation(triRef, i3, i4, i1);
/* 402 */     int ori2 = orientation(triRef, i3, i4, i2);
/* 403 */     if (((ori1 <= 0) && (ori2 <= 0)) || ((ori1 >= 0) && (ori2 >= 0))) {
/* 404 */       return false;
/*     */     }
/* 406 */     return true;
/*     */   }
/*     */
/*     */   static double getRatio(Triangulator triRef, int i, int j, int k)
/*     */   {
/* 427 */     Point2f p = triRef.points[i];
/* 428 */     Point2f q = triRef.points[j];
/* 429 */     Point2f r = triRef.points[k];
/*     */
/* 432 */     double a = baseLength(p, q);
/* 433 */     double b = baseLength(p, r);
/* 434 */     double c = baseLength(r, q);
/* 435 */     double base = max3(a, b, c);
/*     */
/* 437 */     if (10.0D * a < Math.min(b, c)) return 0.1D;
/*     */
/* 439 */     double area = stableDet2D(triRef, i, j, k);
/* 440 */     if (lt(area, triRef.epsilon)) {
/* 441 */       area = -area;
/*     */     }
/* 443 */     else if (!gt(area, triRef.epsilon)) {
/* 444 */       if (base > a) return 0.1D;
/* 445 */       return 1.7976931348623157E+308D;
/*     */     }
/*     */
/* 448 */     double ratio = base * base / area;
/*     */
/* 450 */     if (ratio < 10.0D) return ratio;
/*     */
/* 452 */     if (a < base) return 0.1D;
/* 453 */     return ratio;
/*     */   }
/*     */
/*     */   static int spikeAngle(Triangulator triRef, int i, int j, int k, int ind)
/*     */   {
/* 468 */     int ind2 = ind;
/* 469 */     int i2 = triRef.fetchData(ind2);
/*     */
/* 474 */     int ind1 = triRef.fetchPrevData(ind2);
/* 475 */     int i1 = triRef.fetchData(ind1);
/*     */
/* 480 */     int ind3 = triRef.fetchNextData(ind2);
/* 481 */     int i3 = triRef.fetchData(ind3);
/*     */
/* 486 */     return recSpikeAngle(triRef, i, j, k, ind1, ind3);
/*     */   }
/*     */
/*     */   static int recSpikeAngle(Triangulator triRef, int i1, int i2, int i3, int ind1, int ind3)
/*     */   {
/* 498 */     if (ind1 == ind3)
/*     */     {
/* 504 */       return -2;
/*     */     }
/*     */
/* 507 */     if (i1 != i3)
/*     */     {
/*     */       int ii2;
/*     */       int ii1;
/*     */       int ii2;
/* 508 */       if (i1 < i2) {
/* 509 */         int ii1 = i1;
/* 510 */         ii2 = i2;
/*     */       }
/*     */       else {
/* 513 */         ii1 = i2;
/* 514 */         ii2 = i1;
/*     */       }
/* 516 */       if (inBetween(ii1, ii2, i3)) {
/* 517 */         i2 = i3;
/* 518 */         ind3 = triRef.fetchNextData(ind3);
/* 519 */         i3 = triRef.fetchData(ind3);
/*     */
/* 521 */         if (ind1 == ind3) return 2;
/* 522 */         int ori = orientation(triRef, i1, i2, i3);
/* 523 */         if (ori > 0) return 2;
/* 524 */         if (ori < 0) return -2;
/* 525 */         return recSpikeAngle(triRef, i1, i2, i3, ind1, ind3);
/*     */       }
/*     */
/* 528 */       i2 = i1;
/* 529 */       ind1 = triRef.fetchPrevData(ind1);
/* 530 */       i1 = triRef.fetchData(ind1);
/* 531 */       if (ind1 == ind3) return 2;
/* 532 */       int ori = orientation(triRef, i1, i2, i3);
/* 533 */       if (ori > 0) return 2;
/* 534 */       if (ori < 0) return -2;
/* 535 */       return recSpikeAngle(triRef, i1, i2, i3, ind1, ind3);
/*     */     }
/*     */
/* 539 */     int i0 = i2;
/* 540 */     i2 = i1;
/* 541 */     ind1 = triRef.fetchPrevData(ind1);
/* 542 */     i1 = triRef.fetchData(ind1);
/*     */
/* 544 */     if (ind1 == ind3) return 2;
/* 545 */     ind3 = triRef.fetchNextData(ind3);
/* 546 */     i3 = triRef.fetchData(ind3);
/* 547 */     if (ind1 == ind3) return 2;
/* 548 */     int ori = orientation(triRef, i1, i2, i3);
/* 549 */     if (ori > 0) {
/* 550 */       int ori1 = orientation(triRef, i1, i2, i0);
/* 551 */       if (ori1 > 0) {
/* 552 */         int ori2 = orientation(triRef, i2, i3, i0);
/* 553 */         if (ori2 > 0) return -2;
/*     */       }
/* 555 */       return 2;
/*     */     }
/* 557 */     if (ori < 0) {
/* 558 */       int ori1 = orientation(triRef, i2, i1, i0);
/* 559 */       if (ori1 > 0) {
/* 560 */         int ori2 = orientation(triRef, i3, i2, i0);
/* 561 */         if (ori2 > 0) return 2;
/*     */       }
/* 563 */       return -2;
/*     */     }
/*     */
/* 566 */     Point2f pq = new Point2f();
/* 567 */     Basic.vectorSub2D(triRef.points[i1], triRef.points[i2], pq);
/* 568 */     Point2f pr = new Point2f();
/* 569 */     Basic.vectorSub2D(triRef.points[i3], triRef.points[i2], pr);
/* 570 */     double dot = Basic.dotProduct2D(pq, pr);
/* 571 */     if (dot < 0.0D) {
/* 572 */       ori = orientation(triRef, i2, i1, i0);
/* 573 */       if (ori > 0) return 2;
/* 574 */       return -2;
/*     */     }
/*     */
/* 577 */     return recSpikeAngle(triRef, i1, i2, i3, ind1, ind3);
/*     */   }
/*     */
/*     */   static double angle(Triangulator triRef, Point2f p, Point2f p1, Point2f p2)
/*     */   {
/* 597 */     int sign = Basic.signEps(Basic.det2D(p2, p, p1), triRef.epsilon);
/*     */
/* 599 */     if (sign == 0) return 0.0D;
/*     */
/* 601 */     Point2f v1 = new Point2f();
/* 602 */     Point2f v2 = new Point2f();
/* 603 */     Basic.vectorSub2D(p1, p, v1);
/* 604 */     Basic.vectorSub2D(p2, p, v2);
/*     */
/* 606 */     double angle1 = Math.atan2(v1.y, v1.x);
/* 607 */     double angle2 = Math.atan2(v2.y, v2.x);
/*     */
/* 609 */     if (angle1 < 0.0D) angle1 += 6.283185307179586D;
/* 610 */     if (angle2 < 0.0D) angle2 += 6.283185307179586D;
/*     */
/* 612 */     double angle = angle1 - angle2;
/* 613 */     if (angle > 3.141592653589793D) angle = 6.283185307179586D - angle;
/* 614 */     else if (angle < -3.141592653589793D) angle = 6.283185307179586D + angle;
/*     */
/* 616 */     if (sign == 1) {
/* 617 */       if (angle < 0.0D) return -angle;
/* 618 */       return angle;
/*     */     }
/*     */
/* 621 */     if (angle > 0.0D) return -angle;
/* 622 */     return angle;
/*     */   }
/*     */ }

/* Location:           Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name:     com.sun.j3d.utils.geometry.Numerics
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.utils.geometry.Numerics

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.