dat<-read.csv(file="in.txt",header=F) end<-"end" a<-1 for (a in 1:length(dat$V1)){ lab<-dat[a:a,1:1] xc<-dat[a:a,2:2] yc<-dat[a:a,3:3] d<-16 r<-10 i<-1 fn=paste("out",a,".txt",sep="") beta=(360/d)/2 # calculate the degrees for half a slice for (i in 1:d ){ id<-paste(lab,i,sep="") theta=i*(beta*2) - beta # find the center of this slice #change degrees to radians dbeta=beta*0.017453292 # size of half slice - bc needs angle=theta*0.017453292 # center of slice - bc needs x1=xc y1=yc # intersction of tangent line and extended radius (lower) x2=x1 + r*sin(angle) +r*(sin(dbeta)/cos(dbeta))*sin(1.570796327 +angle) y2=y1 + r*cos(angle) +r*(sin(dbeta)/cos(dbeta))*cos(1.570796327 + angle) # intersction of tangent line and extended radius (upper) x3=x1 + r*sin(angle) + r*(sin(dbeta)/cos(dbeta))*sin(1.570796327 + 3.1415927 + angle) y3=y1 + r*cos(angle) + r*(sin(dbeta)/cos(dbeta))*cos(1.570796327 + 3.1415927 + angle) # create a text file that describes the triangle area for r.in.poly out1<-c(x1,y1) out1t<-t(out1) out2<-c(x2,y2) out2t<-t(out2) out3<-c(x3,y3) out3t<-t(out3) if (i==1){ write.table(id, file= fn,append=F, quote=F, sep=",",row.names=F,col.names=F) }else{ write.table(id, file= fn,append=T, quote=F, sep=",",row.names=F,col.names=F) } write.table(out1t, file= fn,append=T, quote=F, sep=",",row.names=F,col.names=F) write.table(out2t, file= fn,append=T, quote=F, sep=",",row.names=F,col.names=F) write.table(out3t, file= fn,append=T, quote=F, sep=",",row.names=F,col.names=F) write.table(end, file= fn,append=T, quote=F, sep=",",row.names=F,col.names=F) i<-i+1 } a<-a+1 }