Morphing circles to annulus using transformr

24 Views Asked by At

I am trying to morph circles to annulus using the transformr package in R following the code given here, namely (this code should work as copy-paste in your RStudio):

library(transformr)
library(ggplot2)
library(spatstat)

# Define circles
circles <- poly_circles()

# Define annulus
big_circle <- disc(1, c(0,0))
small_circle <- disc(0.5, c(0,0))
circle_with_hole <- setminus.owin(big_circle, small_circle)

df1 <- data.frame(x = circle_with_hole$bdry[[1]]$x, y = circle_with_hole$bdry[[1]]$y)
df2 <- data.frame(x = circle_with_hole$bdry[[2]]$x, y = circle_with_hole$bdry[[2]]$y)
df <- rbind(df1, df2)
id <- data.frame(id = rep(1, dim(df)[1]))

annulus <- cbind(df, id)

# Do the morphing
morph <- tween_polygon(circles, annulus, 
                       ease = 'linear',
                       id = id, 
                       nframes = 12,
                       match = FALSE)
ggplot(morph) + 
  geom_polygon(aes(x = x, y = y, group = id), fill = NA, colour = 'black') + 
  facet_wrap(~.frame, labeller = label_both, ncol = 3) + 
  theme_void()

However, you can see the end result has a bit of wedge:

enter image description here

even when the original annulus doesn't have it.

ggplot(df, aes(x=x, y=y)) + geom_point()

enter image description here

How to get rid of this wedge? Thanks!

0

There are 0 best solutions below