Q:

Divide a Line and get its points

I have the coordinates for Point A and Point B.

Now I want to divide this line in k equal parts, and get the points coordinates (red lines are the points):

How do I do this? I know that's a simple formula but I'm having trouble with it.
Thanks !

A:

If you want to divide the line into $k$ equal parts, you will need $k-1$ points.
Let $A$ be $(x_A,y_A)$ and $B$ be $(x_B,y_B)$.  The $k-1$ points would be
$$(x_A+\frac{x_B-x_A}{k},y_A+\frac{y_B-y_A}{k})\\(x_A+2\frac{x_B-x_A}{k},y_A+2\frac{y_B-y_A}{k})\\(x_A+3\frac{x_B-x_A}{k},y_A+3\frac{y_B-y_A}{k})\\\dots\\(x_A+(k-1)\frac{x_B-x_A}{k},y_A+(k-1)\frac{y_B-y_A}{k})$$
Note, this works for lines that are horizontal, vertical or "diagonals".  If you know they will be "horizontal", the formula can be simplified (though this one will still work).

