Changeset 2864
 Timestamp:
 06/13/07 12:32:23 (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/loci/visbio/util/MathUtil.java
r2863 r2864 75 75 * @param v Coordinates of the second point 76 76 */ 77 public static double getDistance (double[] p, double[] v){77 public static double getDistance(double[] p, double[] v){ 78 78 int len = p.length; // redundant with getProjection 79 79 double sum = 0; … … 92 92 * @param v Coordinates of the second point 93 93 */ 94 public static double getDistance (float[] p, float[] v){94 public static double getDistance(float[] p, float[] v){ 95 95 double[] pp = new double[p.length]; 96 96 double[] vv = new double[v.length]; … … 170 170 double ydist = y  nodes[1][0]; 171 171 minDist = Math.sqrt(xdist * xdist + ydist * ydist); 172 } else {173 172 } 173 else { 174 174 for (int i=0; i<numNodes1; i++) { 175 176 177 178 179 180 181 182 183 184 185 double segDist = getDistance(a, b);186 double fracDist = getDistance(a, proj);187 188 189 175 double[] a = {nodes[0][i], nodes[1][i]}; 176 double[] b = {nodes[0][i+1], nodes[1][i+1]}; 177 double[] p = {x, y}; 178 179 double[] proj = getProjection(a, b, p, true); 180 double dist = getDistance(p, proj); 181 182 if (dist < minDist) { 183 minDist = dist; 184 seg = i; 185 double segDist = getDistance(a, b); 186 double fracDist = getDistance(a, proj); 187 weight = fracDist / segDist; 188 } 189 } 190 190 } 191 191 … … 222 222 double ydist = y  nodes[1][0]; 223 223 minDist = Math.sqrt(xdist * xdist + ydist * ydist); 224 } else {225 224 } 225 else { 226 226 for (int i=0; i<numNodes1; i++) { 227 228 229 230 231 232 233 234 235 236 237 double segDist = getDistance(a, b);238 double fracDist = getDistance(a, proj);239 240 241 227 double[] a = {(double) nodes[0][i], (double) nodes[1][i]}; 228 double[] b = {(double) nodes[0][i+1], (double) nodes[1][i+1]}; 229 double[] p = {(double) x, (double) y}; 230 231 double[] proj = getProjection(a, b, p, true); 232 double dist = getDistance(p, proj); 233 234 if (dist < minDist) { 235 minDist = dist; 236 seg = i; 237 double segDist = getDistance(a, b); 238 double fracDist = getDistance(a, proj); 239 weight = fracDist / segDist; 240 } 241 } 242 242 } 243 243 // 'seg' is always an integer; … … 297 297 return result; 298 298 } 299 299 300 300 //  Vector Math Methods  301 301 … … 315 315 } 316 316 317 /** Computes the dot product of two ND vectors */317 /** Computes the dot product of two ND vectors. */ 318 318 public static float dot(float[] a, float[] b) { 319 319 float sum = 0f; 320 320 for (int i=0; i<a.length; i++) { 321 sum += a[i] * b[i]; 321 sum += a[i] * b[i]; 322 322 } 323 323 return sum; … … 368 368 * b2 and b2 (i.e., in 2D, whether a is inside the box with diagonal 369 369 * b1b2; in 3D, whether a is inside the cube with diagonal b1b2). 370 */ 370 */ 371 371 public static boolean inside(float[] a, float[] b1, float[] b2) { 372 372 // assumes a, b1, b2 have same lengths … … 377 377 float hi = flip ? b1[i] : b2[i]; 378 378 if (a[i] < lo  a[i] > hi) { 379 between = false; 379 between = false; 380 380 break; 381 381 } … … 385 385 386 386 /** Obtains the zcoordinate of the cross product of the 2D vectors 387 * p2p1 and p3p2, useful for determining whether the curve 387 * p2p1 and p3p2, useful for determining whether the curve 388 388 * p1>p2>p3 is curving to the right or left. */ 389 389 public static float orient2D(float[] p1, float[] p2, float[] p3) { … … 391 391 float x2 = p2[0]; float y2 = p2[1]; 392 392 float x3 = p3[0]; float y3 = p3[1]; 393 // z coord. of cross product of p2(minus)p1 and p3p2 393 // z coord. of cross product of p2(minus)p1 and p3p2 394 394 float z = x1 * (y2  y3) + x2 * (y3  y1) + x3 * (y1  y2); 395 395 return z; 396 396 } 397 397 398 /** Gets a vector perpendicular to the vector p2p1, pointing to the right 398 /** Gets a vector perpendicular to the vector p2p1, pointing to the right 399 399 * with respect to the direction of p2p1. */ 400 400 public static float[] getRightPerpendicularVector2D(float[] p2, float[] p1) { … … 407 407 public static float[] getRightBisectorVector2D(float[] p1, float[] p2, 408 408 float[] p3) 409 { 409 { 410 410 // System.out.println("entering getBisectorVector2D ..."); //TEMP 411 411 // Always retrieves the bisector vector on the right (as opposed to left) 412 412 // side of the angle made by the two vectors. 413 413 414 // z coord. of cross product of p2(minus)p1 and p3p2 414 // z coord. of cross product of p2(minus)p1 and p3p2 415 415 float z = orient2D(p1, p2, p3); 416 416 … … 423 423 float[] aBisector = null; // ... says what? 424 424 if ((vAvg[0] == 0 && vAvg[1] == 0)  z == 0) { 425 // Sometimes, z can have a very small nonzero value even when 425 // Sometimes, z can have a very small nonzero value even when 426 426 // the points have the same x=coordinate 427 427 // (Apparently due to floating point arithmetic?) … … 440 440 } 441 441 442 System.out.println("z = " + z);443 System.out.println("vAvg = " + vAvg[0] + ", " + vAvg[1]);444 445 442 float[] bisector = unit(aBisector); 446 443 447 444 return bisector; 448 445 } 449 446 450 451 447 }
Note: See TracChangeset
for help on using the changeset viewer.