Difference between revisions of "Point (MathObject Class)"
(6 intermediate revisions by one other user not shown) | |||
Line 2: | Line 2: | ||
The Point class implements points in <math>{\bf R}^n</math> for arbitrary <math>n</math>. Typically, Points are delimited by parentheses, but that can be controlled by settings in the Context. Points are typically used in the <code>Point</code> or <code>Vector</code> Contexts, though they are also available in <code>Matrix</code> Context. It is possible to create Points in <math>{\bf C}^n</math>, though there is no pre-defined Context that makes this easy to do. |
The Point class implements points in <math>{\bf R}^n</math> for arbitrary <math>n</math>. Typically, Points are delimited by parentheses, but that can be controlled by settings in the Context. Points are typically used in the <code>Point</code> or <code>Vector</code> Contexts, though they are also available in <code>Matrix</code> Context. It is possible to create Points in <math>{\bf C}^n</math>, though there is no pre-defined Context that makes this easy to do. |
||
+ | |||
+ | The answer checker for Points can give students hints about the coordinates that are wrong, and about whether the number of coordinates is correct. |
||
=== Creation === |
=== Creation === |
||
− | Points are created via the <code>Point()</code> function, or by <code>Compute()</code> |
+ | Points are created via the <code>Point()</code> function, or by <code>Compute()</code>. |
Context("Point"); |
Context("Point"); |
||
Line 13: | Line 15: | ||
$p = Point("(3,0,-2)"); |
$p = Point("(3,0,-2)"); |
||
$p = Compute("(3,0,-2)"); |
$p = Compute("(3,0,-2)"); |
||
− | |||
+ | |||
+ | |||
+ | === Operations on Points === |
||
+ | |||
+ | Points (of the same dimension) can be added to and subtracted from each other. Points can be multiplied and divided by scalars. |
||
+ | |||
$q = $p + Point(1,3,7); # same as Point(4,3,5); |
$q = $p + Point(1,3,7); # same as Point(4,3,5); |
||
$q = $p + [1,3,7]; # same as above |
$q = $p + [1,3,7]; # same as above |
||
Line 39: | Line 46: | ||
| style="text-align:center" | <code>1</code> |
| style="text-align:center" | <code>1</code> |
||
|} |
|} |
||
+ | |||
+ | By default, the Point answer checker asks the student to type the entire point, including the parentheses and commas. This allows the student to enter point-values formulas (like sums of points, or multiples of points). You may want to restrict the operations that are allowed in the student answer, in which case you might consider using the <code>LimitedPoint</code> Context available in the <code>pg/macros/contextLimitedPoint.pl</code> file; see the [http://webwork.maa.org/pod/pg/macros/contextLimitedPoint.html POD documentation] for details. |
||
+ | |||
+ | Alternatively, you can use the Point's <code>ans_array()</code> method rather than PG's <code>ans_rule()</code> function to obtain a separate answer box for each coordinate. The Point answer checker will manage this collection of answer boxes for you, so your code doesn't have to change in any other way. |
||
+ | |||
+ | Context("Point"); |
||
+ | |||
+ | $P = Point(random(1,10,1),random(1,10,1),-1); |
||
+ | |||
+ | Context()->texStrings; |
||
+ | BEGIN_TEXT |
||
+ | \($P\) = \{$P->ans_array\} |
||
+ | END_TEXT |
||
+ | Context()->normalStrings; |
||
+ | |||
+ | ANS($P->cmp); |
||
+ | |||
+ | The value of this approach is that it forces the student to enter individual coordinates, without allowing operations on Points. |
||
=== Methods === |
=== Methods === |
||
− | The Point class supports the [[ |
+ | The Point class supports the [[Common MathObject Methods]]. There are no additional methods for this class. |
=== Properties === |
=== Properties === |
||
− | The Point class supports the [[ |
+ | The Point class supports the [[Common MathObject Properties]], and the following additional ones: |
+ | |||
+ | {| class="wikitable" |
||
+ | ! Property !! Description !! style="padding:5px" | Default |
||
+ | |||
+ | |- style="vertical-align: baseline" |
||
+ | | style="padding: 5px; white-space: nowrap" | <code>$r->{open}</code> |
||
+ | | style="padding: 5px" | The symbol to use for the open parenthesis |
||
+ | | style="text-align:center" | <code>(</code> |
||
+ | |||
+ | |- style="vertical-align: baseline" |
||
+ | | style="padding: 5px; white-space: nowrap" | <code>$r->{close}</code> |
||
+ | | style="padding: 5px" | The symbol to use for the close parenthesis |
||
+ | | style="text-align:center" | <code>)</code> |
||
+ | |} |
||
Latest revision as of 17:56, 7 April 2021
Point Class
The Point class implements points in [math]{\bf R}^n[/math] for arbitrary [math]n[/math]. Typically, Points are delimited by parentheses, but that can be controlled by settings in the Context. Points are typically used in the Point
or Vector
Contexts, though they are also available in Matrix
Context. It is possible to create Points in [math]{\bf C}^n[/math], though there is no pre-defined Context that makes this easy to do.
The answer checker for Points can give students hints about the coordinates that are wrong, and about whether the number of coordinates is correct.
Creation
Points are created via the Point()
function, or by Compute()
.
Context("Point"); $p = Point(3,0,-2); $p = Point([3,0,-2]); $p = Point("(3,0,-2)"); $p = Compute("(3,0,-2)");
Operations on Points
Points (of the same dimension) can be added to and subtracted from each other. Points can be multiplied and divided by scalars.
$q = $p + Point(1,3,7); # same as Point(4,3,5); $q = $p + [1,3,7]; # same as above $q = 3*$p; # same as Point(9,0,-6); $p = $p/2; # same as Point(3/2,0,-1);
Answer Checker
As with all MathObjects, you obtain an answer checker for a Point object via the cmp()
method:
ANS(Compute("(4,0,-2)")->cmp);
The Point class supports the common answer-checker options, and the following additional options:
Option | Description | Default |
---|---|---|
showDimensionHints => 1 or 0
|
Show/don't show messages about the wrong number of coordinates. | 1
|
showCoordinateHints => 1 or 0
|
Show/don't show message about which coordinates are right. | 1
|
By default, the Point answer checker asks the student to type the entire point, including the parentheses and commas. This allows the student to enter point-values formulas (like sums of points, or multiples of points). You may want to restrict the operations that are allowed in the student answer, in which case you might consider using the LimitedPoint
Context available in the pg/macros/contextLimitedPoint.pl
file; see the POD documentation for details.
Alternatively, you can use the Point's ans_array()
method rather than PG's ans_rule()
function to obtain a separate answer box for each coordinate. The Point answer checker will manage this collection of answer boxes for you, so your code doesn't have to change in any other way.
Context("Point"); $P = Point(random(1,10,1),random(1,10,1),-1); Context()->texStrings; BEGIN_TEXT \($P\) = \{$P->ans_array\} END_TEXT Context()->normalStrings; ANS($P->cmp);
The value of this approach is that it forces the student to enter individual coordinates, without allowing operations on Points.
Methods
The Point class supports the Common MathObject Methods. There are no additional methods for this class.
Properties
The Point class supports the Common MathObject Properties, and the following additional ones:
Property | Description | Default |
---|---|---|
$r->{open}
|
The symbol to use for the open parenthesis | (
|
$r->{close}
|
The symbol to use for the close parenthesis | )
|