Added Hermite functions
This commit is contained in:
7
HermiteTest/index.html
Normal file
7
HermiteTest/index.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<section>
|
||||
<h2>Hermite test</h2>
|
||||
<code>
|
||||
<div id="content"></div>
|
||||
</code>
|
||||
#
|
||||
</section>
|
||||
28
HermiteTest/index.py
Executable file
28
HermiteTest/index.py
Executable 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()
|
||||
44
HermiteTest/js/HermiteTest.js
Normal file
44
HermiteTest/js/HermiteTest.js
Normal 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('];');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user