# Best way to calculate these steps?

• 11-04-2008
6tr6tr
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?
• 11-04-2008
master5001
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).
• 11-04-2008
tabstop
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.
• 11-04-2008
matsp
Or look up Bresenham's line drawing algorithm - it is one of the better.

--
Mats
• 11-04-2008
6tr6tr
Quote:

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.