-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate.js
36 lines (35 loc) · 1.16 KB
/
calculate.js
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
onmessage=function (event) {
var params=event.data;
var type=params[0];
var huchang=params[1];
var accuracy=params[3];
var multiply=params[4];
var resuleParams=new Array();
var max=10000;
if(type==0){
var gonggao=params[2];
var banjing = accuracy;
while (banjing<max) {
if (Math.abs(Math.cos((huchang) / (2 * banjing)) - ((banjing - gonggao) / banjing)) < (accuracy*multiply)) {
var xianchang = Math.sin((huchang) / (2 * banjing)) * banjing * 2;
resuleParams[0]=banjing;
resuleParams[1]=xianchang;
break;
}
banjing += accuracy;
}
}else if(type==2){
var xianchang=params[2];
var banjing = accuracy;
while (banjing<max) {
if (Math.abs(Math.sin((huchang) / (2 * banjing)) - ((xianchang / 2) / banjing)) < accuracy*multiply) {
break;
}
banjing += accuracy
}
var gonggao = banjing - Math.cos((huchang) / (2 * banjing)) * banjing;
resuleParams[0]=banjing;
resuleParams[1]=gonggao;
}
postMessage(resuleParams);
}