- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvectorfunc.lua
More file actions
Latest commit
34 lines (33 loc) · 628 Bytes
/
Copy pathvectorfunc.lua
File metadata and controls
34 lines (33 loc) · 628 Bytes
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
functionvecadd(a,b)
res= {};
fori=1,#ado
res[i] =a[i]+b[i];
end
returnres;
end
functionvecsub(a,b)
res= {};
fori=1,#ado
res[i] =a[i]-b[i];
end
returnres;
end
functionvecmul(a,b)
assert (type(b)=='number',"vecmul rhs must be a number")
res= {};
fori=1,#ado
res[i] =a[i]*b;
end
returnres;
end
functionvecdist(a)
locall=0;
for_,vinipairs(a) dol=l+v*vend;
returnmath.sqrt(l);
end
functionextrapolate (a,b,distance)
localdiff=vecsub(a,b)
localdist=vecdist(diff)
localnewdiff=vecmul(diff,distance/dist)
returnvecadd(a,newdiff);
end