弦と矢と半径 – 9
JavaScript で.
<body> c : <input type='number' id='in__c' value='80.0' size='10' step='any' /><input type='submit' value='c_rs' id='c_rs' /> <span id='out_c'> </span> <br /> s : <input type='number' id='in__s' value='20.0' size='10' step='any' /><input type='submit' value='s_rc' id='s_rc' /> <span id='out_s'> </span> <br /> r : <input type='number' id='in__r' value='50.0' size='10' step='any' /><input type='submit' value='r_cs' id='r_cs' /> <span id='out_r'> </span> <br /> <img src='r_cs.png' width='300px'> <script> function r_cs (c , s) { return ( ( c*c ) / ( 8*s ) + s/2 ) ; } function s_rc (r , c) { return ( r-Math.sqrt(r*r - (c/2)*(c/2) ) ) ; } function c_rs (r , s) { return ( Math.sqrt(r*r - (r-s)*(r-s) )*2 ) ; } function f_c_rs () { var oc = document.querySelector("#out_c") ; var os = document.querySelector("#out_s") ; var or = document.querySelector("#out_r") ; var ic = document.querySelector("#in__c") ; var is = document.querySelector("#in__s") ; var ir = document.querySelector("#in__r") ; var fc = parseFloat(ic.value) ; var fs = parseFloat(is.value) ; var fr = parseFloat(ir.value) ; oc.textContent = "" ; os.textContent = "" ; or.textContent = "" ; oc.textContent = c_rs(fr,fs) ; } // ... { var ec = document.getElementById("c_rs") ; var es = document.getElementById("s_rc") ; var er = document.getElementById("r_cs") ; ec.addEventListener("click",f_c_rs, false) ; es.addEventListener("click",f_s_rc, false) ; er.addEventListener("click",f_r_cs, false) ; } </script> </body>