-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVtron.Math.js
More file actions
51 lines (35 loc) · 1.21 KB
/
Vtron.Math.js
File metadata and controls
51 lines (35 loc) · 1.21 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
if(!Vtron){ var Vtron = {}; }
(function (Vtron) {
if(!Vtron.Math){ Vtron.Math = {}; }
//-----------------------------------------------------
Vtron.Math.map = function(value, istart, istop, ostart, ostop, bclamp) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
}
//-----------------------------------------------------
Vtron.Math.clamp = function(value, lowVal,highVal) {
value = Math.max(value,lowVal);
value = Math.min(value,highVal);
return value;
}
//-----------------------------------------------------
Vtron.Math.dist = function(x1,y1,x2,y2) {
return Math.sqrt(Math.pow((x2-x1),2) + Math.pow(y2-y1,2));
}
//-----------------------------------------------------
Vtron.Math.getAngle = function(x1, y1, x2, y2) {
return Math.atan2(y2 - y1, x2 - x1);
}
//-----------------------------------------------------
Vtron.Math.radToDeg = function(radians) {
return (radians*180)/Math.PI;
}
//-----------------------------------------------------
Vtron.Math.withinRect = function(x,y, rectX, rectY, rectW, rectH) {
if(x > rectX && x < rectX + rectWidth) {
if(y > rectY && y < rectY + rectHeight) {
return true;
}
}
return false;
}
})(Vtron);