Skip to content
Prev 363155 / 398502 Next

only plot borders of a region in a scatter plot

Hi Zun Yin,
The first problem requires something like this:

pixel8<-function(x,y,pixsize=1) {
 nsteps<-length(x)-1
 newx<-x[1]
 newy<-y[1]
 for(i in 1:nsteps) {
  dx<-diff(x[i:(i+1)])
  dy<-diff(y[i:(i+1)])
  if(dx && dy) {
   newx<-c(newx,x[i]+dx,x[i]+dx)
   newy<-c(newy,y[i],y[i]+dy)
  }
  else {
   newx<-c(newx,x[i+1])
   newy<-c(newy,y[i+1])
  }
 }
 return(list(x=newx,y=newy))
}

I think that this does part of what you want. Your points seem to be
in the middle of a pixel edge, so an offset would have to be added to
align the resulting points with the corners. The other thing to work
out is the order of changing x and y on a slope, which I think is a
function of whether the line is "inside" or "outside" the overall area
enclosed. I'll post again if I have any brilliant ideas.

Jim
On Fri, Aug 5, 2016 at 6:08 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote: