function getValue(nome) { return document.getElementById(nome).value; } function setValue(nome,value) { document.getElementById(nome).value=value; hh=(getValue(nome)); if (hh=='NaN') setValue(nome,'Errore'); } function calcolaAreaEsempio1() { A=getValue('es1a'); B=getValue('es1b'); C=getValue('es1c'); Area=areaOf(A,B,C); setValue('es1Area',Area/10000); } function calcolaAreaEsempio1b() { A=getValue('es1a0'); B=getValue('es1a1'); C=getValue('es1a2'); Area=areaOf(A,B,C); Hx=Area*2/A; Hy=Math.round(Math.sqrt(Math.pow(C,2)-Math.pow(Hx,2))); //alert(Hx);alert(Hy); CVx= Math.round(Hx/3) ; CVy=Math.round((parseInt(A)+parseInt(Hy))/3); setValue('es1a3',CVx); setValue('es1a4',CVy); } function calcolaarea() { setValue('abcarea',''); setValue('adearea',''); setValue('farea',''); setValue('garea',''); setValue('harea',''); setValue('iarea',''); a=getValue('lta'); b=getValue('ltb'); c=getValue('ltc'); d=getValue('ltd'); e=getValue('lte'); f=getValue('ltf'); g=getValue('ltg'); h=getValue('lth'); i=getValue('lti'); abc=areaOf(a,b,c); ade=areaOf(a,d,e); setValue('abcarea',abc); setValue('adearea',ade); cf=areaOfchord(c,f);setValue('farea',cf); dg=areaOfchord(d,g);setValue('garea',dg); bh=areaOfchord(b,h);setValue('harea',bh); ei=areaOfchord(e,i);setValue('iarea',ei); setValue('areatot',(cf+dg+bh+ei+abc+ade)/10000); } function areaOf(x,y,z) { //formula di Erone if (x==0||y==0||z==0) {return(0);} sp = (eval(x) + eval(y) + eval(z)) / 2 // semiperimetro return Math.round( Math.sqrt (sp*(sp-x)*(sp-y)*(sp-z)) ) } function areaOfchord(corda,aln) // restituisce area allunamento { pi=Math.PI; if(aln<0) segno=-1; else segno=1; aln=Math.abs(aln); if (aln==0) return(0); raggio=(aln/2)+(Math.pow(corda,2))/(aln*8); cosAngolo=(raggio-aln)/raggio; if(Math.abs(cosAngolo==0)) return(0); angolo=(2*Math.acos(cosAngolo))*180/pi; areatriangolo=corda*(raggio-aln)/2; areasettore=(Math.pow(raggio,2)*pi)/360*angolo; return Math.round(areasettore-areatriangolo)*segno; }