问题
I can do this on paper easily enough but have a bit of a mental block in getting this into a language (I'd take any answer but Java probably easiest).
I have two sets of points Point A (xA, yA) and Point B (xB, yB).
Knowing this, and assuming that these two create a straight line graph I need to be able write a function that will give me xC given that I would know yC (and, obviously that the new point is on the same line).
All help appreciated :)
Kind Regards
回答1:
(yB-yA)/(xB-xA) = (yC - yA) / (xC-xA)
you just have to obtain xC now, that is
xC = xA + ((yC - yA) * (xB-xA) / (yB-yA))
This is, assuming that yB is different from yA . If they are equal, then you have not solutions if yC is different from yA, and infinite solutions ( every xC works) if yC=yA
来源:https://stackoverflow.com/questions/18771965/determining-a-straight-line-equation-from-2-cartesian-coordinates