DarianFlorianVoda / BioShapes

Bachelor Thesis R Package
0 stars 0 forks source link

Graphic.Objects: Circles around another Circle #17

Closed discoleo closed 2 years ago

discoleo commented 2 years ago

Helper function to compute the centers of n tangent circles which form a closed circle.

# Tangent circles forming a large circle
circlesOnCircle = function(n, r, center = c(0,0), phi=0) {
    R  = r / sin(pi/n);
    xy = pointsCircle(n, r=R, center=center, phi=phi);
    attr(xy, "R") = R;
    return(xy);
}

Example

n = 15
r = 1
phi = pi / n; # add some rotation
xy = circlesOnCircle(n, r, phi=phi);
x = xy$x; y = xy$y;
R = attr(xy, "R");
d = R + r + 1;
plot(x, y, xlim=c(-d, d), ylim=c(-d, d))
par.old = par(pin = c(4.8, 4.8))
for(id in seq(n)) {
  filledcircle(r1=r, r2=0, mid = c(x[id], y[id]))
}
par(par.old)
DarianFlorianVoda commented 2 years ago

Added. Added also a test file for the examples and tests (temporary, will add the examples also in the examples file). image