Dear R users, I am thinking about an easy and especially fast solution to calculate the x,y coordinates of the interesection between the borders of the red circle and the line. short example: plot(c(-3,0,3,9,21),c(-8,0,5,12,25)) draw.circle(0,0,radius=6,border="red",col=NA,lty=1,lwd=1) x <- c(-12,-6,-1,0,13,21) y <- c(-19,-10,-5,0,9,25) plot(x,y) require(plotrix) draw.circle(0,0,radius=6,border="red",col=NA,lty=1,lwd=1) lines(c(-12,-6,-1,13,21),c(-19,-10,-5,9,25),cex=2) At the moment I am interpolating the points which gives the basis coordinates of the line. I do this with approx() and then I check which point is within the circle and which one is not. The probleme is, that this method is not really exact and for my dataset it takes too much time. Thanks. With best regards -- View this message in context: http://r.789695.n4.nabble.com/Intersection-between-circle-and-line-tp3844063p3844063.html Sent from the R help mailing list archive at Nabble.com.
Intersection between circle and line?
3 messages · David Winsemius, Chris82
On Sep 26, 2011, at 11:03 AM, Chris82 wrote:
Dear R users, I am thinking about an easy and especially fast solution to calculate the x,y coordinates of the interesection between the borders of the red circle and the line.
This would seem to be the solution to two simultaneous equations : one a quadratic and the other linear. I suspect tenth-grade algebra would be the level; Looking for something to minimize the mental strain also succeeds easily. Googling on "intersection of line and circle" produces this analytic approach (and there are many other webpages.) http://mathworld.wolfram.com/Circle-LineIntersection.html
> > plot(c(-3,0,3,9,21),c(-8,0,5,12,25)) > draw.circle(0,0,radius=6,border="red",col=NA,lty=1,lwd=1) > x <- c(-12,-6,-1,0,13,21) > y <- c(-19,-10,-5,0,9,25) > plot(x,y) > require(plotrix) > draw.circle(0,0,radius=6,border="red",col=NA,lty=1,lwd=1) > lines(c(-12,-6,-1,13,21),c(-19,-10,-5,9,25),cex=2) > > > At the moment I am interpolating the points which gives the basis > coordinates of the line. I do this with approx() and then I check > which > point is within the circle and which one is not. The probleme is, > that this > method is not really exact and for my dataset it takes too much time. > > > Thanks. > > With best regards > > -- > View this message in context: http://r.789695.n4.nabble.com/Intersection-between-circle-and-line-tp3844063p3844063.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. David Winsemius, MD West Hartford, CT
Thanks! In principle it is a mathematical problem. I have already found some solutions with google. I thought there is maybe an existing R function or package which handel this stuff. But it seems not to be. sos package gives me no suitable information for that. With best regards -- View this message in context: http://r.789695.n4.nabble.com/Intersection-between-circle-and-line-tp3844063p3846846.html Sent from the R help mailing list archive at Nabble.com.