~ubuntu-branches/ubuntu/quantal/commons-math/quantal

« back to all changes in this revision

Viewing changes to src/main/java/org/apache/commons/math/geometry/Vector3D.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2010-04-05 23:33:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100405233302-gpqlceked76nw28a
Tags: 2.1-1
* New upstream release.
* Bump Standards-Version to 3.8.4: no changes needed
* Bump debhelper to >= 7
* Switch to 3.0 (quilt) source format:
  - Remove B-D on quilt
  - Add d/source/format
  - Remove d/README.source

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import org.apache.commons.math.MathRuntimeException;
23
23
import org.apache.commons.math.util.MathUtils;
24
24
 
25
 
/** 
 
25
/**
26
26
 * This class implements vectors in a three-dimensional space.
27
27
 * <p>Instance of this class are guaranteed to be immutable.</p>
28
 
 * @version $Revision: 769880 $ $Date: 2009-04-29 15:10:01 -0400 (Wed, 29 Apr 2009) $
 
28
 * @version $Revision: 922713 $ $Date: 2010-03-13 20:26:13 -0500 (Sat, 13 Mar 2010) $
29
29
 * @since 1.2
30
30
 */
31
31
 
53
53
  /** Opposite of the third canonical vector (coordinates: 0, 0, -1).  */
54
54
  public static final Vector3D MINUS_K = new Vector3D(0, 0, -1);
55
55
 
 
56
  // CHECKSTYLE: stop ConstantName
56
57
  /** A vector with all coordinates set to NaN. */
57
58
  public static final Vector3D NaN = new Vector3D(Double.NaN, Double.NaN, Double.NaN);
 
59
  // CHECKSTYLE: resume ConstantName
58
60
 
59
61
  /** A vector with all coordinates set to positive infinity. */
60
62
  public static final Vector3D POSITIVE_INFINITY =
111
113
  }
112
114
 
113
115
  /** Multiplicative constructor
114
 
   * Build a vector from another one and a scale factor. 
 
116
   * Build a vector from another one and a scale factor.
115
117
   * The vector built will be a * u
116
118
   * @param a scale factor
117
119
   * @param u base (unscaled) vector
348
350
      }
349
351
      return Math.PI - Math.asin(v3.getNorm() / normProduct);
350
352
    }
351
 
    
 
353
 
352
354
    // the vectors are sufficiently separated to use the cosine
353
355
    return Math.acos(dot / normProduct);
354
356
 
374
376
   * @return  true if any coordinate of this vector is NaN; false otherwise
375
377
   */
376
378
  public boolean isNaN() {
377
 
      return Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z);        
 
379
      return Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z);
378
380
  }
379
 
  
 
381
 
380
382
  /**
381
383
   * Returns true if any coordinate of this vector is infinite and none are NaN;
382
384
   * false otherwise
384
386
   * false otherwise
385
387
   */
386
388
  public boolean isInfinite() {
387
 
      return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y) || Double.isInfinite(z));        
 
389
      return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y) || Double.isInfinite(z));
388
390
  }
389
 
  
 
391
 
390
392
  /**
391
393
   * Test for the equality of two 3D vectors.
392
394
   * <p>
404
406
   * @return true if two 3D vector objects are equal, false if
405
407
   *         object is null, not an instance of Vector3D, or
406
408
   *         not equal to this Vector3D instance
407
 
   * 
 
409
   *
408
410
   */
409
411
  @Override
410
412
  public boolean equals(Object other) {
411
413
 
412
 
    if (this == other) { 
 
414
    if (this == other) {
413
415
      return true;
414
416
    }
415
417
 
416
 
    if (other == null) {
417
 
      return false;
418
 
    }
419
 
 
420
 
    try {
421
 
 
 
418
    if (other instanceof Vector3D) {
422
419
      final Vector3D rhs = (Vector3D)other;
423
420
      if (rhs.isNaN()) {
424
421
          return this.isNaN();
425
422
      }
426
423
 
427
 
      return (x == rhs.x) && (y == rhs.y) && (z == rhs.z); 
428
 
 
429
 
    } catch (ClassCastException ex) {
430
 
        // ignore exception
431
 
        return false;
 
424
      return (x == rhs.x) && (y == rhs.y) && (z == rhs.z);
432
425
    }
433
 
 
 
426
    return false;
434
427
  }
435
 
  
 
428
 
436
429
  /**
437
430
   * Get a hashCode for the 3D vector.
438
431
   * <p>
439
432
   * All NaN values have the same hash code.</p>
440
 
   * 
 
433
   *
441
434
   * @return a hash code value for this object
442
435
   */
443
436
  @Override