Students apply their knowledge of the Pythagorean Theorem and Circles of Evaluation to develop a function for the distance formula.
Prerequisites |
|
Relevant Standards |
Select one or more standards from the menu on the left (⌘-click on Mac, Ctrl-click elsewhere). Common Core State Statements
|
Lesson Goals |
Students will be able to:
|
Student-Facing Lesson Goals |
|
Materials |
|
Supplemental Resources |
|
Preparation |
|
Key Points for the Facilitator |
|
- Boolean
-
a type of data with two values: true and false
- circle of evaluation
-
a diagram of the structure of an expression (arithmetic or code)
- coordinate
-
a number or set of numbers describing an object’s location
- hypotenuse
-
the side opposite the 90-degree angle in a right triangle
- interactions area
-
the right-most text box in the Editor, where expressions are entered to evaluate
- pixel
-
the smallest unit that makes up a digital image. The more pixels, the more detailed an image or video can appear.
Warmup
Students should have their workbook, pencil, and be logged into WeScheme on their computer.
Distance 30 minutes
Overview
Students discover the need for distance calculation (first in one dimention, then in two) in videogames.
Launch
Have students open this game file and investigate.
-
What seems to be missing from this game?
The characters aren’t doing anything when they collide.
-
Why are the characters moving by each other?
We haven’t given the game any instructions on what to do when the characters get close.
-
What does it mean for characters to 'hit' one another? To collide?
They have to be in the same place at the same time.
-
How will the computer know when the characters have collided?
When the coordinates of the characters are really close to each other.
Role-Play: Ask a volunteer to help role-play two characters colliding. Stand about 10 steps away from one another and side-step towards each other one step at a time, while asking, "True or False: we colliding!"
Do this until students can clearly see it’s when the two characters are 'touching' or 'overlapping' in some way - NOT when they are 'at the same point.' Don’t worry too much about clarifying the difference now, they will be able to see the differences with their own images very soon.
Have students explore using the line-length
function in the Interactions area.
Extension You can extend this |
Have students open this new game file and investigate.
Notice and Wonder What do you Notice? What do you Wonder? |
-
What kind of triangles are these?
Right triangles.
-
What do the numbers represent?
Let students discuss - the numbers should represent the lengths of the sides, but one side is always showing 0.
The missing length on the right triangle is the hypotenuse. The legs of the triangle show the length of each side, or the distance between those points on the number line.
Extension
You can take this activity further by having students prove the distance formula by solving for the hypotenuse of a right triangle. This page from Cut the Knot includes a number of different proofs. Proof #4 is especially well-suited for students who may be uncomfortable with symbol manipulation, and need more of a geometric proof. The animation on the right is a demonstration of this proof. |
Investigate
Optional: Have students use this Graphic Organizer (Page 62) to model the distance formula with the Circles of Evaluation and translate it to code.
Using Design Recipe: distance (Page 63),
have students write a function that takes in two coordinate pairs (four numbers) of two characters (x1, y1) and (x2, y2) and returns the distance between those two points.
Students can test their distance
function using Pythagorean triples, such as (3, 4, 5) or (5, 12, 13), to make sure the function is calculating the distance correctly.
Common Misconceptions
-
It is extremely common for students to put variables in the wrong order. In other words, their program looks like
…(sqrt (+ (sqr (- x1 y1)) (sqr (- x2 y2))))…
instead of…(sqrt (+ (sqr (- x2 x1)) (sqr (- y2 y1))))…
In this situation, remind student to look back at what they circled and labeled in the examples step. This is why we label!
Collision Detection 20 minutes
Overview
Students once again see function composition at work, as they compose a simple inequality with the distance
function they’ve created.
Launch
Knowing how far apart our characters are is the first step. We still need the computer to be asking: "True or False: is there a collision?"
Investigate
Using Design Recipe: collision? (Page 64), have students write a function that takes in two coordinate pairs (four numbers) of two characters (x1, y1) and (x2, y2) and returns a Boolean as to whether or not the two characters have gotten within 50 pixels of each other.
Synthesize
-
Explicitly point out that this function is easy to write because we can re-use the distance function.
-
Connect this back to
profit
,revenue
,cost
andonscreen
from previous lessons. Function composition is powerful!
Additional Exercises:
-
Bootstrap: Algebra - More Design Recipe Practice (Desmos Activity)
These materials were developed partly through support of the National Science Foundation,
(awards 1042210, 1535276, 1648684, and 1738598).
BS:Games by Jen Poole, Emmanuel Schanzer, Ed Campos Jr, and Dorai Sitaram
is licensed under a
Creative Commons 4.0 Unported License.
Based on a work at www.BootstrapWorld.org.
Permissions beyond the scope of this license may be available by contacting
schanzer@BootstrapWorld.org.