how i can find the next point on slope when the point can be changed?

90 Views Asked by At

iam try to find the next point on the same slope of an line i I had a problem when I tried to add A small number to find the next point add it the next point The distance has become very large i try on this formula:

          slope = (P2.Y - P1.Y) / (P2.X - P1.X);
          nx2 = P2.X +add;
          ny2 = P2.Y+ slope * add;

The nx2 is the next x , ny2 is the next y and p1,p2 is the point1 and point2; add : is the number i want to add in this case i used 18

so i used this formula in this exmaple this tow point {X=517, Y=336}--{X=505, Y=530.5} the next point is *{x=535,y=44} i just add 18 for * but on othe point the distance is normal but on other point like this distance be very far

thank you

2

There are 2 best solutions below

2
On

This is doing what it should. Your first two points have an $x$ difference of $12$ and a $y$ difference of about $-200$. The third point is $18$ away in $x$, so the $y$ difference should be about $\frac {18}{12}(-200)=-300$ and it is.

4
On

The slope can be calculated by either

$\frac {530.5 - 336}{505-517} = \frac {194.5}{-12}= -16 \frac 5{24}$.

Or by $\frac {336 - 44}{517- 535} = \frac {292}{-18}=-16 \frac 29$.

Or by $\frac {530.5 - 44}{505-535} = \frac {486.5}{-30} = -16 \frac 7{60}$.

These slopes are no exact but they all are aproximately $-16.2$ which means for every one you go over you go down $16.2$.

So to go from $x =517;y = 535$ to $x = 535$ you go over $18$. So you expect to go down $18*16.2 = 291.6$. So you go down from $y = 336$ to $y = 336-291.6 = 44.4$. Which is very close to where we did end up at $y= 44$.

"but on othe point the distance is normal but on other point like this distance be very far"

That because $-16.2$ is a very steep slope. Going over $12$ ($517-505= 12$) means going down nearly $200$ ($336 - 530.5= -194.5$). And going over $18$ $(535-517$) means going down nearly $300$ ($44-336=-292$). This is consistent. $18$ is $1\frac 12$ times $12$ and $-292$ is (about) $1\frac 12$ times $-194.5$.