[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm
www
www@source.lon-capa.org
Tue, 19 Oct 2010 02:04:27 -0000
www Tue Oct 19 02:04:27 2010 EDT
Modified files:
/loncom/homework functionplotresponse.pm
Log:
Server-side spline calculation
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.14 loncom/homework/functionplotresponse.pm:1.15
--- loncom/homework/functionplotresponse.pm:1.14 Sun Oct 17 22:32:19 2010
+++ loncom/homework/functionplotresponse.pm Tue Oct 19 02:04:27 2010
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: functionplotresponse.pm,v 1.14 2010/10/17 22:32:19 www Exp $
+# $Id: functionplotresponse.pm,v 1.15 2010/10/19 02:04:27 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -453,6 +453,40 @@
return ($answer,%coords);
}
+#
+# The following functions calculate the cubic-hermite splines server-side
+#
+
+sub cubic_hermite {
+ my ($t,$p1,$s1,$p2,$s2)=@_;
+ return (2.*$t*$t*$t-3.*$t*$t+1.)*$p1 + 5.*($t*$t*$t-2.*$t*$t+$t)*($s1-$p1)+
+ (-2.*$t*$t*$t+3.*$t*$t) *$p2 + 5.*($t*$t*$t-$t*$t) *($s2-$p2);
+}
+
+#
+# d/dt(...)
+#
+
+sub ddt_cubic_hermite {
+ my ($t,$p1,$s1,$p2,$s2)=@_;
+ return (6.*$t*$t-6.*$t) *$p1 + 5.*(3.*$t*$t-4.*$t+1.)*($s1-$p1)+
+ (-6.*$t*$t+6.*$t)*$p2 + 5.*(3.*$t*$t-2.*$t) *($s2-$p2);
+}
+
+#
+# d^2/dt^2(...)
+#
+
+sub d2dt2_cubic_hermite {
+ my ($t,$p1,$s1,$p2,$s2)=@_;
+ return (12.*$t-6.) *$p1 + 5.*(6.*$t-4.)*($s1-$p1)+
+ (-12.*$t+6.)*$p2 + 5.*(6.*$t-2.)*($s2-$p2);
+}
+
+#
+# Implentation of <functionplotresponse>
+#
+
sub start_functionplotresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result='';