球形坐标javascript

时间:2018-10-02 14:55:20

标签: javascript html

嗨! 我是javascript的新手,我尝试计算球坐标中给出的两个(GNNS)点之间的距离?我的脚本:

    function spherical_dist() {

        fi_A = document.sphere.fi_A.value;
        lambda_A = document.sphere.lambda_A.value;
        fi_B = document.sphere.fi_B.value;
        lambda_B = document.sphere.lambda_B.value;

        R = 6378000;

        dlambda_AB = lambda_B - lambda_A;
        nu_AB = Math.acos( sin(fi_A) * Math.sin(fi_B) + Math.cos(fi_A) * Math.cos(fi_B) * Math.cos(dlambda_AB) );
        ro = 180/Math.PI;
        S_AB = R * nu_AB / ro;

        document.sphere.S_AB.value=S_AB;
    }

我的问题是:在语法上正确吗? 我想为我的一项家庭作业编写HTMH代码(也是HTML的新功能)。整个脚本:

<html>
<head>
    <title>Distance between two coordinates in spherical coordinate system</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
</head>

<script language="JavaScript">
    function init() {
        document.sphere.S_AB.value="";
        document.sphere.fi_A.value="";
        document.sphere.lambda_A.value="";
        document.sphere.fi_B.value="";
        document.sphere.lambda_B.value="";
    }

    function sz_enter() {
        if (event.keyCode==13) {
            spherical_dist();
        }
    }

    function spherical_dist() {

        fi_A = document.sphere.fi_A.value;
        lambda_A = document.sphere.lambda_A.value;
        fi_B = document.sphere.fi_B.value;
        lambda_B = document.sphere.lambda_B.value;

        R = 6378000;

        dlambda_AB = lambda_B - lambda_A;
        nu_AB = Math.acos( sin(fi_A) * Math.sin(fi_B) + Math.cos(fi_A) * Math.cos(fi_B) * Math.cos(dlambda_AB) );
        ro = 180/Math.PI;
        S_AB = R * nu_AB / ro;

        document.sphere.S_AB.value=S_AB;
    }
</script>

<body bgcolor="#FFFFFF" text="#000000">
    <form name="sphere" method="post" action="">

        <p>P1 Longitude: <input type="text" name="fi_A"></p>

        <p>P1 Latitude: <input type="text" name="lambda_A"></p>

        <p>P2 Longitude: <input type="text" name="fi_B"></p>

        <p>P2 Latitude: <input type="text" name="lambda_B" onFocus="init();"></p>

        <p><input type="button" name="start" value="Calculate" onClick="spherical_dist();"></p>

        <hr>

        <p>
        Distance between the two points [m]: <input type="text" name="S_AB" size="10" readonly>
        </p>
    </form>

    Explanation: <br>
    - Here comes some explanation
</body>

感谢您的帮助! :)

0 个答案:

没有答案
相关问题