Question: I have two points `A (x1,y1)` and `B (x2,y2)` that are given as an input to the program. I have to find a third point `C` that lies on the line `AB` and is at a distance `10` away from the point A.

I can easily get the slope of the line but that doesn't give me the full equation for the line. Even if I get the full equation, I am not sure using this equation, how would I find out a point that is `x` distance away from A.

Any suggestions on how to approach this?

Answer: 
There are always two points on each line:

* get the vector from `A` to `B` (subtract the coordinates)
* normalize the vector (divide by its length; pythagorean theorem)
* multiply the vector by 10 **or** -10
* add the vector to `A` to get `C`

Note that if `A==B`, the line is not defined, and this algorithm causes a division by zero. You may want to add a test for equality at the beginning.
I have done the calculation in Andengine using a Sprite object. I have two Array List x coordinates and y coordinates. Here i am just calculating using the last two values from these two array list to calculate the third point 800 pixel distant from Your point B. you can modify it using different values other than 800. Hope it will work.The coordinate system here is a little different where (0,0) on the top left corner of the screen. Thanks

```
private void addExtraCoordinate(CarSprite s) {
int x0, y0, x1, y1;
float x = 0f, y = 0f;
x0 = Math.round(xCoordinates.get(xCoordinates.size() - 2));
x1 = Math.round(xCoordinates.get(xCoordinates.size() - 1));
y0 = Math.round(yCoordinates.get(yCoordinates.size() - 2)) * (-1);
y1 = Math.round(yCoordinates.get(yCoordinates.size() - 1)) * (-1);

if (x1 == x0 && y1 == y0) {
    return;
} else if (y1 == y0 && x1 != x0) {
    if (x1 > x0) {
        x = (float) x1 + 800f;
    } else
        x = (float) x1 - 800f;
    y = Math.round(yCoordinates.get(yCoordinates.size() - 1));
} else if (y1 != y0 && x1 == x0) {
    if (y1 > y0) {
        y = (float) Math.abs(y1) - 800f;
    } else
        y = (float) Math.abs(y1) + 800f;
    x = Math.round(xCoordinates.get(xCoordinates.size() - 1));
} else {
    float m = (float) (yCoordinates.get(yCoordinates.size() - 1) * (-1) - yCoordinates
            .get(yCoordinates.size() - 2) * (-1))
            / (float) (xCoordinates.get(xCoordinates.size() - 1) - xCoordinates
                    .get(xCoordinates.size() - 2));
    if (x1 > x0) {
        x = (float) ((float) x1 + 800f / (float) Math
                .sqrt((double) ((double) 1f + (double) (m * m))));
    } else
        x = (float) ((float) x1 - 800f / (float) Math
                .sqrt((double) ((double) 1f + (double) (m * m))));

    if (y0 > y1) {
        y = (float) ((float) Math.abs(y1) + 800f / (float) Math
                .sqrt((double) (((double) 1f / (double) (m * m)) + (double) 1f)));
    } else
        y = (float) ((float) Math.abs(y1) - 800f / (float) Math
                .sqrt((double) (((double) 1f / (double) (m * m)) + (double) 1f)));
}

xCoordinates.add(x);
yCoordinates.add(y);

```

}