instagram

(Also available in Pyret)

Students use function composition and the distance formula to detect when characters in their games collide.

Lesson Goals

Students will be able to:

  • Explain how the distance formula is related to the Pythagorean theorem.

  • Write a function for the distance formula.

Student-Facing Lesson Goals

  • I can explain how the distance formula is connected to the Pythagorean theorem.

  • I can write a function that takes in 2 points and returns the distance between them.

Materials

Preparation

  • Make sure all materials have been gathered

  • Decide how students will be grouped in pairs

Key Points for the Facilitator

  • The distance formula is an excellent review of Circles of Evaluation. Have students work out the expression in small groups to foster discussion.

Click here to see the prior unit-based version

Glossary
circle of evaluation

a 'sentence diagram' of the structure of a mathematical expression

pixel

the smallest unit that makes up a digital image. The more pixels, the more detailed an image or video can appear.

🔗Problem Decomposition Returns! 20 minutes

Overview

Students revisit the problem decomposition concept from earlier lessons.

Launch

Students should have their workbook, pencil, and be logged into WeScheme on their computer.

Problem Decomposition is a powerful tool, which lets us break apart complex problems into simpler ones that we can solve, test, and then glue together into a complex solution.

Students may remember that there are two strategies for doing this:

  1. Top-Down: Describe the problem at a high level, then fill in the details later

  2. Bottom-Up: Focus on the smaller parts that you’re sure of, then build them together to get the big picture

Problem Decomposition is the focus of an entire Bootstrap lesson, is used to solve “onscreen?”, and build up the 2-dimensional distance function.

Investigate

For the following complex word problem, have students first decide which strategy they want to use, and then apply the Design Recipe to build the functions they need.

A retractable flag pole starts out 24 inches tall, and can grow at a rate of 0.6in/sec. An elastic is tied to the top of the pole and anchored 200 inches from the base, forming a right triangle. Define functions that compute the height of the pole and the area of the triangle after a given number of seconds.

Have students complete the Top Down / Bottom Up worksheet, using Problem Decomposition and the Design Recipe to solve this problem!

Synthesize

  • Which strategy did students use?

  • Did they start out with one, and then switch to another?

🔗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 Word Problem: collide?, have students write a function that takes in two coordinate pairs (four numbers) of the PLAYER and a character ((px, py) and (cx, cy)), and and returns true if they are within 50 pixels of each other.

Synthesize

  • You started by writing the distance function first, and then collide? Is this Top-Down or Bottom-Up decomposition?

  • 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 and onscreen from previous lessons. Problem Decomposition is powerful!

🔗Additional Exercises:

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.