PostgreSQL - Rotate geometric type giving unexpected results
<p>I'm using PostgresSQL 9.5 to generate a rectangle (<a href="https://www.postgresql.org/docs/9.5/static/datatype-geometric.html" rel="nofollow noreferrer">geometric type</a> BOX).
That works fine</p>

<pre><code>SELECT Box(Point(-50, -100), Point(50, 100)) ; -- this works
</code></pre>

<p>Then I try to rotate that box around the origin (its center point). The <a href="https://www.postgresql.org/docs/9.5/static/functions-geometry.html" rel="nofollow noreferrer">rotation function</a> is both</p>

<pre><code>*   Scaling/rotation    box '((0,0),(1,1))' * point '(2.0,0)'
/   Scaling/rotation    box '((0,0),(2,2))' / point '(2.0,0)'
</code></pre>

<p>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).</p>

<p>To check that the rotation is correct, I calculate the height, width and area of the box for each angle.</p>

<pre><code> 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;  
</code></pre>

<p>The results, which don't change between using <code>*</code> or <code>/</code> functions,</p>

<pre><code>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
</code></pre>

<p>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).</p>

<hr>

<p><strong>UPDATE</strong></p>

<p>I have a working solution that is not the fastest but gives correct results. See here</p>

<p><a href="https://stackoverflow.com/a/39680955/2327328">https://stackoverflow.com/a/39680955/2327328</a></p>