G
G
GineTik2021-08-02 23:18:59
Mathematics
GineTik, 2021-08-02 23:18:59

How to make a grid of rhombuses?

I have a task to make just such a grid
6108523b975de691945638.png

, it needs to be done using js canvas. And also each cell of the grid should be a separate rhombus (that is, I have to know x and y of each rhombus in the grid)

I can’t think of a way to create
it, I also wanted to say that I have a canvas center with coordinates 0, 0 and I need to place around them cells (for example, there may be coordinates 0, -50 or 100, 50)

I would be grateful for any answer!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-08-02
@GineTik

To draw a separate rhombus, it will help to mentally draw the diagonals of the rhombus: such a stretched plus. The center of the plus is the center of the rhombus.
Let these xbe ythe "radii" of the rhombus. There are coordinates of the center (cx, cy), or, more conveniently, (0, 0)the coordinates of the vertices of the rhombus are clear: (-x, 0), (0, -y), (x, 0), (0, y)(clockwise).
Neighboring rhombus on the right: (0 + 2x, 0)(center).
Rhombus down right: (0 + x, 0 + y).
When drawing on canvas, it is convenient to remember the state in order to translate the coordinates later, making the center (0, 0) the center of the next rhombus. Draw a diamond, and then restore the state of the canvas coordinates from the saved one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question