Friday, September 26, 2014

Coding and the equation of a circle

A student was creating a tower defence game in my computer class, doing so he learned what the equation of a circle is.  This idea is a Gr. 12 math idea, and he did this in Grade 10.  Here is what happened...

He was coding a certain tower in his game and he asked me "How do I code the tower to only attack units which are within 200 pixels?"  I first asked if he could draw me a picture of what he wanted, and below is computer graphic of what he drew..




I then said, "What do you have?" He then showed me that he created variables:

t_x = x value of the turret
t_y= y value of the turret
u_x= x value of the unit
u_y= y value of the unit
He had currently coded that if the following two inequalities were true the tower would attack.
At a quick glance we realize that this creates a square around the turret not a circle.  This he had already realized.  He then said, "How do I test if the straight line distance is less than 200?".  We then drew a picture as follows:


 He then said "Well I know that once the line from the turret to the unit is less than or equal to 200, the turret will attack but what inequality do I create?"  A student, next to him, said "Would pythagorean theorem work?".  The problem we had was to label the other two sides.  Minutes passed while I let him think, and finally he asked if this would work
 I said.. "lets try it".. sadly the turret would attack the unit if the unit was within 200 units of the origin not the turret.  Once again, I refused to simply give him the answer and I asked him, "what could we do to change from the origin to the turret?"  He replied with "Well the turret isn't always the origin, so we would have to test the distance.. and so can we do.."
I then asked, "Why did you use the absolute value before?" Which is responded "because the code needs to take the positive value, and if the unit was to the left or below the turret I need it to become positive....but....wait....squaring is positive, so can I just remove the absolute value?"  We tried and here was his final test

When tested, this worked perfectly.  Keep in mind this child is in Grade 10, and completed an outcome from Gr. 12 mathematics.



Discovering a Variable

I wanted to see if I could get students to "create" or "discover" the idea of a variable.  To try this, I completed the following in my ESL (English as a Second Language) math class.


We first started with a discussion around language, and how math is the "Universal Language".  Next, we talked about "What is the best way to learn a language?"  The students agreed that we should learn how to translate from our language into math would be a great start.  I then told them how I once ordered 2 pepperoni pizzas and 3 Hawaiian pizzas and it cost $70.00, and I asked the class if there is a way we could translate this into math?  One student came up and wrote,
2 Pepperoni + 3 Hawaiian = $70.00 
We then had a discussion how, currently, we would not be able to deduce how much each pizza cost, however this would count as a translation.  I then asked how would you translate "4 Pineapple Pizzas, 3 bottles of Coca-Cola, and 1 Meat lovers, costing $92.00"? Another student came to the board and wrote
4 Pineapple + 3 Coca Cola + 1 Meat Lovers = 92
The class again agreed this was sufficient.  At this time, a student in the back was getting irritated at how easy and time consuming this one.  I asked him to go to the front and in front of everyone translate "3 super size fries, 2 Extra large Coca-cola, and 1 double, extra bacon, cheeseburger costs $21".  He let out a big "UGH!", and asked me to repeat.  As I repeated he wrote...

3 F + 2 C + 1 CB = 21

He looked at me with a smile, and some of his classmates started to laugh.  I then told him "I said supersize fries, not Fs", which he responded with "Yeah this F is supersize fries".  We then had a dialogue around what CB could mean.  After some time, a student asked "Could that be Cheese times burgers?",  and almost immediately a student yelled "but C is coca-cola, so coca-cola times burger?". The student, at the board then changed his answer to   

3 F + 2 C + 1 B = 21

I then wrote on the board

3D +2C = 13

and asked "What does that mean?".  The answers ranged from "3 Dogs and 2 cats cost 13" to "3 bags of dill pickles and 2 bags of cheetos is $13".  We then decided, as a class, that it is important to create a legend at the top.  Therefore we went back and wrote legends such as "F is Super size fries, C is extra large Coca-Cola..."

This was my attempt at students creating their own knowledge of variables.