JAL-3026 comment in main test method in PDbFtsrestClient.java
[jalview.git] / srcjar / javajs / util / V3d.java
1 /*
2    Copyright (C) 1997,1998,1999
3    Kenji Hiranabe, Eiwa System Management, Inc.
4
5    This program is free software.
6    Implemented by Kenji Hiranabe(hiranabe@esm.co.jp),
7    conforming to the Java(TM) 3D API specification by Sun Microsystems.
8
9    Permission to use, copy, modify, distribute and sell this software
10    and its documentation for any purpose is hereby granted without fee,
11    provided that the above copyright notice appear in all copies and
12    that both that copyright notice and this permission notice appear
13    in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc.
14    makes no representations about the suitability of this software for any
15    purpose.  It is provided "AS IS" with NO WARRANTY.
16 */
17 package javajs.util;
18
19
20
21
22 /**
23  * A 3 element vector that is represented by double precision floating point
24  * x,y,z coordinates. If this value represents a normal, then it should be
25  * normalized.
26  * 
27  * @version specification 1.1, implementation $Revision: 1.9 $, $Date:
28  *          2006/07/28 17:01:32 $
29  * @author Kenji hiranabe
30  * 
31  * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012
32  * for unique constructor and method names
33  * for the optimization of compiled JavaScript using Java2Script
34  */
35 public class V3d extends T3d {
36
37   /**
38    * Sets this vector to be the vector cross product of vectors v1 and v2.
39    * 
40    * @param v1
41    *        the first vector
42    * @param v2
43    *        the second vector
44    */
45   public final void cross(V3d v1, V3d v2) {
46     // store on stack once for aliasing-safty
47     // i.e. safe when a.cross(a, b)
48     set(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y
49         - v1.y * v2.x);
50   }
51
52   /**
53    * Normalizes this vector in place.
54    */
55   public final void normalize() {
56     double d = length();
57
58     // zero-div may occur.
59     x /= d;
60     y /= d;
61     z /= d;
62   }
63
64   /**
65    * Computes the dot product of the this vector and vector v.
66    * 
67    * @param v
68    *        the other vector
69    * @return this.dot.v
70    */
71   public final double dot(V3d v) {
72     return x * v.x + y * v.y + z * v.z;
73   }
74
75   /**
76    * Returns the squared length of this vector.
77    * 
78    * @return the squared length of this vector
79    */
80   public final double lengthSquared() {
81     return x * x + y * y + z * z;
82   }
83
84   /**
85    * Returns the length of this vector.
86    * 
87    * @return the length of this vector
88    */
89   public final double length() {
90     return Math.sqrt(lengthSquared());
91   }
92
93 }