divide the distance between two points

108 Views Asked by At

I have two points(in two dimension) and I want to divide the distance between them to n part with same length, I was thinking about doing this manually by using for, but because it is numerical it wont be precise, so is there any way to do this? any help is appreciated.

1

There are 1 best solutions below

3
On BEST ANSWER

In your original question you wrote, "n part with same length", which implies n+1 equispaced points and n equal segments between them.

In your followup comment you wrote "n points", which implies n-1 equal spaces between them.

It's now unclear which you actually want.

p1:=[2,4]:
p2:=[6,1]:

n:=7:

# n equal distances
S1:=Matrix([seq(p1+(p2-p1)*(i-1)/(n), i=1..n+1)]);

plot(S1, style=pointline,
     symbolsize=20, symbol=solidcircle);

# n equispaced points
S2:=Matrix([seq(p1+(p2-p1)*(i-1)/(n-1), i=1..n)]);

plot(S2, style=pointline,
     symbolsize=20, symbol=solidcircle);