# Having two points (line) how can I substract a specific amount to each point?

I have two points that make a line. And I need to subtract a specific amount to each point keeping the direction of the line. I know the radius which is the amount to subtract. The red dots of the first line is what I have, and the dots of the second line is an example of what I would like to calc.

This should work:

For each point of the line:

point = point + ((otherPoint - point).normalise() * radiusToSubtract)

### Explanation:

First we get the direction from the point we're moving to the other point

(otherPoint - point).normalise()

Then we multiply that unit vector by the amount you want to budge the point toward the other point

* radiusToSubtract)

Lastly we add that to the point we're moving

point + ((otherPoint - point).normalise() * radiusToSubtract)

• It works perfectly translating your formulas to Three.js thank you.
– Enzo
Mar 2, 2019 at 23:25
• Great to hear! Glad I could help. Mar 2, 2019 at 23:30

Imperial's answer works fine if you are in a game engine that has the normalise() function, but if you are doing something a bit more homebrew, the actual math works like this:

Since both points are an object with a known X, Y, and radius value, you can use your basic slope formula tells us Slope=(Y2-Y1)/(X2-X1)

We also know that both objects will follow this slope over the distance of their radius at which point you are left with something like this to find your X: https://math.stackexchange.com/questions/566029/in-a-right-triangle-given-slope-and-length-of-hypotenuse-find-length-of-legs

With two known legs on a right triangle, the Y is just a simple pythagorean function equation.

Lastly, you need to check the directions of your rise and run because all that Squaring only produces positive values.

So what this would look like in a language agnostic since is something like this:

getCloser(target){
rise = target.y-this.y;
run = target.x-this.x;
slope = rise/run;

if (run > 0){
this.x += movX;
} else {
this.x -= movX;
}

if (rise > 0){
this.y += movY;
}else{
this.y -= movY;
}
}


then

point1.getCloser(point2);
point2.getCloser(point1);

• Yes, I'm using Three.js and have all the functions I need to work with vectors. But thank you for the deep/raw explanation.
– Enzo
Mar 2, 2019 at 23:27