JavaScript DHTML/Dojo toolkit/Math
Содержание
Calculate distance for two points
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.math._base");
function testIt() {
var s = dojox.math.distance([2,2],[4,2]);
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Convert degree to Radians
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.math._base");
function testIt() {
var s = dojox.math.degreesToRadians(90);
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Convert radian to degree
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.math._base");
function testIt() {
var s = dojox.math.radiansToDegrees(1.5707963267948966);
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Get gaussian random number
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.math._base");
function testIt() {
var s = dojox.math.gaussian();
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Get mid point
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.math._base");
function testIt() {
var s = dojox.math.midpoint([2,2],[8,2]);
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Get range
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.math._base");
function testIt() {
var s = dojox.math.range(10, 100, 5);
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Math.standard deviation
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.math._base");
function testIt() {
var s = dojox.math.sd([99,45,-17,62]);
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>