I'm using PostgresSQL 9.5 to generate a rectangle (geometric type BOX). That works fine
SELECT Box(Point(-50, -100), Point(50, 100)) ; -- this works
Then I try to rotate that box around the origin (its center point). The rotation function is both
* Scaling/rotation box '((0,0),(1,1))' * point '(2.0,0)'
/ Scaling/rotation box '((0,0),(2,2))' / point '(2.0,0)'
where the x-point is the scaling factor (2.0 in this example) and the y-point is the rotation radians (0 in this example).
To check that the rotation is correct, I calculate the height, width and area of the box for each angle.
SELECT
xx.deg, -- angle in degrees
xx.geom, -- geometry of box
Area(xx.geom),
Center(xx.geom),
Height(xx.geom),
Width(xx.geom)
FROM
(SELECT deg,
Box(Point(-5, -10), Point(5, 10)) / Point(1, Radians(deg)) -- scale box by factor 1 and rotate by radians(degrees)
AS geom
FROM Generate_series(0, 360, 90) AS deg -- generate list of degrees from 0 to 360 by 90
) xx;
The results, which don't change between using *
or /
functions,
deg;geom;area;center;height;width
0;"(5,10),(-5,-10)";200;"(0,0)";20;10
90;"(5.97218570021291,0.618912639168559),(-5.97218570021291,-0.618912639168559)";14.785044853294;"(0,0)";1.23782527833712;11.9443714004258
180;"(3.35025316397424,0.525130727607429),(-3.35025316397424,-0.525130727607429)";7.03728352666753;"(0,0)";1.05026145521486;6.70050632794848
270;"(2.24607945852279,0.584400089411209),(-2.24607945852279,-0.584400089411209)";5.25043614554159;"(0,0)";1.16880017882242;4.49215891704558
360;"(1.67575357650576,0.529070250354662),(-1.67575357650576,-0.529070250354662)";3.5463654570185;"(0,0)";1.05814050070932;3.35150715301153
show that the box is being rotated but also scaled - the height, width and area are all not constant. I read somewhere that a rotation needs to take into account scaling, but I don't understand what scaling factor should be used to compsenate for the rotation. The documentation doesn't give any examples, and most of the resources online are for PostGIS (i.e. ST_Rotate).
UPDATE
I have a working solution that is not the fastest but gives correct results. See here