0

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

Mark Taylor
  • 1,128
  • 8
  • 15
  • "I can do this on paper but not in Java" doesn't make much sense to me. If it were a hard algorithm, ok (or if you were having trouble because of integer division). But transforming an equation on paper to an equation in Java isn't that hard. – Teepeemm Sep 12 '13 at 18:58

1 Answers1

6
(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

Save
  • 11,450
  • 1
  • 18
  • 23