Domanda

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

È stato utile?

Soluzione

(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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top