At My Fingertips

Documentation

Abstraction

Have a look at these geometric figures:

ABCDE
abcde

They are all known as kite shapes. Here are some similarities:

  • All figures have four corners (they are quadrilaterals)
  • They have a symmetry line

Notice that they are rotated such that the symmetry line is vertical.

Kites A, B, and C are convex, kites D and E are concave.

def kite(...) -> 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 vertical symmetry_diagonal
  • the length of the bottom_sides (because of the symmetry, the two bottom sides have the same length)
  • the bottom_angle (the angle between the bottom sides)

There would be other ways (e.g, to specify other angles, the other diagonal, the other side lengths), but let's go with symmetry_diagonal, bottom_side, and bottom_angle. The following function signature reflects this choice:

def kite(symmetry_diagonal: float, bottom_side: float, bottom_angle: float, color: Color) -> Graphic:

Decomposition

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

kite

One way to achieve this is to decompose the kite into triangles. We could decompose it into:

  • two isosceles triangles (top and bottom)
  • four right triangles (two halves of top part, two halves of bottom part)
  • two triangles along the symmetry diagonal (left and right part)

Let's decompose it into two triangles along the symmetry diagonal:

breakdown

Implementation

Hint: Make sure that your function can produce all the examples (convex and concave kites) shown at the beginning.

Loading...

Play With Parameters

Play with your kite function, creating kites with different sizes and angles.

Loading...

If you use 180 degrees for the bottom point, the bottom isosceles triangle collapses into a line, and only the top isosceles triangle remains.

Bottom angles greater than 180 degrees lead to concave kites. At a bottom angle of 360 degrees the kite degenerates into a line, similar to a bottom angle of 0 degrees.

Here is an overview of the effect of different bottom angles:

bottom_angleshape
angle = 0degenerate kite (line)
0 < angle < 180convex kite
angle = 180degenerate kite (isosceles triangle)
180 < angle < 360concave kite
angle = 360degenerate kite (line)

Save in Toolbox

Save the kite function in your toolbox. It will come in handy when creating other graphics (such as a star).


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

Kite

Logo of PyTamaro

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

Privacy PolicyPlatform Version 1cd5229 (Tue, 05 Nov 2024 16:55:57 GMT)