开发者

Find what percent of a line a point makes up

I have two points, x2 and x1. I have their corresponding y's, y2 and y1.

I always know that x2>.95>x1 and that y2>y1.

so i wrote this code, in the开发者_开发问答 hopes that I can basically find where along y1-y2 that .95 occurs, however I am not sure towards its accurancy, so any suggestions or notices would be nice:

  3 x1 = float(raw_input('x1: '))
  4 x2 = float(raw_input('x2: '))
  5 y1 = float(raw_input('y1: '))
  6 y2 = float(raw_input('y2: '))
  7 
  8 z = 0.95
  9 
 10 dist = x2-x1
 11 
 12 yi = ((1-(.01*(dist/(dist-(x2-z)))))*(y2-y1))+y1

please let me know if this is right, because I am not sure it is, but I am also not sure what I am missing.


The equation of a line is y = mx + c where m is the slope, and c is the intercept.

Given (x1, y1) and (x2, y2), you can find m and c:

m = (y2-y1)/(x2-x1)
c = y2 - m * x2

Now that you know those, you can find the value of y when x = 0.95, by:

y = m * 0.95 + c


The equation of a line by two points (x1, y1) and (x2, y2) is (y-y1)/(y2-y1) = (x-x1)/(x2-x1). if xi = 0.95, then yi = (y2-y1)*(xi-x1)/(x2-x1)+y1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜