[R-sig-Geo] help to rotate around a centre a owin square
Rolf Turner
r.turner at auckland.ac.nz
Tue Apr 5 00:05:19 CEST 2011
On 05/04/11 02:37, gianni lavaredo wrote:
> Dear Reasearcher,
>
> I wish to rotate randomly a owin square aroud the centre of owin square. I
> try to use "rotate" in spatstat but it's not the function i need.
Actually "rotate" ***is*** the function you need, but you need to do a
little
bit more work. First *shift* the window you wish to rotate so that its
centroid is at the origin. Then rotate the result, and finally shift back
again.
This can all be bundled up in a simple function as follows:
foo <- function (W,angle=NULL) {
U <- shift(W,origin="centroid")
if(is.null(angle)) angle <- runif(1,-pi/2,pi/2)
U <- rotate(U,angle)
shift(U,vec=unlist(centroid.owin(W)))
}
Check:
SQ <- unit.square()
plot(owin(c(-1,2),c(-1,2)),main="")
plot(SQ,add=TRUE)
plot(foo(SQ),add=TRUE,border="red")
plot(foo(SQ,angle=-pi/3),add=TRUE,border="blue")
cheers,
Rolf Turner
More information about the R-sig-Geo
mailing list