For example:
Code: Select all
P1
*
*
*
*
P2
That is not a problem.
For such easy example, reducing the X and Y coordinates for the next step of the diagonal line is enough:
X = X + 1
Y = Y + 1
But the problem appears when X <> Y.
When X > Y, if using the formulae there up, the Y reaches faster the Point2 'Y' coordinate, so it will not decrease/increase more, meanwhile the 'X' will still be modified until reach the Point2 'X' coordinate. This results in something like this:
Code: Select all
P1
*
*
*
************P2
I think the example is quite visual on what I want to mean.
So, I need an algorithm to allow me to trace such diagonal lines without the side effect described before. I don't mind the ASCII line to look perfect diagonal, just to have an algorithm that results on the most perfect numeric approximation.
I was trying to apply the Pythagorean Theorem, but I couldn't reach a real functionality by using the Theorem, other than acquiring the real distance between P1 and P2.
Thanks in advance.