[英]Find what percent of a line a point makes up
I have two points, x2 and x1. 我有两点,x2和x1。 I have their corresponding y's, y2 and y1.
我有他们对应的y,y2和y1。
I always know that x2>.95>x1 and that y2>y1. 我一直都知道x2> .95> x1和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: 因此,我编写了这段代码,希望可以基本上找到y1-y2出现.95的位置,但是我不确定它的准确性,因此任何建议或注意都将是不错的:
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. 直线的等式为
y = mx + c
,其中m
为斜率, c
为截距。
Given (x1, y1)
and (x2, y2)
, you can find m
and c
: 给定
(x1, y1)
和(x2, y2)
,您可以找到m
和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: 现在您知道了这些,可以通过以下
x = 0.95
找到x = 0.95
时的y
值:
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)
. 由两点(x1,y1)和(x2,y2)组成的直线方程为
(y-y1)/(y2-y1) = (x-x1)/(x2-x1)
。 if xi = 0.95
, then yi = (y2-y1)*(xi-x1)/(x2-x1)+y1
如果
xi = 0.95
,则yi = (y2-y1)*(xi-x1)/(x2-x1)+y1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.