1 package at
.mus
.recognition
.ThreeDollar
;
6 public Vector(float x
, float y
, float z
) {
12 public Vector(float[] value
) {
13 this(value
[0], value
[1], value
[2]);
16 public Vector(Vector acc
) {
22 public float[] values() {
23 return new float[] { x
, y
, z
};
27 * Returns distance between 2 vectors
32 public float distance(Vector acc
) {
33 return (float) Math
.sqrt((x
- acc
.x
) * (x
- acc
.x
) + (y
- acc
.y
) * (y
- acc
.y
) + (z
- acc
.z
) * (z
- acc
.z
));
37 * Returns length of the vector
41 public float length() {
42 return (float) Math
.sqrt(x
* x
+ y
* y
+ z
* z
);
50 public final Vector
unit() {
51 float norm
= (float) (1.0 / length());
52 return new Vector(norm
* x
, norm
* y
, norm
* z
);
56 * Returns difference between 2 vectors
60 public final Vector
difference(Vector v
) {
61 return new Vector(x
- v
.x
, y
- v
.y
, z
- v
.z
);
65 * Returns vector orthogonal to (cross-product of) this vector and a
70 public Vector
orthogonal(Vector v
) {
71 return new Vector(y
* v
.z
- z
* v
.y
, z
* v
.x
- x
* v
.z
, x
* v
.y
- y
* v
.x
);
74 public final float dot_product(Vector v
) {
75 return x
* v
.x
+ y
* v
.y
+ z
* v
.z
;
78 public final float norm_dot_product(Vector v
) {
79 return dot_product(v
) / (length() * v
.length());
82 public final float angle(Vector v
) {
83 float norm_product
= norm_dot_product(v
);
84 if (norm_product
<= 1.0f
) {
85 float theta
= (float) Math
.acos(norm_product
);