[LON-CAPA-cvs] cvs: loncom /homework edit.pm functionplotresponse.pm insertlist.xml /homework/templates functionplotvector.problem

www www at source.lon-capa.org
Tue Feb 28 17:42:34 EST 2012


www		Tue Feb 28 22:42:34 2012 EDT

  Modified files:              
    /loncom/homework	edit.pm functionplotresponse.pm insertlist.xml 
    /loncom/homework/templates	functionplotvector.problem 
  Log:
  Vector sum tool
  
  
-------------- next part --------------
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.140 loncom/homework/edit.pm:1.141
--- loncom/homework/edit.pm:1.140	Mon Feb 13 11:23:11 2012
+++ loncom/homework/edit.pm	Tue Feb 28 22:42:31 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.140 2012/02/13 11:23:11 foxr Exp $
+# $Id: edit.pm,v 1.141 2012/02/28 22:42:31 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -427,6 +427,12 @@
 <plotvector />';
 }
 
+sub insert_drawvectorsum {
+    return '
+<drawvectorsum />';
+}
+
+
 sub insert_functionplotrule {
     return '
 <functionplotrule />';
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.92 loncom/homework/functionplotresponse.pm:1.93
--- loncom/homework/functionplotresponse.pm:1.92	Tue Feb 28 15:46:55 2012
+++ loncom/homework/functionplotresponse.pm	Tue Feb 28 22:42:31 2012
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # Functionplot responses
 #
-# $Id: functionplotresponse.pm,v 1.92 2012/02/28 15:46:55 www Exp $
+# $Id: functionplotresponse.pm,v 1.93 2012/02/28 22:42:31 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,6 +38,7 @@
   &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline',
                                                             'plotobject','plotvector',
                                                             'functionplotvectorrule','functionplotvectorsumrule',
+                                                            'drawvectorsum',
                                                             'functionplotcustomrule',
                                                             'functionplotrule','functionplotruleset',
                                                             'functionplotelements'));
@@ -591,6 +592,83 @@
 }
 
 
+#
+# Vector sum - have GeoGebra draw a sum of specified vectors to help students draw
+#
+
+sub start_drawvectorsum {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+    my $result='';
+    my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
+    my $tailx=&Apache::lonxml::get_param('tailx',$parstack,$safeeval);
+    my $taily=&Apache::lonxml::get_param('taily',$parstack,$safeeval);
+    my $vectorlist=&Apache::lonxml::get_param('vectorlist',$parstack,$safeeval);
+    my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval);
+    $label=~s/\W//gs;
+    $label=ucfirst($label);
+    unless ($label) { $label="NewVector"; }
+    if ($target eq 'web') {
+        my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
+        unless (defined($tailx)) { $tailx=$xmin; }
+        unless (defined($taily)) { $taily=$ymin; }
+        unless (defined($vectorlist)) { $vectorlist=''; }
+        my @vectors=split(/\,/,$vectorlist);
+        if ($#vectors>0) {
+            my @sumx=();
+            my @sumy=();
+            foreach my $thisvector (@vectors) {
+                $thisvector=~s/\W//gs;
+                $thisvector=ucfirst($thisvector);
+                unless ($thisvector) { next; }
+                my $vectorx=$thisvector.'X';
+                my $vectory=$thisvector.'Y';
+                $result.=(<<ENDADDVEC);
+document.ggbApplet_$internalid.evalCommand("$vectorx=x($thisvector)");
+document.ggbApplet_$internalid.evalCommand("$vectory=y($thisvector)");
+document.ggbApplet_$internalid.evalCommand("Include$thisvector$label=Checkbox[]");
+ENDADDVEC
+                push(@sumx,"If[Include$thisvector$label,$vectorx,0]");
+                push(@sumy,"If[Include$thisvector$label,$vectory,0]");
+            }
+            $result.="document.ggbApplet_$internalid.evalCommand(".'"'."xTot$label=".join('+', at sumx).'");'."\n";
+            $result.="document.ggbApplet_$internalid.evalCommand(".'"'."yTot$label=".join('+', at sumy).'");'."\n";
+            $result.=(<<ENDMAKEVECTOR);
+document.ggbApplet_$internalid.evalCommand("$label=Vector[($tailx,$taily),($tailx+xTot$label,$taily+yTot$label)]");
+document.ggbApplet_$internalid.setLabelVisible("$label",true);
+document.ggbApplet_$internalid.setLineThickness("$label",8);
+document.ggbApplet_$internalid.setColor("$label",255,0,0);
+ENDMAKEVECTOR
+        }
+    } elsif ($target eq 'edit') {
+        $result=&Apache::edit::tag_start($target,$token,'Draw Vector Sum').
+             &Apache::edit::text_arg('Label on Plot:','label',
+                                     $token,'16').
+             &Apache::edit::text_arg('Tail x:','tailx',
+                                     $token,'8').
+             &Apache::edit::text_arg('Tail y:','taily',
+                                     $token,'8').'<br />'.
+             &Apache::edit::text_arg('Vector List:','vectorlist',
+                                     $token,'40').
+             &Apache::edit::end_row();
+    } elsif ($target eq 'modified') {
+        $env{'form.'.&Apache::edit::html_element_name('label')}=ucfirst($env{'form.'.&Apache::edit::html_element_name('label')});
+        my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'label','tailx','taily','vectorlist');
+        if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
+    }
+    return $result;
+}
+
+
+sub end_drawvectorsum {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+    my $result='';
+    if ($target eq 'edit') {
+        $result=&Apache::edit::end_table();
+    }
+    return $result;
+}
+
+
 
 #
 # <backgroundplot function="..." fixed="yes/no" />
Index: loncom/homework/insertlist.xml
diff -u loncom/homework/insertlist.xml:1.30 loncom/homework/insertlist.xml:1.31
--- loncom/homework/insertlist.xml:1.30	Fri Dec  2 16:33:58 2011
+++ loncom/homework/insertlist.xml	Tue Feb 28 22:42:31 2012
@@ -65,6 +65,12 @@
                 </help>
 
         </tag>
+        <tag name="drawvectorsum">
+                <description>Draw Vector Sum</description>
+                <color>#88aa99</color>
+                <insert_sub>insert_drawvectorsum</insert_sub>
+                <allow></allow>
+        </tag>
         <tag name="functionplotruleset">
                 <description>Function Plot Rule Set</description>
                 <color>#99ff88</color>
@@ -75,7 +81,7 @@
                 <description>Function Plot Elements</description>
                 <color>#99ff88</color>
                 <insert_sub>insert_functionplotelements</insert_sub>
-                <allow>spline,backgroundplot,plotobject,plotvector</allow>
+                <allow>spline,backgroundplot,plotobject,plotvector,drawvectorsum</allow>
         </tag>
 
         <tag name="functionplotrule">
Index: loncom/homework/templates/functionplotvector.problem
diff -u loncom/homework/templates/functionplotvector.problem:1.1 loncom/homework/templates/functionplotvector.problem:1.2
--- loncom/homework/templates/functionplotvector.problem:1.1	Sat Nov 26 02:12:45 2011
+++ loncom/homework/templates/functionplotvector.problem	Tue Feb 28 22:42:34 2012
@@ -6,24 +6,27 @@
 $angle=180.*atan($slope)/$pi;
 $perp=$angle+90.;</script>
 <startouttext />
-A mass is sliding down the indicated incline with a constant velocity. Construct the free body diagram, making sure the forces are approximately proportionally correct. Leave unused vectors unattached.<br /> <endouttext />
+A mass is sliding down the indicated incline with a constant velocity. Construct the free body diagram, making sure the forces are approximately proportionally correct. Leave unused vectors unattached.<br />
+<i>You can use the red-colored vector sum tool to help you construct your diagram; check the boxes for the vectors you want included in the sum. The tool is just there to help you, its settings are not graded.</i>
+<br />
+<endouttext />
 <functionplotresponse xaxisvisible="no" xlabel="x" gridvisible="yes" ylabel="y" id="11" xmax="10" yaxisvisible="no" xmin="0" ymin="0" ymax="10" width="450" height="450">
 <functionplotelements>
 
 <backgroundplot function="$function" fixed="yes" />
 <plotobject label="Mass" x="$massx" y="$massy" />
-<plotvector label="Gravity" tailx="6" taily="1" tipx="9" tipy="1" />
-<plotvector label="KineticFriction" tailx="6" taily="2" tipx="9" tipy="2" />
-<plotvector label="StaticFriction" tailx="6" taily="3" tipx="9" tipy="3" />
-<plotvector label="NormalForce" tailx="6" taily="4" tipx="9" tipy="4" />
-
+<plotvector label="Gravity" tailx="7" taily="1" tipx="8" tipy="1" />
+<plotvector label="KineticFriction" tailx="7" taily="2" tipx="8" tipy="2" />
+<plotvector label="StaticFriction" tailx="7" taily="3" tipx="8" tipy="3" />
+<plotvector label="NormalForce" tailx="7" taily="4" tipx="8" tipy="4" />
+<drawvectorsum label="Sum" tailx="$massx" taily="$massy" vectorlist="Gravity,KineticFriction,StaticFriction,NormalForce" />
 </functionplotelements>
 <functionplotruleset>
 <functionplotvectorrule index="Grav" vector="Gravity" attachpoint="Mass" angle="270" angleerror="2" />
-<functionplotvectorrule index="Norm" vector="NormalForce" attachpoint="Mass" angle="$perp" angleerror="3" />
-<functionplotvectorrule index="KFriction" vector="KineticFriction" attachpoint="Mass" angle="$angle" angleerror="2" />
+<functionplotvectorrule index="Norm" vector="NormalForce" attachpoint="Mass" angle="$perp" angleerror="4" />
+<functionplotvectorrule index="KFriction" vector="KineticFriction" attachpoint="Mass" angle="$angle" angleerror="3" />
 <functionplotvectorrule index="SFriction" vector="StaticFriction" notattachpoint="Mass" />
-<functionplotvectorsumrule vectors="Gravity,NormalForce,KineticFriction" length="0" lengtherror="1" index="Total" />
+<functionplotvectorsumrule vectors="Gravity,NormalForce,KineticFriction" length="0" lengtherror="2" index="Total" />
 </functionplotruleset>
 <hintgroup showoncorrect="no">
     
@@ -36,6 +39,10 @@
 <hintpart on="Total">
     <startouttext />What should be the net force on the mass?<endouttext />
 </hintpart>
+<hintpart on="Norm">
+    <startouttext />What should be the direction of the normal force?<endouttext />
+</hintpart>
+
 </hintgroup>
 </functionplotresponse>
 </problem>


More information about the LON-CAPA-cvs mailing list