book collections email follower instructable user
Picture of Fraction Action With Coding

CREATOR(S): Diane Brancazio and Anya Timchenko, MIT Edgerton Center

Lesson Overview

How can I divide a piece into 3rds, 10ths, 17ths? How do quarters and 12ths compare? Investigate fractions and the math behind them! Use Codeblocks, the Autodesk coding environment in Tinkercad, to automatically create fractional pieces. View them or 3D print them. Make them in stock shapes or create your own shape.

This lesson explores the algorithms used to divide a standard piece into any number of fractions and line them up side by side to recreate the whole. Follow the code provided to step through the math, then come with your own shapes or algorithms.

Essential Question:

What algorithms can be used to divide an object and line the pieces up side by side?

What are the basic principles of coding and how are they useful in understanding mathematical concepts?

Skills Taught:

  • Algorithms to divide parts into fractions
  • Basic coding principles
  • Coordinate planes with X, Y, Z axes
  • 3D modeling

Time Required: 1 - 2 Hours

Materials Needed:

  • Codeblocks workspace in Tinkercad
  • 3D printer and filament

Step 1: Understand the Project and Explore Codeblocks

Context

3D modeling can be useful for visualizing and exploring concepts without the need for objects to be 3D printed. This activity is based on Tinkercad Codeblocks where users “design with code” - making 3D models using draggable blocks of code. Codeblocks is easy for beginners to learn, and is a useful tool for learning and practicing coding and math as well as 3D modeling.

Features of Codeblocks:

  • There are computation blocks for common math functions including: ( ) + - * /.
  • Objects can be moved around the design space on standard X, Y, Z axes, and can be scaled along those axes as well.
  • Designers can create and set variables for objects and for mathematical quantities and can call them in the math computation blocks.
  • Count and Repeat loops are available for replicating objects easily
  • All the usual Tinkercad 3D modeling capability of building with primitive shapes that can be solid or holes, and grouping to create new shapes.

*************************************************************************

The first step is to get familiar with the block-based programming environment in Tinkercad Codeblocks. Watch the Quick Start Guide on the Codeblocks site to learn how to snap and unsnap blocks. Explore and practice with these investigations:

1. The Workplane and the Origin

a. The Workplane measures 200 mm x 200 mm. The Origin is the center point where X = 0, Y = 0, and Z = 0

b. Objects come into the Workplane with their center points on the Origin. To set objects to specific positions, it is necessary to shift them in the X, Y, and Z directions. A convenient way to do that is to move the object by half its size in the X, Y, and or Z direction. Some objects allow you to set those Width, Length, and Height dimensions when they are created, others you can determine by moving them around.

2. Moving

a. Pick a Shape. Click and drag it into the black workspace.

b. Find the “Move” function. Click and drag it into the code space until it attaches to the Shape:

c. Play around with the X, Y and Z values individually.

  • At what position do all shapes start when imported?
  • What happens when you make a value negative?

Examples:

3. Scaling

a. Some Shapes will have an extended size arrow that imports the Shape with that specified size. Import and play around with the options to see how the object changes.

Example:

b. Locate and import the “Scale” function into the code space.

c. Attach the “Scale” to the Shape and play around with changing the X, Y and Z variables.

4. Rotating

a. Import a new Shape or use an existing Shape.

b. Find and add the “Rotate around” function to the Shape.

c. Rotate the Shapes around the X, Y and Z directions, switching the degree variable each time.

d. Try adding multiple rotations to the same shape.

Does the direction change the second/third time you rotate?

Example:

5. Group

a. Import two or more shapes.

b. Add a “Move”, “Rotate” or “Scale” one of them.

c. Turn one of the shapes into a hole.

d. Find the “Create group” function, add it to the shapes.

e. Group the shapes as followed:

  • Solid grouped to solid. Overall shape: Solid.
  • Solid grouped to a hole. Overall shape: Solid.

6. Define variable

a. Import the “Create Variable” into the code space.

b. In the drop-down options, select “Rename Variable…” and rename as “Number pieces”. In the number box on the right, change the variable to anything between 1 and 10. (This number will be a reference for the repeat variable to refer to.)

c . Find and attach a “Count with” to the bottom of the “Create Variable”. The variable “i” is the index number used in the Count loop

d. Under “Data” find the “Number pieces”, and drag the code into the “10” box.

e. Import a “Shape”, a “Move”, and a computation block “0 + 0” found under “Math” into the code space. Change the + to any of the drop-down selection (+,-,*,/) and choose a number to move the shape by in the second number variable box. You can play the “0+0” blocks inside each other and play around with the math to see how the equation affects the X, Y, and Z movement.

Here is an example of a math equation placed in the Y variable:

((5 + i) * number pieces)) The i stands for the “Count with” number variable and the number pieces references the number found in the “Count Variable”.

f. Add the “Shape” and “Move” code into “Count with” and play the code.

g. Play around with the numbers under “Move”, and “Create Variable”. Try changing the 1 in “count with”, to see how it affects the code.

7. Repeat variable.

a. Find and import the “Repeat” function.

b. Add two or more “Set Color”.

c. Play around with the colors and see if you can make a glowing pattern.

You should now be comfortable enough with Codeblocks to easily follow the activity instructions. Have fun!