Created
August 6, 2015 04:31
-
-
Save mathdoodle/db28c91288e367a5acca to your computer and use it in GitHub Desktop.
Matrix4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"uuid": "cb207fcb-2fc9-4b64-b71f-a3464224b0ea", | |
"description": "Matrix4", | |
"dependencies": { | |
"DomReady": "latest", | |
"davinci-blade": "1.1.1", | |
"davinci-eight": "latest" | |
}, | |
"operatorOverloading": true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exp = blade.universals.exp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<style> | |
/* STYLE-MARKER */ | |
</style> | |
<!-- SCRIPTS-MARKER --> | |
</head> | |
<body> | |
<pre id='info'></pre> | |
<script> | |
// LIBS-MARKER | |
</script> | |
<script> | |
// CODE-MARKER | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create shortcuts for some values. | |
var e1 = blade.e3ga.e1; | |
var e2 = blade.e3ga.e2; | |
var e3 = blade.e3ga.e3; | |
var meter = blade.scalarE3(1, blade.units.meter); | |
var newton = blade.scalarE3(1, blade.units.newton); | |
var kilogram = blade.scalarE3(1, blade.units.kilogram); | |
var second = blade.scalarE3(1, blade.units.second); | |
// Wait for the DOM to be loaded. | |
DomReady.ready(function() { | |
try { | |
calculate(); | |
} | |
catch(e) { | |
function colorize(arg: any, color: string) { | |
return "<span style='color:"+color+"'>" + arg + "</span>"; | |
} | |
println(colorize(e.message, 'red')); | |
} | |
}); | |
/** | |
* Performs the calculation. | |
*/ | |
function calculate() { | |
var I = EIGHT.Matrix4.identity(); | |
// FIXME: This is a bad API, because we can easily omit scale factors of unity. | |
// We also can't easily scale an arbitrary direction. | |
var S = EIGHT.Matrix4.scaling(4 * e1); | |
var T = EIGHT.Matrix4.translation(2 * e1 + 3 * e2 + 4 * e3); | |
var R = EIGHT.Matrix4.rotation(exp(-0.5 *(e1 ^ e2)*30*Math.PI/180)); | |
var RI = EIGHT.Matrix4.identity().invert(R); | |
// printvar('I', I.toFixed(0), true); | |
printvar('S', S.toFixed(3), true); | |
// printvar('T', T.toFixed(0), true); | |
printvar('R', R.toFixed(3), true); | |
printvar('R.determinant()', R.determinant().toFixed(6), true); | |
printvar('RI', RI.toFixed(3), true); | |
printvar('R * RI', (R * RI).toFixed(3), true); | |
printvar('RI * S * R', (RI * S * R).toFixed(3), true); | |
} | |
/** | |
* Print the HTML string without a line ending. | |
*/ | |
function print(html: string): void { | |
var element = document.getElementById('info'); | |
element.innerHTML = element.innerHTML + html; | |
} | |
/** | |
* Print the HTML string and go to the next line. | |
*/ | |
function println(html: string): void { | |
print(html + '\n'); | |
} | |
/** | |
* Print the value of a variable. | |
*/ | |
function printvar(name: string, value: any, newLine=false): void { | |
if (newLine) { | |
println('<b>' + name + '</b> =>\n' + value); | |
} | |
else { | |
println('<b>' + name + '</b> => ' + value); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#info { | |
position: absolute; | |
left: 40%; | |
top: 50px; | |
font-size: 26px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment