# 各頂点から最も近い分岐点を選んで結ぶモデル
rm(list=ls()) ; graphics.off()
# draw n-polygon
ngon <- function(n,print=TRUE,digit=TRUE,axis=FALSE,cex=1,...){
r=exp(2*pi/n*1i)
p=complex(n)
for(i in 1:(n+1)) p[i]= (1-r^i)/(1-r)
if(print){
plot(p,bty='l',type='l',axes=axis, ann=FALSE,asp=1,...)
points(1/(1-r),pch='.')
if(digit) text(Re(p),Im(p),paste('p',1:n),cex=cex)
if(axis){axis(1) ; axis(2)}}
invisible(p) # return vertex complex
}
# draw segment of complex a to complex b
seg <- function(a,b,...){
segments(Re(a),Im(a),Re(b),Im(b),col=2,...)
}
# draw text y at complex x
pt <- function(x,y=NULL,...){
text(Re(x),Im(x), ifelse(is.null(y),'+',y), ...)
}