zh_CN Javascript

This commit is contained in:
Bigsk 2022-10-19 01:14:05 +08:00
parent 20fc55e989
commit b63a5dc22c
5 changed files with 208 additions and 0 deletions

5
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/

12
.idea/commu_a_c.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/commu_a_c.iml" filepath="$PROJECT_DIR$/.idea/commu_a_c.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

177
zh_CN/commu_a_c.js Normal file
View File

@ -0,0 +1,177 @@
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function sgn(n) {
if (n > 0) {
return 1;
} else if (n < 0) {
return -1;
} else {
return 0;
}
}
function fndeg(d, m, s) {
return d + sgn(d) * (m / 60 + s/ 3600);
}
function fnacs(x) {
return Math.PI / 2 - 2 * Math.atan(x / (1 + Math.sqrt(1 - x * x)));
}
function calc(tlongd, tlatd, rlongd, rlatd) {
let ro = 6370;
let gcdkm;
let btrd;
let brtd;
let r2d = 180 / Math.PI;
let d2r = Math.PI / 180;
let tlong = tlongd * d2r;
let tlat = tlatd * d2r;
let rlong = rlongd * d2r;
let rlat = rlatd * d2r;
if (tlong < 0) {
tlong = Math.PI * 2 + tlong;
}
if (rlong < 0) {
rlong = Math.PI * 2 + rlong;
}
let dlong = tlong - rlong;
if (Math.abs(dlong) > Math.PI) {
dlong = dlong - Math.PI * 2 * sgn(dlong);
}
let x = Math.sin(tlat) * Math.sin(rlat) + Math.cos(tlat) * Math.cos(rlat) * Math.cos(dlong);
let gcd = fnacs(x);
if (gcd < 0.0000001) {
gcd = 0.0000001;
}
if (Math.cos(tlat) - 0.0000001 <= 0) {
let btr;
if (tlat >= 0) {
btr = 0;
} else {
btr = Math.PI;
}
if (Math.cos(rlat) - 0.0000001 > 0) {
x = (Math.sin(tlat) - Math.sin(rlat) * Math.cos(gcd)) / (Math.cos(rlat) * Math.sin(gcd));
let brt = fnacs(x);
if (dlong < 0) {
brt = Math.PI * 2 - brt;
}
gcdkm = gcd * ro;
btrd = btr * r2d;
brtd = brt * r2d;
} else {
let brt;
if (rlat >= 0) {
brt = 0;
} else {
brt = Math.PI;
}
gcdkm = gcd * ro;
btrd = btr * r2d;
brtd = brt * r2d;
}
} else {
x = (Math.sin(rlat) - Math.sin(tlat) * Math.cos(gcd)) / (Math.cos(tlat) * Math.sin(gcd));
let btr = fnacs(x);
if (dlong > 0) {
btr = Math.PI * 2 - btr;
}
if (Math.cos(rlat) - 0.0000001 > 0) {
x = (Math.sin(tlat) - Math.sin(rlat) * Math.cos(gcd)) / (Math.cos(rlat) * Math.sin(gcd));
let brt = fnacs(x);
if (dlong < 0) {
brt = Math.PI * 2 - brt;
}
gcdkm = gcd * ro;
btrd = btr * r2d;
brtd = brt * r2d;
} else {
let brt;
if (rlat >= 0) {
brt = 0;
} else {
brt = Math.PI;
}
gcdkm = gcd * ro;
btrd = btr * r2d;
brtd = brt * r2d;
}
}
return [gcdkm, btrd, brtd];
}
function main() {
console.log("《计算通信方位角和大圆距离程序》")
let gcdkm;
let btrd;
let brtd;
rl.question("发信点经度(度,分,秒)=", function(tmp) {
tmp = tmp.toString().split(",")
let tmp2 = [];
for (let i=0;i<tmp.length;i++) {
tmp2.push(parseInt(tmp[i]))
}
tlongd = fndeg(tmp2[0], tmp2[1], tmp2[2]);
rl.question("发信点纬度(度,分,秒)=", function(tmp3) {
tmp3 = tmp3.toString().split(",")
let tmp4 = [];
for (let i=0;i<tmp3.length;i++) {
tmp4.push(parseInt(tmp3[i]))
}
tlatd = fndeg(tmp4[0], tmp4[1], tmp4[2]);
rl.question("收信点经度(度,分,秒)=", function(tmp5) {
tmp5 = tmp5.toString().split(",")
let tmp6 = [];
for (let i=0;i<tmp5.length;i++) {
tmp6.push(parseInt(tmp5[i]))
}
rlongd = fndeg(tmp6[0], tmp6[1], tmp6[2]);
rl.question("收信点纬度(度,分,秒)=", function(tmp7) {
tmp7 = tmp7.toString().split(",")
let tmp8 = [];
for (let i=0;i<tmp7.length;i++) {
tmp8.push(parseInt(tmp7[i]))
}
rlatd = fndeg(tmp8[0], tmp8[1], tmp8[2]);
let temp = calc(tlongd, tlatd, rlongd, rlatd);
let gcdkm = temp[0];
let btrd = temp[1];
let brtd = temp[2];
console.log("大圆距离为" + gcdkm + "(km)");
d = Math.trunc(btrd);
m = Math.trunc((btrd - d) * 60);
s = (btrd - d - m / 60) * 3600;
console.log("发信点对收信点的方位角为" + d + "度" + m + "分" + s + "秒");
d = Math.trunc(brtd);
m = Math.trunc((brtd - d) * 60);
s = (brtd - d - m / 60) * 3600;
console.log("收信点对发信点的方位角为" + d + "度" + m + "分" + s + "秒");
process.exit(0);
});
});
});
});
}
main()