##DESCRIPTION
##  Trigonometry problem: Solve a special right triangle
##ENDDESCRIPTION

##KEYWORDS('trigonometry', 'right triangle', 'triangle')

## DBsubject(Trigonometry)
## DBchapter(Triangle Trigonometry)
## DBsection(Applications of special triangles & right triangles)
## Level(2)
## Author(K. Andrew Parker)
## Institution(CUNY City Tech)
## Language(en)


########################################################################

DOCUMENT();      

loadMacros(
   "PGstandard.pl",     # Standard macros for PG language
   "MathObjects.pl",
   "PGML.pl",
   "PGgraphmacros.pl"
);

# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;

##############################################################
#
#  Setup
#
#
Context("Numeric");
Context()->flags->set(reduceConstants=>0, reduceConstantFunctions=>0);
Parser::Number::NoDecimals();

$leg = random(2,9,1);
$hyp = Formula("$leg sqrt(2)");


$forty5 = "45~~x{00B0}";

$xmin = 0;
$xmax = 1;
$ymin = 0;
$ymax = 1;

$gr = init_graph(-0.15,-0.15,1.15,1.15,size=>[300,300]);
$gr->lb('reset');
$gr->lb( new Label($xmin,$ymin,'A','black','center','top'));
$gr->lb( new Label($xmax,$ymin,'B','black','center','top'));
$gr->lb( new Label($xmin,$ymax,'C','black','center','bottom'));

$gr->lb( new Label($xmin+0.05,$ymax-0.13,"$forty5",'blue','center','middle'));
$gr->lb( new Label($xmax-0.1,$ymin+0.03,"$forty5",'blue','center','middle'));

$gr->lb( new Label(0.5,$ymin-0.025,'x','red','center','middle'));
$gr->lb( new Label($xmin-0.03,0.5,"$leg",'blue','center','middle'));
$gr->lb( new Label(0.55,0.5,'h','red','center','middle'));

$gr->moveTo($xmin,$ymin);
$gr->lineTo($xmax,$ymin,"black",2); # bottom edge
$gr->lineTo($xmin,$ymax,"black",2); # hypotenuse
$gr->lineTo($xmin,$ymin,"black",2); # left edge



##############################################################
#
#  Text
#
#

BEGIN_PGML

>> [@ image(insertGraph($gr), width=>400, height=>400) @]* <<

If [` \overline{AC} `] has length [$leg], find the length of [` \overline{AB} `] and [` \overline{BC} `].  

[` \overline{AB} = `] [__________]{$leg}  
[` \overline{BC} = `] [__________]{$hyp}  

* Your answers need to be in exact form, do not use decimal approximations.
* To enter a number like [` \sqrt{3} `], use _sqrt(3)_.

END_PGML

BEGIN_PGML_HINT

Any 45-45-90 triangle will also be an isosceles triangle.

Which two sides must have the same length?

Can you use this knowledge to determine the remaining sides?

END_PGML_HINT
BEGIN_PGML_SOLUTION

45-45-90 triangles are always isosceles triangles.

The legs always have the same length.

So we know right away that both [` \overline{AB} = [$leg] `] and [` \overline{AC} = [$leg] `]

Now that we know two sides of this right triangle, Pythagorean theorem will help us with the remaining side:

    [` \overline{AB}^2 + \overline{AC}^2 = \overline{BC}^2 `]

    [` ([$leg])^2 + ([$leg])^2 = \overline{BC}^2 `]

    [` [@$leg**2@] + [@$leg**2@] = \overline{BC}^2 `]

    [` [@2*$leg**2@] = \overline{BC}^2 `]

    [` \sqrt{[@2*$leg**2@]} = \overline{BC} `]

    [` [$leg]\sqrt{2} = \overline{BC} `]

END_PGML_SOLUTION

COMMENT("Funded by US DoE Title V: Opening Gateways grant.");

ENDDOCUMENT();        
