Skip to content
Prev 278226 / 398503 Next

x, y for point of intersection

On 22-Nov-11 21:25:56, Monica Pisica wrote:
.. and get the x and y
ya <- 2
  xa = -5
  yb =  4
  xb = 12

These define a line

  y = ya + (x - xa)*(yb - ya)/(xb - xa)

so write this as

  y = A + B*x

Then points above the line satisfy

  y > A + B*X

and points below the line satisfy

  Y < A + B*X

  A <- ya - xa*(yb - ya)/(xb - xa)
  B <- (yb - ya)/(xb - xa)

So now extract the points (x,y) fron the loess fit:

  x.ln <- ln$x
  y.ln <- ln$y

and now find the points on 'ln' which are above, and
the points on ln which are below, which will locate the
segment which crosses the (X,Y) line:

  ix.upper <- which(y.ln >  A + B*ln$y)
  ix.lower <- which(y.ln <=3D A + B*ln$y)

  ix.upper
  # 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15=20

So now you have the line segment from

  (x.ln[15],y.ln[15])
to
  (x.ln[16],y.ln[16])

and now all you need to do is to find the intersection
of the line from (ln.x[15],ln.y[15]) to (ln.x[16],ln.y[16])
with the line from (xa,ya) to (xb,yb).

(There could be complications if the y-values of ln do not
continually decrease in value; but happily they do decrease
in your example).

Hoping this helps!
Ted.



--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 22-Nov-11                                       Time: 22:49:54
------------------------------ XFMail ------------------------------