I would like to find each integer coordinate point between 2 set of coordinate points.
For example, I need the coordinates between (2,15) (6,15). It should give me (3,15) (4,15) (5,15)
. I cannot find any math formula or c++ code that does this.
I want all the coordinates on the line connecting the two points where both X and Y happen to be integers
(6,15)&(6,17) = (6,16)
The coordinates form a shape such as Rectangle or cross and the basic idea is to get the coordinates between each set of coordinates.
Rectabgle Shape
Point [1] : (2, 17)
Point [2] : (2, 15)
Point [3] : (6, 15)
Point [4] : (6, 17)
Points on perimeter : (2, 16), (3, 15), (4, 15), (5, 15), (6, 16), (5, 17), (4, 17), (3, 17)
Hope this explains better on what I want to achieve.
Trying to find all the coordinates on the line connecting the two points where both X and Y happen to be integers:
First, as another poster pointed out, you need to put this in the form
y = mx + b:Now iterate:
This code is not tested, and it fails if
EndX < StartX, but it should get you started. If someone has a better comparison method, let me know and I’ll include it.Edited to add
The question has been closed, probably because it was not stated clearly, but I’ve added a line to show where you need to handle
StartX == EndXandStartY == EndY.