0
$\begingroup$

I got 4 Variables:

X
Y

TargetX
TargetY

Basically X and Y are my start Point and I want to get to The Target.

I increase both X and Y til they get to their destination

Here is a photo: diagram

I've done path A and want to do the smooth B At the moment am I increasing each one. So how do I make both X and Y reach the Destination at the same Time (X and Y value is different!) So simply make a shortcut.

//Tom

  • 0
    "I've done path A" - is that a broken-line path?2011-05-10
  • 1
    Please don't "sign" your posts; posts already include an identifier in the bottom right. If you want your name associated to your posts, then change the user name in your account to reflect that.2011-05-10

2 Answers 2

1

Compute the lengths of $A$ and $B$ and divide them into the same number of "steps".

  • 0
    So if my Start X and Y is 0 My Goal is 10,5 Then i have to??2011-05-10
1

The way I'm reading your question, you want to move along a (single) straight line from $(X,Y)$ to $(\text{Target}X, \text{Target}Y)$. To do this, simply find the difference between the $x$-values and the $y$-values and divide those by the number of steps you want. Then you can add this number to your $X$ and $Y$ repeatedly. Here's a pseudocode example that should make things clearer.

X = whatever
Y = whatever
TargetX = whatever
TargetY = whatever

dx = TargetX-X
dy = TargetY-Y

numSteps = whatever

stepX = dx/numSteps
stepY = dy/numSteps

currentX = X
currentY = Y

for t = 0 to numSteps
{
currentX = X + t*stepX
currentY = Y + t*stepY
}

That help?