Introduction

Area and Perimeter.
Area and Perimeter.
Photo by: Sarah Pflug.

Before we start we need to ensure we understand what a 2D shape is, please read through the following link in the Links section for a better understanding: 2D and 3D shapes.

We can calculate the perimeters and areas of shapes, we need to understand the maths behind it. Please read through the following link in the Links for a better understanding: Area and Perimeter 2D shapes. You can also watch a short video in the videos section to understand Area and Perimeter of 2D shapes.

To find the perimeter of a polygon, add all the side lengths up together.

To find the area of a square, we calculate length * width.

To find the area of triangle, we calculate ½ * base * height.

We can find the area of any regular polygon using the following formula:

area = n * a² * cot(π/n) / 4

Where n = number of sides and a = the side length

To calculate the perimeter of a square we add up the length of each side:

perimeter = 10 + 10 + 10 + 10

The area of a pentagon:

area = 5 * (7)² * cot(π/5) / 4

area = 84.3034 m²

 

Task

Tiling Company
Tiling Company
Photo by: Kiki Zhang.

A tiling company is developing a new range of kitchen and bathroom tiles.

The tiles vary in shape and size, and to know how much everything is going to cost, they need a piece of software that can help them quickly find the area and perimeter of polygons.

You’ve been tasked with creating a 2D polygon calculator!

Process

In this project we will be making a 2D shape calculator and will:

  • Let the user find the area and perimeter of triangles.
  • Let the user find the area and perimeter of squares.

Extension

  • Allow the user to find the area and perimeter of any 2D regular polygon.

You will need to read through "Level 2- 2D shapes calculator" presentation in the documents sections:

Steps:

First open Python or use the following link for an online platform: Python Online Editor

  1. 1. Read through slides 7-8 about how to code subroutines and what parameters and arguments are when parameter passing. On slide 9, your first step is to create two subroutines to calculate the area and perimeter of a square. User inputs will be passed to the subroutines which is a line of code ooutside of the routines, in the main code. To better understand subroutines please read through the following link in the Links section: Introduction to Subroutines and you can watch a short video in the video section which introduces you to subroutines: Introduction to Subroutines.
  2. Using slide 10, now create subroutines to calculate the area and perimeter or a triangle. You will need to understand how to pass parameters into functions, please watch a short video in the video section to understand Functions with Arguments.
  3. Next step is to create a menu so the user can select if they want to calculate area and perimeter for a square or a triangle. You will also use iteration here in the form of a while loop. Read through slide 11 to help you with this part.
  4. Using slides 13-14 you can modify your program so the user can calculate area and perimeter for any shape.

 

Conclusion

Now check you have completed the following Learning Outcomes:

  •  Learnt how to use subroutines.
  •  Applied programming skills to a real life problem.
  •  Created a menu that the user can interact with.

Links to everyday life:

Geometry is a really key part of many industries. Being able to rapidly calculate perimeter and area could be crucial.

In the Links section you can read how a tiling company calulates number of tiles required: Tile Calculator.

Architects, trades people, engineers – so many professions require geometry. Our programs could make their lives easier!

CONGRATULATIONS!

You have created your own 2D shapes calculator using python.

 Next Steps:

You should now move onto Installation and Introduction to Java to apply techniques learnt in a different programming lanuguage. 

Learning Objectives

Learning Objectives

  • Learn how to use subroutines.
  • Apply programming skills to a real life problem.
  • Create a menu that the user can interact with.