2 * FROM : package org.freehep.graphics3d;
4 * Keeps a 3 dimensional vector.
6 * Original ArcBall C code from Ken Shoemake, Graphics Gems IV, 1993.
8 * @author Mark Donszelmann
9 * @version $Id: Vector3.java,v 1.2 2002/06/12 23:15:15 duns Exp $
14 package ini
.trakem2
.utils
;
16 public class Vector3
{
18 public double x
, y
, z
;
21 * creates vector from x,y,z
23 public Vector3(double x
, double y
, double z
) {
37 * creates vector from v
39 public Vector3(Vector3 v
) {
44 * @return string representation of vector
47 /*public String toString() {
48 return "["+x+", "+y+", "+z+"]";
54 public double length() {
55 return Math
.sqrt(x
*x
+ y
*y
+ z
*z
);
59 * @return normal vector , or null if length is 0
63 public Vector3
normalize(Vector3 r
) {
64 if (r
== null) r
= new Vector3();
65 double vlen
= length();
67 return r
.set(x
/vlen
, y
/vlen
, z
/vlen
);
74 * @return vector scaled by s
76 public Vector3
scale(double s
, Vector3 r
) {
77 if (r
== null) r
= new Vector3();
78 return r
.set(s
*x
, s
*y
, s
*z
);
82 * @return difference between vector and s
84 /*public Vector3 sub(Vector3 s, Vector3 r) {
85 if (r == null) r = new Vector3();
86 return r.set(x - s.x, y - s.y, z - s.z);
90 * @return sum of vector and v
92 public Vector3
add(Vector3 v
, Vector3 r
) {
93 if (r
== null) r
= new Vector3();
94 return r
.set(x
+ v
.x
, y
+ v
.y
, z
+ v
.z
);
98 * @return the negation of vector
100 /*public Vector3 negate(Vector3 r) {
101 if (r == null) r = new Vector3();
102 return r.set(-x, -y, -z);
106 * @return dot product of vector and v
108 /*public double dot(Vector3 v) {
109 return x*v.x + y*v.y + z*v.z;
114 * @return cross produc of vector x v
116 /*public Vector3 cross(Vector3 v, Vector3 r) {
117 if (r == null) r = new Vector3();
118 return r.set(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
122 * @return half arc between vector and v
124 /*public Vector3 bisect(Vector3 v, Vector3 r) {
125 if (r == null) r = new Vector3();
127 double length = r.length();
128 return (length < 1.0e-7) ? r.set(0, 0, 1) : r.scale(1/length, r);
132 * @return the vector set to x,y,z
134 public Vector3
set(double x
, double y
, double z
) {
141 } // End of class Vector3