ExtractingCoordinatesFromPoint: Difference between revisions
No edit summary |
(added historical tag and gave updated problem link) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{historical}} | |||
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/problem-techniques/ExtractingCoordinatesFromPoint.html a newer version of this problem]</p> | |||
<h2>Extracting coordinates from a Point: PG Code Snippet</h2> | <h2>Extracting coordinates from a Point: PG Code Snippet</h2> | ||
Line 44: | Line 47: | ||
Context( "Point" ); | Context( "Point" ); | ||
push( @point, Point( random(1,5,1) , random(-5,-1,1) ) ); | push(@point, Point(random(1,5,1), random(-5,-1,1))); | ||
push( @point, Point( random(5,10,1) , random(6,11,1) ) ); | push(@point, Point(random(5,10,1), random(6,11,1))); | ||
# now we have two points, $point[0] = (x1,y1) | |||
# and $point[1] = (x2,y2). | |||
# the following makes $d1 = x1 - x2, $d2 = y1 - y2 | |||
($d1, $d2) = ($point[0] - $point[1])->value; | |||
Line 80: | Line 86: | ||
BEGIN_TEXT | BEGIN_TEXT | ||
Consider the two points \( $point[0] \) and \( $point[1] \). | Consider the two points \( $point[0] \) | ||
The distance between them is:\{ $length->ans_rule() \} | and \( $point[1] \). | ||
The distance between them is: | |||
\{ $length->ans_rule() \} | |||
$BR | $BR | ||
The midpoint of the line segment | The midpoint of the line segment |
Latest revision as of 13:42, 28 June 2023
This problem has been replaced with a newer version of this problem
Extracting coordinates from a Point: PG Code Snippet
This code snippet shows the essential PG code to evaluate antderivative and general antiderivative formulas. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.
This wiki page is under construction as of 6/13/08.
PG problem file | Explanation |
---|---|
loadMacros("MathObjects.pl"); |
In the initialization section, we need to include the macros file |
Context( "Point" ); push(@point, Point(random(1,5,1), random(-5,-1,1))); push(@point, Point(random(5,10,1), random(6,11,1))); # now we have two points, $point[0] = (x1,y1) # and $point[1] = (x2,y2). # the following makes $d1 = x1 - x2, $d2 = y1 - y2 ($d1, $d2) = ($point[0] - $point[1])->value; $length = Compute("sqrt( ($d1)^2+($d2)^2 )"); $mid = ( $point[1] + $point[0] ) / 2; |
In the problem setup section of the file, we put the value of the subtraction of two Points in two variables, Alternative method: If you want to get only one of the coordinates of a Point, you can use the
We don't use Alternative method: You can use
We need to put parentheses around |
Context()->texStrings; BEGIN_TEXT Consider the two points \( $point[0] \) and \( $point[1] \). The distance between them is: \{ $length->ans_rule() \} $BR The midpoint of the line segment that joins them is:\{ $mid->ans_rule() \} $BR END_TEXT Context()->normalStrings; |
The problem text section of the file is as we'd expect. |
ANS( $length->cmp ); ANS( $mid->cmp ); |
As is the answer. |