At My Fingertips
Rapid Playground
Have a look at these three geometric figures:
A | B | C |
---|---|---|
Here are some similarities (there are others):
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:
top
basebottom
baseheight
of the figureThere 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:
Let's try different argument values:
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 1cd5229 (Tue, 05 Nov 2024 16:55:57 GMT)