Skip to content

Instantly share code, notes, and snippets.

@raphaelm
Created April 19, 2010 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphaelm/371311 to your computer and use it in GitHub Desktop.
Save raphaelm/371311 to your computer and use it in GitHub Desktop.
Strahlensätze: JavaScript zur Berechnung fehlender Werte in bestimmten Figuren unter Anwendung der Strahlensätze
<!--
strahlensatz.html
Copyright 2010 Raphael Michel <webmaster@raphaelmichel.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Strahlensätze</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<style type="text/css">
.simple {
width: 372px;
height: 205px;
background: url('simple.gif');
}
.simple input {
width: 50px;
position: relative;
margin:0;
padding:2px;
border: 1px solid black;
}
#sa {
left: 50px;
top: 60px;
}
#sb {
left: 120px;
top: 20px;
}
#sc {
left: -70px;
top: 145px;
}
#sd {
left: 0px;
top: 165px;
}
#su {
left: -75px;
top: 95px;
}
#sv {
left: -10px;
top: 95px;
}
.ext {
width: 372px;
height: 205px;
background: url('ext.gif');
}
.ext input {
width: 50px;
position: relative;
margin:0;
padding:2px;
border: 1px solid black;
}
#ea {
left: 75px;
top: 60px;
}
#ec {
left: 15px;
top: 150px;
}
#ed {
left: 75px;
top: 60px;
}
#eb {
left: 15px;
top: 130px;
}
#eu {
left: -230px;
top: 110px;
}
#ev {
top: 100px;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
function value(variable){
variable = variable.replace(/,/g, ".");
if(!isNaN(parseFloat(variable)) && variable != "" && parseFloat(variable) > 0)
return parseFloat(variable)
else
return -1
}
function scalc(){
a = value($("#sa").val());
b = value($("#sb").val());
c = value($("#sc").val());
d = value($("#sd").val());
u = value($("#su").val());
v = value($("#sv").val());
olda = a;
oldb = b;
oldc = c;
oldd = d;
oldu = u;
oldv = v;
if(a != -1 && b != -1 && v != -1 && u != -1){
if((a+b)/a != v/u){
alert("Das geht nicht!");
return false;
}
}
if(c != -1 && d != -1 && v != -1 && u != -1){
if(v/u != (c+d)/c){
alert("Das geht nicht!");
return false;
}
}
if(a != -1 && b != -1 && c != -1 && d != -1){
if(a/b != c/d){
alert("Das geht nicht!");
return false;
}
if((a+b)/a != (c+d)/c){
alert("Das geht nicht!");
return false;
}
}
if(a == -1){
if(c != -1 && d != -1 && b != -1)
a = (c/d)*b;
}
if(b == -1){
if(c != -1 && d != -1 && a != -1)
b = (d/c)*a;
else if(v != -1 && u != -1 && a != -1)
b = (v/u)*a-a;
}
if(c == -1){
if(a != -1 && b != -1 && d != -1)
c = (a/b)*d;
}
if(d == -1){
if(b != -1 && a != -1 && c != -1)
d = (b/a)*c;
else if(v != -1 && u != -1 && c != -1)
b = (v/u)*c-c;
}
if(u == -1){
if(a != -1 && b != -1 && v != -1)
u = (a/(a+b))*v;
else if(c != -1 && d != -1 && v != -1)
u = (c/(c+d))*v;
}
if(v == -1){
if(a != -1 && b != -1 && u != -1)
v = (a/(a+b))*u;
else if(c != -1 && d != -1 && u != -1)
v = (c/(c+d))*u;
}
if(olda != a || oldb != b || oldc != c || oldd != d || oldu != u || oldv != v){
if(a > 0) $("#sa").val(a);
if(b > 0) $("#sb").val(b);
if(c > 0) $("#sc").val(c);
if(d > 0) $("#sd").val(d);
if(u > 0) $("#su").val(u);
if(v > 0) $("#sv").val(v);
scalc();
}
}
function ecalc(){
a = value($("#ea").val());
b = value($("#eb").val());
c = value($("#ec").val());
d = value($("#ed").val());
u = value($("#eu").val());
v = value($("#ev").val());
olda = a;
oldb = b;
oldc = c;
oldd = d;
oldu = u;
oldv = v;
if(u != -1 && v != -1 && a != -1 && b != -1){
if(u/v != a/b){
alert("Das geht nicht!");
return false;
}
}
if(u != -1 && v != -1 && c != -1 && d != -1){
if(u/v != c/d){
alert("Das geht nicht!");
return false;
}
}
if(a != -1 && b != -1 && c != -1 && d != -1){
if(a/b != c/d){
alert("Das geht nicht!");
return false;
}
}
if(a == -1){
if(c != -1 && d != -1 && b != -1)
a = (c/d)*b;
else if(u != -1 && v != -1 && b != -1)
a = (u/v)*b;
}
if(b == -1){
if(c != -1 && d != -1 && a != -1)
b = (d/c)*a;
else if(v != -1 && u != -1 && a != -1)
b = (v/u)*a;
}
if(c == -1){
if(a != -1 && b != -1 && d != -1)
c = (a/b)*d;
else if(u != -1 && v != -1 && d != -1)
c = (u/v)*d;
}
if(d == -1){
if(b != -1 && a != -1 && c != -1)
d = (b/a)*c;
else if(v != -1 && u != -1 && c != -1)
b = (v/u)*c;
}
if(u == -1){
if(a != -1 && b != -1 && v != -1)
u = (a/b)*v;
else if(c != -1 && d != -1 && v != -1)
u = (c/d)*v;
}
if(v == -1){
if(a != -1 && b != -1 && u != -1)
v = (b/a)*c;
else if(c != -1 && d != -1 && u != -1)
v = (d/c)*u;
}
if(olda != a || oldb != b || oldc != c || oldd != d || oldu != u || oldv != v){
if(a > 0) $("#ea").val(a);
if(b > 0) $("#eb").val(b);
if(c > 0) $("#ec").val(c);
if(d > 0) $("#ed").val(d);
if(u > 0) $("#eu").val(u);
if(v > 0) $("#ev").val(v);
ecalc();
}
}
</script>
</head>
<body>
<h1>Strahlensatz-Rechner</h1>
<p>Einfach Zahlen eingeben und auf Berechnen klicken - das Programm rechnet dann alles, was es herausfinden kann.</p>
<h2>Einfache Strahlensätze</h2>
<div class="simple">
<input type="text" id="sa" />
<input type="text" id="sb" />
<input type="text" id="sc" />
<input type="text" id="sd" />
<input type="text" id="su" />
<input type="text" id="sv" />
</div>
<input type="button" onclick="scalc()" value="Berechnen" />
<h2>Erweiterte Strahlensätze</h2>
<div class="ext">
<input type="text" id="ea" />
<input type="text" id="ec" />
<input type="text" id="ed" />
<input type="text" id="eb" />
<input type="text" id="eu" />
<input type="text" id="ev" />
</div>
<input type="button" onclick="ecalc()" value="Berechnen" />
<hr />
Programmiert 2010 von <a href="http://www.raphaelmichel.de">Raphael Michel</a>, veröffentlicht unter der GNU General Public License<br />Für die Richtigkeit der Ergebnisse wird keine Haftung übernommen!<br />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment