Re: [R] x, y for point of intersection

2011-12-01 Thread Monica Pisica

Hi everybody,

Thanks for checking my code, Hans, it help to see where my initial mistake was. 
I am sorry i assumed that there was a minimization problem. 

In short i had 2 "wavy" lines (left and right) that didn't intersect and lots 
of straight parallel lines that intersect the first 2 lines. I wanted to solve 
the intersection for the left and right line simultaneously and put everything 
in a big loop. And there the mistake was.

Meanwhile i was able to use Don suggestion with no problem and no loop.

Thanks again,

Monica

> Date: Thu, 1 Dec 2011 12:13:49 +0100
> Subject: Re: [R] x, y for point of intersection
> From: hwborch...@googlemail.com
> To: r-help@r-project.org
> CC: macque...@llnl.gov; pisican...@hotmail.com; dwinsem...@comcast.net; 
> ted.hard...@wlandres.net
> 
> Monica has sent me some data and code for taking a quick look. As it
> turned out, there was a simple programming error on her side. The
> segm_distance() function in package 'pracma' is working correctly. And
> there is no minimization procedure in here, it simply solves some
> equations from plane geometry.
> 
> Maybe the function suggested by Don is faster, I haven't checked that.
> 
> Regards,  Hans Werner
> 
> 
> 2011/11/29 Monica Pisica 
> >
> > Hi again,
> >
> > Working with my real data and not with the little example i sent to the 
> > list i discovered that segm_distance function from package "pracma" does 
> > not converge to 0 in all cases, even if i increase the number of iteration 
> > to 10,000 for example. It seems that it depends on the "initialization" 
> > point - most like a minimization function.
> >
> > So my thanks  go to Don who's suggestion works for the real data as well 
> > without any problems - so far ;-) He suggested to use the function 
> > crossing.psp from package "spatstat".
> >
> > Thanks again to all who have answered and helped to solve my problem. I 
> > certainly learned few new things.
> >
> > Monica
> >
> >
> >
> >
> >
> > > From: macque...@llnl.gov
> > > To: pisican...@hotmail.com
> > > CC: r-help@r-project.org
> > > Date: Wed, 23 Nov 2011 14:03:42 -0800
> >
> > > Subject: Re: [R] x, y for point of intersection
> > >
> > > The function crossing.psp() in the spatstat package might be of use.
> > > Here's an excerpt from its help page:
> > >
> > > crossing.psp package:spatstat R Documentation
> > > Crossing Points of Two Line Segment PatternsDescription:
> > > Finds any crossing points between two line segment patterns.
> > > Usage:
> > > crossing.psp(A,B)
> > > -Don
> > >
> > >
> > > --
> > > Don MacQueen
> > >
> > > Lawrence Livermore National Laboratory
> > > 7000 East Ave., L-627
> > > Livermore, CA 94550
> > > 925-423-1062
> > >
> >
  
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] x, y for point of intersection

2011-12-01 Thread Hans W Borchers
Monica has sent me some data and code for taking a quick look. As it
turned out, there was a simple programming error on her side. The
segm_distance() function in package 'pracma' is working correctly. And
there is no minimization procedure in here, it simply solves some
equations from plane geometry.

Maybe the function suggested by Don is faster, I haven't checked that.

Regards,  Hans Werner


2011/11/29 Monica Pisica 
>
> Hi again,
>
> Working with my real data and not with the little example i sent to the list 
> i discovered that segm_distance function from package "pracma" does not 
> converge to 0 in all cases, even if i increase the number of iteration to 
> 10,000 for example. It seems that it depends on the "initialization" point - 
> most like a minimization function.
>
> So my thanks  go to Don who's suggestion works for the real data as well 
> without any problems - so far ;-) He suggested to use the function 
> crossing.psp from package "spatstat".
>
> Thanks again to all who have answered and helped to solve my problem. I 
> certainly learned few new things.
>
> Monica
>
>
>
>
>
> > From: macque...@llnl.gov
> > To: pisican...@hotmail.com
> > CC: r-help@r-project.org
> > Date: Wed, 23 Nov 2011 14:03:42 -0800
>
> > Subject: Re: [R] x, y for point of intersection
> >
> > The function crossing.psp() in the spatstat package might be of use.
> > Here's an excerpt from its help page:
> >
> > crossing.psp package:spatstat R Documentation
> > Crossing Points of Two Line Segment PatternsDescription:
> > Finds any crossing points between two line segment patterns.
> > Usage:
> > crossing.psp(A,B)
> > -Don
> >
> >
> > --
> > Don MacQueen
> >
> > Lawrence Livermore National Laboratory
> > 7000 East Ave., L-627
> > Livermore, CA 94550
> > 925-423-1062
> >
>

__
R-help@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.


Re: [R] x, y for point of intersection

2011-11-29 Thread Monica Pisica

Hi again,

Working with my real data and not with the little example i sent to the list i 
discovered that segm_distance function from package "pracma" does not converge 
to 0 in all cases, even if i increase the number of iteration to 10,000 for 
example. It seems that it depends on the "initialization" point - most like a 
minimization function. 

So my thanks  go to Don who's suggestion works for the real data as well 
without any problems - so far ;-) He suggested to use the function crossing.psp 
from package "spatstat".

Thanks again to all who have answered and helped to solve my problem. I 
certainly learned few new things.

Monica

 



> From: macque...@llnl.gov
> To: pisican...@hotmail.com
> CC: r-help@r-project.org
> Date: Wed, 23 Nov 2011 14:03:42 -0800
> Subject: Re: [R] x, y for point of intersection
> 
> The function crossing.psp() in the spatstat package might be of use.
> Here's an excerpt from its help page:
> 
> crossing.psp package:spatstat  R Documentation
> Crossing Points of Two Line Segment PatternsDescription:
> Finds any crossing points between two line segment patterns.
> Usage:
> crossing.psp(A,B)
> -Don
> 
> 
> -- 
> Don MacQueen
> 
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> 
> 
> 
> 
> 
> On 11/22/11 12:48 PM, "R. Michael Weylandt "
>  wrote:
> 
> >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  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@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.
> >
> >__
> >R-help@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.
> 
  
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] x, y for point of intersection

2011-11-23 Thread MacQueen, Don
The function crossing.psp() in the spatstat package might be of use.
Here's an excerpt from its help page:

crossing.psp package:spatstat  R Documentation
Crossing Points of Two Line Segment PatternsDescription:
Finds any crossing points between two line segment patterns.
Usage:
crossing.psp(A,B)
-Don


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 11/22/11 12:48 PM, "R. Michael Weylandt "
 wrote:

>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  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@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.
>
>__
>R-help@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.

__
R-help@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.


[R] x, y for point of intersection

2011-11-23 Thread Monica Pisica

Hi everybody,

Thank you so much for your answers. The easiest and most straight forward 
solution is using the function segm_dist from package "pracma" as suggested by 
Hans Borchers. 

Thanks again and Happy Thanksgiving for those who celebrate!

Monica



Message: 99

Date: Wed, 23 Nov 2011 08:11:22 +

From: Hans W Borchers 

To: 

Subject: Re: [R] x, y for point of intersection

Message-ID: 

Content-Type: text/plain; charset="utf-8"



Monica Pisica  hotmail.com> writes:



> 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")



xa <- -5; ya <- 2

xb <- 12; yb <- 4



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.



You could apply the function segm_distance in package 'pracma'. If the 

distance between two segments is 0, it returns the intersection point:



p1 <- c(xa, ya); p2 <- c(xb, yb)

for (i in 2:100) {

p3 <- c(k1[i-1], q1[i-1]); p4 <- c(k1[i], q1[i])

s <- segm_distance(p1, p2, p3, p4)

if (s$d == 0) break

}

s$p # 0.2740154 2.6204724

points(s$p[1], s$p[2], pch="+", col="red")



> Thanks,

> Monica

>


  
__
R-help@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.


Re: [R] x, y for point of intersection

2011-11-23 Thread Hans W Borchers
Monica Pisica  hotmail.com> writes:

> 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")

xa <- -5; ya <- 2
xb <- 12; yb <- 4

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.

You could apply the function segm_distance in package 'pracma'. If the 
distance between two segments is 0, it returns the intersection point:

p1 <- c(xa, ya); p2 <- c(xb, yb)
for (i in 2:100) {
p3 <- c(k1[i-1], q1[i-1]); p4 <- c(k1[i], q1[i])
s <- segm_distance(p1, p2, p3, p4)
if (s$d == 0) break
}
s$p  # 0.2740154 2.6204724
points(s$p[1], s$p[2], pch="+", col="red")

> Thanks,
> Monica
>

__
R-help@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.


Re: [R] x, y for point of intersection

2011-11-22 Thread Ted Harding
On 22-Nov-11 21:25:56, Monica Pisica 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

  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) 
Fax-to-email: +44 (0)870 094 0861
Date: 22-Nov-11   Time: 22:49:54
-- XFMail --

__
R-help@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.


Re: [R] x, y for point of intersection

2011-11-22 Thread David Winsemius


On Nov 22, 2011, at 3:40 PM, Monica Pisica wrote:


(edited out excessive white space)
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)



You should look at:
str(ln)
#  then plot
lines(ln$x, ln$fitted, col="blue")
plot(approxfun(c(xa, xb), c(ya, yb)), add=TRUE, col="green")
plot(approxfun(ln$x, ln$fitted), col="orange", add=TRUE)

And think about minimizing the difference in distances between two  
functions.





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@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] x, y for point of intersection

2011-11-22 Thread Monica Pisica

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@r-project.org
> From: michael.weyla...@gmail.com
> Subject: Re: [R] x, y for point of intersection
> Date: Tue, 22 Nov 2011 15:48:34 -0500
> To: pisican...@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  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@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.
  
__
R-help@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.


Re: [R] x, y for point of intersection

2011-11-22 Thread R. Michael Weylandt
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  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@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.

__
R-help@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.


[R] x, y for point of intersection

2011-11-22 Thread Monica Pisica



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@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.