At My Fingertips

Documentation

Implement a rhombus function to recreate the following graphic.

rhombus

A rhombus is composed of two isosceles triangles placed one above the other.

The Upright Isosceles Triangle

Let's start by implementing the upright_isosceles_triangle function, that generates an isosceles triangle rotated upright (with a horizontal base, and the tip at the top center). An approach could be to import your isosceles_triangle function from your toolbox (or to call the triangle function with the same value for the two sides), and then to rotate the resulting triangle accordingly. The following sketches might help you with the reasoning on the rotation angle.

Note that the rotate function requires a negative angle to rotate clock-wise.

  • result of triangle(160, 160, 40, black)

    triangle not rotated

  • with horizontal and vertical axis to help find the angle of rotation

    isosceles triangle rotation

  • wanted result

    triangle rotated

Loading...

The Rhombus

Now you only have to combine two isosceles triangles, one above the other, to generate a rhombus. Implement the rhombus function using the pytamaro above and rotate functions, together with the upright_isosceles_triangle function that you just implemented.

Loading...

Save in Toolbox

Now save your rhombus function in your toolbox. It may come in handy as a component for more complex graphics in the future.


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

Rhombus

Logo of PyTamaro

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

Privacy PolicyPlatform Version 0d7866a (Fri, 20 Dec 2024 07:46:38 GMT)