Added unfinished 3$ Recognizer
[gsk.git] / GestureDetectionApp / GestureRecognition / src / at / mus / recognition / ThreeDollar / Vector.java
blob8f5788dea5af36aaab6be9e60c1f1a229a8d89b6
1 package at.mus.recognition.ThreeDollar;
3 public class Vector {
4 public float x, y, z;
6 public Vector(float x, float y, float z) {
7 this.x = x;
8 this.y = y;
9 this.z = z;
12 public Vector(float[] value) {
13 this(value[0], value[1], value[2]);
16 public Vector(Vector acc) {
17 this.x = acc.x;
18 this.y = acc.y;
19 this.z = acc.z;
22 public float[] values() {
23 return new float[] { x, y, z };
26 /**
27 * Returns distance between 2 vectors
29 * @param acc
30 * @return
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));
36 /**
37 * Returns length of the vector
39 * @return
41 public float length() {
42 return (float) Math.sqrt(x * x + y * y + z * z);
45 /**
46 * Returns unit vector
48 * @return
50 public final Vector unit() {
51 float norm = (float) (1.0 / length());
52 return new Vector(norm * x, norm * y, norm * z);
55 /**
56 * Returns difference between 2 vectors
58 * @return
60 public final Vector difference(Vector v) {
61 return new Vector(x - v.x, y - v.y, z - v.z);
64 /**
65 * Returns vector orthogonal to (cross-product of) this vector and a
67 * @param v
68 * @return
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);
86 return theta;
87 } else {
88 return 0.0f;