[postgis-users] ST_RotateX with pointOrigin!

Stephen Mather stephen at smathermather.com
Sat Dec 14 19:57:13 PST 2013


Ahem-- bugs fixed:

-- Function: st_rotatex(geometry, double precision, geometry)
CREATE OR REPLACE FUNCTION ST_RotateX(geomA geometry, rotRadians
double precision, pointOrigin geometry)
  RETURNS geometry AS
$BODY$

----- Transform geometry to nullsville (0,0,0) so rotRadians will take
place around the pointOrigin
WITH transformed AS (
    SELECT ST_Translate(geomA, -1 * ST_X(pointOrigin), -1 *
ST_Y(pointOrigin), -1 * ST_Z(pointOrigin)) AS the_geom
    ),
----- Rotate in place
rotated AS (
    SELECT ST_RotateX(the_geom, rotRadians) AS the_geom FROM transformed
    ),
----- Translate back home
rotTrans AS (
    SELECT ST_Translate(the_geom, ST_X(pointOrigin),
ST_Y(pointOrigin), ST_Z(pointOrigin)) AS the_geom
    FROM rotated
    )
----- profit
SELECT the_geom from rotTrans

;

$BODY$
  LANGUAGE sql VOLATILE
  COST 100;


On Sat, Dec 14, 2013 at 8:37 PM, Stephen Mather
<stephen at smathermather.com> wrote:
> Hi All,
>
> I think I avoided doing linear algebra, which is good since I never
> studied it... .
>
> This is my cludgy patch for making a version of
>
> geometry ST_RotateX(geometry geomA, float rotRadians, geometry pointOrigin)
>
> It's not pretty enough to be a real patch ('cause my brain couldn't do
> that whole linear algebra thing, and hence why it's here and not the
> developers list), but thought I'd share it anyway and get impressions,
> and have some brighter minds make sure I don't have some major logic
> failure here:
>
> -------
>
> DROP FUNCTION st_rotatex(geometry,double precision,geometry);
>
> CREATE OR REPLACE FUNCTION ST_RotateX(geomA geometry, rotRadians
> double precision, pointOrigin geometry)
>   RETURNS geometry AS
> $BODY$
>
> ----- Transform geometry to nullsville (0,0,0) so rotRadians will take
> place around the pointOrigin
> WITH transformed AS (
>     SELECT ST_Translate(geomA, -1 * ST_X(pointOrigin), -1 *
> ST_Y(pointOrigin), -1 * ST_Z(pointOrigin)) AS the_geom
>     ),
> ----- Rotate in place
> rotated AS (
>     SELECT ST_RotateX(the_geom, rotRadians) FROM transformed
>     ),
> ----- Translate back home
> rotTrans AS (
>     SELECT ST_Translate(geomA, ST_X(pointOrigin), ST_Y(pointOrigin),
> ST_Z(pointOrigin)) AS the_geom
>     )
> ----- profit
> SELECT the_geom from rotTrans
>
> ;
>
> $BODY$
>   LANGUAGE sql VOLATILE
>   COST 100;


More information about the postgis-users mailing list