Here's some R code that does the job, the caveat being we are in cartesian coordinates. The input matrix coords
is a 5x2 matrix of x,y columns, with the last point being coincident with the first point. This is what you get out of spatial objects in R when you read a shapefile, for example.
thinrect <- function(coords, factor=1/3){
dx = diff(coords[,1])
dy = diff(coords[,2])
## test if slope(1-2) is > slope(2-3)
w = diff(atan2(abs(dx[1:2]), abs(dy[1:2])) %% pi) > 0
## if it is, then wrap it round so the first side is the steepest
if(w){
coords = rbind(coords[-1,], coords[1,])
dx = c(dx[-1],dx[1])
dy = c(dy[-1],dy[1])
}
## now its just four points offset from corners 1 and 3
dxy = c(dx[1],dy[1])
p1 = coords[1,] + factor*dxy
p2 = coords[1,] + (0.5+factor/2)*dxy
p3 = coords[3,] - (factor)*dxy
p4 = coords[3,] - (0.5+factor/2)*dxy
rbind(p1, p2, p3, p4, p1)
}
Here's the output on a rectangle under various rotations. Note how the selected rectangle changes to stay parallel to the steepest side.
Simple usage, creating a 5x2 matrix of a unit square:
> coords=matrix(c(0,0,0,1,1,1,1,0,0,0),ncol=2,byrow=TRUE)
> coords
[,1] [,2]
[1,] 0 0
[2,] 0 1
[3,] 1 1
[4,] 1 0
[5,] 0 0
> thinrect(coords)
[,1] [,2]
p1 0.3333333 1
p2 0.6666667 1
p3 0.6666667 0
p4 0.3333333 0
p1 0.3333333 1
> plot(coords)
> polygon(thinrect(coords))
Looping this over a shapefile is pretty trivial.
The algorithm could be ported to Python pretty simply too.