[R] Intersection between circle and line?

David Winsemius dwinsemius at comcast.net
Mon Sep 26 17:40:44 CEST 2011


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



More information about the R-help mailing list