Added Hermite functions

This commit is contained in:
Thomas FORGIONE
2015-04-14 12:02:35 +02:00
parent e16e971a87
commit 848587f11b
5 changed files with 251 additions and 0 deletions

7
HermiteTest/index.html Normal file
View File

@@ -0,0 +1,7 @@
<section>
<h2>Hermite test</h2>
<code>
<div id="content"></div>
</code>
#
</section>

28
HermiteTest/index.py Executable file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from webtools import Web
def main():
print('Content-type: text/html')
print()
page = Web.Element(Web.ROOT_DIR + 'templates/page.html')
head = Web.Element(Web.ROOT_DIR + 'templates/head.html')
body = Web.Element(Web.ROOT_DIR + 'templates/body.html')
jsIncludes = Web.Element(Web.ROOT_DIR + 'templates/jsIncludes.html')
mainJs = Web.Element()
mainJs.open_string = ' <script src="js/HermiteTest.js"></script>'
content = Web.Element('index.html')
page.add_child(head)
page.add_child(body)
body.add_child(content)
body.add_child(jsIncludes)
jsIncludes.add_child(mainJs)
page.print()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,44 @@
var container = document.getElementById('content');
function print(text) {
var content = document.createTextNode(text);
var new_line = document.createElement('br');
container.appendChild(content);
container.appendChild(new_line);
}
function toString(variable) {
if (variable instanceof THREE.Vector3) {
return variable.x + ', ' + variable.y + ', ' + variable.z;
} else {
return variable;
}
}
// Test with THREE.Vector3
t = [0,1];
f = [new THREE.Vector3(0,0,0), new THREE.Vector3(1,1,1)];
fp = [new THREE.Vector3(0,1,2), new THREE.Vector3(0,0,0)];
// Test with doubles
// t = [0,1];
// f = [0,1];
// fp = [-1,-1]0;
var hermite = new Hermite.Polynom(t, f, fp);
print('M = [');
for (var t = 0; t < 1; t += 0.01) {
var res = hermite.eval(t);
print(t + ',' + toString(res) + ';');
}
print('];');
print('MP = [');
for (var t = 0; t < 1; t += 0.01) {
var res = hermite.prime(t);
print(t + ',' + toString(res) + ';');
}
print('];');