# Thread: Best way to calculate these steps?

1. ## Best way to calculate these steps?

I have a canvas with something at a point and when the user enters in a new point, to move it to there. The issue is that i want to move it "evenly" and smoothly.

If abs( x - newX ) == abs( y - newY ), then there's no issue. Just move +/-1 in each direction. The issue becomes when the diff.'s in the x points is not the same as the diff's in the y points. What algorithm would i use to make it move in a straight line to the point, in consistent steps?

2. I am a blond. So speak slowly here:

[Point] -------------------------- [Some other point] ??

Are you just trying to move in a line from one place to another (not necessarily a horizontal one, as in my ascii rendition of the problem).

3. So figure out how many steps you want to take (we will call it 17 for the purposes of discussion). Then divide the difference (in x, and in y) by 17 and use that as the step size.

4. Or look up Bresenham's line drawing algorithm - it is one of the better.

--
Mats

5. Originally Posted by matsp
Or look up Bresenham's line drawing algorithm - it is one of the better.

--
Mats
Thanks, I'll look that up.

What I am doing is figuring out which "diff" is less and then making that be the number of steps.