Purpose: Given the two points, find the coordinates of the arc that connects them, and build it. Implementation: One function for finding arc points ( circleFun ) and another for constructing it ( plottest ). Colors indicate the direction of the path, from red to green.
circleFun <- function(x,y) { center <- c((x[1]+y[1])/2,(x[2]+y[2])/2) diameter <- as.numeric(dist(rbind(x,y))) r <- diameter / 2 tt <- seq(0,2*pi,length.out=1000) xx <- center[1] + r * cos(tt) yy <- center[2] + r * sin(tt) res <- data.frame(x = xx, y = yy) if((x[1]<y[1] & x[2]>y[2]) | (x[1]>y[1] & x[2]<y[2])){ res <- res[which(res$x>min(c(x[1],y[1])) & res$y>min(c(x[2],y[2]))),] } else { res <- res[which(res$x<max(c(x[1],y[1])) & res$y>min(c(x[2],y[2]))),] } return(res) } plottest <- function(x1,y1) { plot(c(x1[1],y1[1]),c(x1[2],y1[2]), xlim=c(-2,2),ylim=c(-2,2),col=2:3,pch=20,cex=2,asp=1) lines(circleFun(x1,y1)) } par(mfrow=c(2,2)) plottest(c( 1,-1),c(-1, 1)) plottest(c(-1, 1),c( 1,-1)) plottest(c(-1,-1),c( 1, 1)) plottest(c( 1, 1),c(-1,-1))
Result:

Question: I cannot understand why the lines function closes the path in figures [1,1] and [1,2], while this is not for figures [2,1] and [2,2]. The expected result should be all the figures, as in the second row.
Thanks!