At My Fingertips

Rapid Playground

Have a look at these three geometric figures:

A | B | C |
---|---|---|

Here are some similarities (there are others):

- They all have four corners
(they are
*quadrilaterals*). - They all have at least two parallel lines
(
*bases*). - They have two other lines (
*legs*) that are of equal length.

Figures like that are called *isosceles trapezoid*.

Figure C is a very special *isosceles trapezoid*:
its legs are also parallel,
its angles are all 90 degrees; it is a *rectangle*.

`def isosceles_trapezoid(...) -> Graphic:`

We can see that the color differs,
so we want to have a parameter to specify the `color`

.

There are different approaches to unambiguously specify the shape. Here is one possible way:

- the length of the
`top`

base - the length of the
`bottom`

base - the
`height`

of the figure

There would be other ways (e.g, to specify angles, or the length of the legs),
but let's go with `top`

, `bottom`

, and `height`

.
The following function signature reflects this choice:

`def isosceles_trapezoid(top: float, bottom: float, height: float, color: Color) -> Graphic:`

How would you decompose an isosceles trapezoid, given that you have functions to create a rectangle, triangle, ellipse, and circular_sector?

Yes, you can decompose it into a rectangle and two triangles.

Hint: Make sure that your function can deal with the three situations shown at the beginning:

- A: the top base is shorter than the bottom base
- B: the top base is longer than the bottom base
- C: the top base and the bottom base are equal in length

Loading...

Let's try different argument values:

Loading...

For a rectangle, the top and bottom have to have the same value. For a square, the height also has to have that same value.

An isosceles triangle is a very degenerate case of an isosceles trapezoid.
One can argue that an isosceles triangle is *not* an isosceles trapezoid,
because it has *three* corners instead of *four*.
Nevertheless, our function is able to produce an isosceles triangle
by passing 0 as an argument for one of the bases.

Even more degenerate cases would be a *line*,
which we can produce by passing 0 for both bases,
and a *point*,
which we get by passing 0 for all three lengths.
While this should work,
lines and points are invisible in PyTamaro, because their area is 0.
When you try to show a graphic with 0 area,
show_graphic will tell you that it cannot show such a graphic.

Save the `isosceles_trapezoid`

function in your toolbox.
It should be useful when creating other graphics.

This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.

Isosceles Trapezoid

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI

Privacy Policy • Platform Version 79aacf0 (Fri, 08 Nov 2024 13:24:29 GMT)