--- loncom/homework/functionplotresponse.pm 2010/10/17 22:32:19 1.14 +++ loncom/homework/functionplotresponse.pm 2010/10/19 02:04:27 1.15 @@ -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 @@ sub get_answer_from_form_fields { 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 +# + sub start_functionplotresponse { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result='';