F
F
Festelo2018-08-22 02:37:12
Algorithms
Festelo, 2018-08-22 02:37:12

How to get segment points given start and end coordinates?

Good afternoon! I want to make a small game, but I need to draw a line through the cells. Something like this:
bDt65jj.png
The input is the coordinates of the beginning and end of the segment.
The program should display the coordinates of each point of the segment (we draw by cells, i.e. all numbers are integers).
Example from the screenshot above:
In: (1;1), (10;5)
Out: (1;1), (2;1), (3;2), (4;2), (5;3), (6;3), (7;3), (8;4), (9;4), (10;5)
I understand that more than one option is possible here, but any one that at least looks a little like Painter's.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-08-22
@Festelo

Bresenham's algorithm

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question