Determining a straight line equation from 2 cartesian coordinates

早过忘川 提交于 2021-02-11 14:26:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!