[R] x, y for point of intersection
Monica Pisica
pisicandru at hotmail.com
Tue Nov 22 22:28:25 CET 2011
Hi,
No it is not one off, the situation is even more complicated .... i will have a series of straight lines like the red one parallel with each other that intersect the black polyline and i need to get all the points (x, y).
Meanwhile i was thinking if it will not be easier if somehow i can rotate the coordinate axes so the red lines are horizontal (of course the polyline needs to be rotated as well) and maybe knowing the distance between the red parallel lines and the fact that now they are horizontal will help. I need to think a little bit more about that - and of course afterwards the results need to be translated back to the original coordinate system.
Thanks,
Monica
----------------------------------------
> CC: r-help at r-project.org
> From: michael.weylandt at gmail.com
> Subject: Re: [R] x, y for point of intersection
> Date: Tue, 22 Nov 2011 15:48:34 -0500
> To: pisicandru at hotmail.com
>
> If it's a one off, the identify() function might be of help -- if you need something algorithmic it's harder due to floating point stuff and sampling frequencies. Let me know if that's the case.
>
> Michael
>
> On Nov 22, 2011, at 3:40 PM, Monica Pisica <pisicandru at hotmail.com> wrote:
>
> >
> >
> >
> > Hi everyone,
> >
> >
> >
> > I am trying to get a point of intersection between a
> > polyline and a straight line ….. and get the x and y coordinates of this point.
> > For exemplification consider this:
> >
> >
> >
> >
> >
> > set.seed(123)
> >
> >
> >
> > k1 <-rnorm(100, mean=1.77, sd=3.33)
> >
> > k1 <- sort(k1)
> >
> > q1 <- rnorm(100, mean=2.37, sd=0.74)
> >
> > q1 <- sort(q1, decreasing = TRUE)
> >
> > plot(k1, q1, xlim <- c((min(k1)-5), (max(k1)+5)),
> > type="l")
> >
> >
> >
> > ya <- 2
> >
> > xa = -5
> >
> > yb=4
> >
> > xb=12
> >
> >
> >
> > lines(c(xa, xb), c(ya, yb), col = 2)
> >
> >
> >
> > # I want to get the x and y coordinates of the
> > intersection of the 2 lines ….
> >
> >
> >
> > m <- (ya-yb)/(xa-xb)
> >
> > b <- ya-m*xa
> >
> > ln <- loess(q1~k1)
> >
> > lines(ln)
> >
> >
> >
> > It is clear that the x, y will satisfy both linear
> > equations, y = m*x + b and the ln polyline ….. but while I can visualize the
> > equation of the straight line – I have problems with the polyline. I will appreciate
> > any ideas to solve this problem. I thought it a trivial solution but it seems I
> > cannot see it.
> > Thanks,
> > Monica
> >
> >
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list