@@ -53,11 +53,11 @@ =head1 DESCRIPTION
53
53
54
54
=head1 GRAPH OBJECTS
55
55
56
- There are nine types of graph objects that the students can graph. Points, lines, circles,
57
- parabolas, quadratics, cubics, intervals, sine waves, and fills (or shading of a region). The
58
- syntax for each of these objects to pass to the GraphTool constructor is summarized as follows.
59
- Each object must be enclosed in braces. The first element in the braces must be the name of the
60
- object. The following elements in the braces depend on the type of element.
56
+ There are several types of graph objects that the students can graph. Points, lines, circles,
57
+ parabolas, quadratics, cubics, intervals, sine waves, vectors, and fills (or shading of a
58
+ region). The syntax for each of these objects to pass to the GraphTool constructor is summarized
59
+ as follows. Each object must be enclosed in braces. The first element in the braces must be the
60
+ name of the object. The following elements in the braces depend on the type of element.
61
61
62
62
For points the name "point" must be followed by the coordinates. For example:
63
63
@@ -119,6 +119,12 @@ =head1 GRAPH OBJECTS
119
119
120
120
represents the function C<f(x) = 5 sin((2 pi / 3)(x - (-4))) + 2 > .
121
121
122
+ For vectors the name "vector" must be followed by the word "solid" or "dashed" to indicate if
123
+ the vector is expected to be drawn solid or dashed. That is followed by the initial point and
124
+ the terminal point. For example:
125
+
126
+ "{vector,solid,(0,0),(3,4)}"
127
+
122
128
The student answers that are returned by the JavaScript will be a list of the list objects
123
129
discussed above and will be parsed by WeBWorK and passed to the checker as such. The default
124
130
checker is designed to grade the graph based on appearance. This means that if a student graphs
@@ -298,8 +304,8 @@ =head1 OPTIONS
298
304
The order the tools are listed here will also be the order the tools are presented in the graph
299
305
tool button box. In addition to the tools listed in the default options above, there is a
300
306
"PointTool", three point "QuadraticTool", four point "CubicTool", "IntervalTool",
301
- "IncludeExcludePointTool", and "SineWaveTool ". Note that the case of the tool names must match
302
- what is shown.
307
+ "IncludeExcludePointTool", "SineWaveTool", and "VectorTool ". Note that the case of the tool
308
+ names must match what is shown.
303
309
304
310
=item staticObjects (Default: C<< staticObjects => [] >>)
305
311
@@ -439,6 +445,7 @@ sub _parserGraphTool_init {
439
445
ADD_JS_FILE(' js/GraphTool/cubictool.js' , 0, { defer => undef });
440
446
ADD_JS_FILE(' js/GraphTool/intervaltools.js' , 0, { defer => undef });
441
447
ADD_JS_FILE(' js/GraphTool/sinewavetool.js' , 0, { defer => undef });
448
+ ADD_JS_FILE(' js/GraphTool/vector.js' , 0, { defer => undef });
442
449
443
450
return ;
444
451
}
@@ -1149,6 +1156,77 @@ sub addTools {
1149
1156
}
1150
1157
);
1151
1158
}
1159
+ },
1160
+ vector => {
1161
+ js => ' graphTool.vectorTool.Vector' ,
1162
+ tikz => {
1163
+ code => sub {
1164
+ my $gt = shift ;
1165
+
1166
+ my ($p1x , $p1y ) = @{ $_ -> {data }[2]{data } };
1167
+ my ($p2x , $p2y ) = @{ $_ -> {data }[3]{data } };
1168
+
1169
+ if ($p1x == $p2x ) {
1170
+ # Vertical vector
1171
+ return (
1172
+ " \\ draw[thick, blue, line width = 2.5pt, $_ ->{data}[1], *->] ($p1x , $p1y ) -- ($p2x , $p2y );\n " ,
1173
+ [
1174
+ " ($p1x ,$gt ->{bBox}[3]) -- ($p1x ,$gt ->{bBox}[1])"
1175
+ . " -- ($gt ->{bBox}[2],$gt ->{bBox}[1]) -- ($gt ->{bBox}[2],$gt ->{bBox}[3]) -- cycle" ,
1176
+ sub { return $_ [0] - $p1x ; }
1177
+ ]
1178
+ );
1179
+ } else {
1180
+ # Non-vertical vector
1181
+ my $m = ($p2y - $p1y ) / ($p2x - $p1x );
1182
+ my $y = sub { return $m * ($_ [0] - $p1x ) + $p1y ; };
1183
+ return (
1184
+ " \\ draw[thick, blue, line width = 2.5pt, $_ ->{data}[1], *->] ($p1x , $p1y ) -- ($p2x , $p2y );\n " ,
1185
+ [
1186
+ " ($gt ->{bBox}[0],"
1187
+ . &$y ($gt -> {bBox }[0]) . ' ) -- '
1188
+ . " ($gt ->{bBox}[2],"
1189
+ . &$y ($gt -> {bBox }[2]) . ' )'
1190
+ . " -- ($gt ->{bBox}[2],$gt ->{bBox}[1]) -- ($gt ->{bBox}[0],$gt ->{bBox}[1]) -- cycle" ,
1191
+ sub { return $_ [1] - &$y ($_ [0]); }
1192
+ ]
1193
+ );
1194
+ }
1195
+ }
1196
+ },
1197
+ cmp => sub {
1198
+ my ($vector ) = @_ ;
1199
+
1200
+ my $solid_dashed = $vector -> {data }[1];
1201
+ my $initial_point = $vector -> {data }[2];
1202
+ my $terminal_point = $vector -> {data }[3];
1203
+
1204
+ # These are the coefficients a, b, and c in ax + by + c = 0.
1205
+ my @stdform = (
1206
+ $vector -> {data }[2]{data }[1] - $vector -> {data }[3]{data }[1],
1207
+ $vector -> {data }[3]{data }[0] - $vector -> {data }[2]{data }[0],
1208
+ $vector -> {data }[2]{data }[0] * $vector -> {data }[3]{data }[1] -
1209
+ $vector -> {data }[3]{data }[0] * $vector -> {data }[2]{data }[1]
1210
+ );
1211
+
1212
+ my $vectorPointCmp = sub {
1213
+ my $point = shift ;
1214
+ my ($x , $y ) = $point -> value;
1215
+ return $stdform [0] * $x + $stdform [1] * $y + $stdform [2] <=> 0;
1216
+ };
1217
+
1218
+ return (
1219
+ $vectorPointCmp ,
1220
+ sub {
1221
+ my ($other , $fuzzy ) = @_ ;
1222
+ return
1223
+ $other -> {data }[0] eq ' vector'
1224
+ && ($fuzzy || $other -> {data }[1] eq $solid_dashed )
1225
+ && $initial_point == $other -> {data }[2]
1226
+ && $terminal_point == $other -> {data }[3];
1227
+ }
1228
+ );
1229
+ }
1152
1230
}
1153
1231
);
1154
1232
@@ -1163,6 +1241,8 @@ sub addTools {
1163
1241
IntervalTool => ' graphTool.intervalTool.IntervalTool' ,
1164
1242
# A sine wave tool.
1165
1243
SineWaveTool => ' graphTool.sineWaveTool.SineWaveTool' ,
1244
+ # A vector tool.
1245
+ VectorTool => ' graphTool.vectorTool.VectorTool' ,
1166
1246
# Include/Exclude point tool.
1167
1247
IncludeExcludePointTool => ' graphTool.includeExcludePointTool.IncludeExcludePointTool' ,
1168
1248
);
0 commit comments