Getting the coordinates of a point travelling a vector

40 Views Asked by At

So I'm currently having a problem with a python game.

Let's say we have a square with a side of $600$ pixels, let's call the top segment $AB$ and the bottom one $CD$.

Now on the $AB$ segment there is a point named $a$ that varies in the range $[A;B]$, we are able to determine it's x coordinate on $AB$ at any time using a python function.

Likewise on the $CD$ segment we have a point named $s$ that varies over time in the range $C;D$, we are also able to determine it's x coordinates at any time.

Thus, the y coordinates of $a$ and $s$ is respectively $0$ and $600$.

Now I'm creating a vector which goes from the center of $a$ to the center of $s$ named $\vec t$ , I need to make a point say $p$ (that is on $a$ originally) travel through that vector until it arrives on $s$ at a constant speed of $5$ pixels per seconds (for example).

Now I am trying to calculate dynamically the coordinates of $p$ on vector $\vec t$.

Ditto I apply the equation $y = m * x$ to find the y coordinate of $p$ and $$x = \frac{y}{m}$$ to find the x coordinate of $p$ dynamically.

Now is that correct? If not what other thing can I do?

PS: I need to have the answer in terms of $x$ and $y$ if possible.

Here is a gif for visualization

Thanks in advance.