[postgis-users] ST_RotateX with pointOrigin!

Stephen Mather stephen at smathermather.com
Sat Dec 14 17:37:20 PST 2013


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