Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
For the figure below [not the original one!], describing two (blue) half-circles intersecting with a square of side 20cm, and a (orange) quarter of a circle with radius 20cm, find the radii of both gold circles, respectively tangent to both half-circles and to the square and going through the three intersections.
diaz=sqrt(2)*20 for (diz in seq(5/8,7/8,le=1e4)*diaz){#position of O radi=sqrt(diz^2/2+(diz/sqrt(2)-10)^2)-10 if (abs(20-(diz/sqrt(2))-radi)<3e-3){ print(c(radi,diz));break()}}
In the case of the second circle I first deduced the intersections of the different circles by sheer comparison of black (blue!) pixels, namely A(4,8), B(8,4), and C(10,10), then looked at the position of the centre O’ of the circle such that the distances to A, B, and C were all equal:
for (diz in seq(20*sqrt(2)-20,10*sqrt(2),le=1e4)){ radi=10*sqrt(2)-diz distA=sqrt((diz/sqrt(2)-4)^2+(diz/sqrt(2)-8)^2) if (abs(distA-radi)<4e-4){ print(c(radi,diz));break()}}
even though Heron’s formula was enough to produce the radius. In both approaches, this radius is 3.54, with the position of the centre O’at 10.6 from the lower left corner. When plotting these results, which showed consistency at this level of precision, I was reminded of the importance of plotting the points with the option “asp=1” in plot() as otherwise, draw.circle() does not plot the circles at the right location!
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.