-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvect_util.cpp
43 lines (38 loc) · 942 Bytes
/
vect_util.cpp
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
#include "vect.cpp"
#include <cstdarg>
using namespace std;
//additional utilities for vect.cpp
template<typename T>
vect<T,3> cross(const vect<T,3>& a, const vect<T,3>& b){
vect<T,3> ret;
ret[0] = a[1]*b[2]-a[2]*b[1];
ret[1] = a[2]*b[0]-a[0]*b[2];
ret[2] = a[0]*b[1]-a[1]*b[0];
return ret;
}
template<typename T,int n,int m>
vect<T,n> change_dim(const vect<T,m>& v){
vect<T,n> ret;
for(int i=0;i<min(n,m);i++) ret[i] = v[i];
return ret;
}
template<typename T,int n>
vect<T,n> make_vect(T first,...){
va_list args;
vect<T,n> ret;
ret[0]=first;
va_start(args,first);
for(int i=1;i<n;i++)
ret[i]=va_arg(args,T);
va_end(args);
return ret;
}
//project a onto b
template<typename T,int d>
vect<T,d> proj(vect<T,d> a,vect<T,d> b){
return ((a*b)/(b*b))*b;
}
template<typename T,int n>
vect<T,n> orth_proj(const vect<T,n>& a, const vect<T,n>& b){
return a-proj(a,b);
}