-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVec.java
More file actions
74 lines (62 loc) · 1.53 KB
/
Copy pathVec.java
File metadata and controls
74 lines (62 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
public class Vec {
public static double dotProd(double[] a, double[] b){
return a[0]*b[0]+a[1]*b[1];
}
public static double[] prod(double[] a,double b){
double[] out=new double[2];
out[0]=a[0]*b;
out[1]=a[1]*b;
return out;
}
public static double[] sumD(double[] a,double[] b){
double[] out=new double[2];
out[0]=a[0]+b[0];
out[1]=a[1]+b[1];
return out;
}
public static double[] sum(int[] a,double[] b){
double[] out=new double[2];
out[0]=a[0]+b[0];
out[1]=a[1]+b[1];
return out;
}
public static int[] sumInt(int[] a,double[] b){
int[] out=new int[2];
out[0]=a[0]+(int)b[0];
out[1]=a[1]+(int)b[1];
return out;
}
public static int[] subInt(int[] a,int[] b){
int[] out=new int[2];
out[0]=a[0]-(int)b[0];
out[1]=a[1]-(int)b[1];
return out;
}
public static int[] sumInt(int[] a,int[] b){
int[] out=new int[2];
out[0]=a[0]+(int)b[0];
out[1]=a[1]+(int)b[1];
return out;
}
public static double[] add(double[] a,double[] b){
double[] out=new double[2];
out[0]=a[0]+b[0];
out[1]=a[1]+b[1];
return out;
}
public static double[] normalize(double[] a, int size){
double sum=0;
for(int i=0;i<size;i++){
sum+=a[i]*a[i];
}
sum=Math.sqrt(sum);
for(int i=0;i<size;i++)a[i]/=sum;
return a;
}
public static double normDouble(double[]a){
return Math.sqrt(Math.pow(a[0], 2)+Math.pow(a[1], 2));
}
public static double normInt(int[]a){
return Math.sqrt(Math.pow(a[0], 2)+Math.pow(a[1], 2));
}
}