名稱

ST_Affine — 對幾何圖形套用 3D 仿射轉換。

概要

geometry ST_Affine(geometry geomA, float a, float b, float c, float d, float e, float f, float g, float h, float i, float xoff, float yoff, float zoff);

geometry ST_Affine(geometry geomA, float a, float b, float d, float e, float xoff, float yoff);

描述

對幾何圖形套用 3D 仿射轉換,以執行如平移、旋轉、縮放等操作,一步到位。

版本 1:呼叫

ST_Affine(geom, a, b, c, d, e, f, g, h, i, xoff, yoff, zoff) 

代表轉換矩陣

/ a  b  c  xoff \
| d  e  f  yoff |
| g  h  i  zoff |
\ 0  0  0     1 /

且頂點轉換方式如下

x' = a*x + b*y + c*z + xoff
y' = d*x + e*y + f*z + yoff
z' = g*x + h*y + i*z + zoff

以下所有平移/縮放函數都透過此類仿射轉換表示。

版本 2:對幾何圖形套用 2D 仿射轉換。呼叫方式為

ST_Affine(geom, a, b, d, e, xoff, yoff)

代表轉換矩陣

/  a  b  0  xoff  \       /  a  b  xoff  \
|  d  e  0  yoff  | rsp.  |  d  e  yoff  |
|  0  0  1     0  |       \  0  0     1  /
\  0  0  0     1  /

且頂點轉換方式如下

x' = a*x + b*y + xoff
y' = d*x + e*y + yoff
z' = z 

此方法是上述 3D 方法的子案例。

增強功能:2.0.0 版本引入了對多面體表面、三角形和 TIN 的支援。

可用性:1.1.2 版本。名稱在 1.2.2 版本從 Affine 變更為 ST_Affine。

[Note]

在 1.3.4 版本之前,若與包含 CURVES 的幾何圖形一起使用,此函數會崩潰。此問題已在 1.3.4+ 版本中修復。

此函數支援多面體表面。

此函數支援三角形和三角不規則網路表面 (TIN)。

此函數支援 3D,且不會捨棄 z 軸索引。

此方法支援圓形字串和曲線。

範例

--Rotate a 3d line 180 degrees about the z axis.  Note this is long-hand for doing ST_Rotate();
 SELECT ST_AsEWKT(ST_Affine(geom,  cos(pi()), -sin(pi()), 0,  sin(pi()), cos(pi()), 0,  0, 0, 1,  0, 0, 0)) As using_affine,
	 ST_AsEWKT(ST_Rotate(geom, pi())) As using_rotate
	FROM (SELECT ST_GeomFromEWKT('LINESTRING(1 2 3, 1 4 3)') As geom) As foo;
        using_affine         |        using_rotate
-----------------------------+-----------------------------
 LINESTRING(-1 -2 3,-1 -4 3) | LINESTRING(-1 -2 3,-1 -4 3)
(1 row)

--Rotate a 3d line 180 degrees in both the x and z axis
SELECT ST_AsEWKT(ST_Affine(geom, cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), 0, 0, 0))
	FROM (SELECT ST_GeomFromEWKT('LINESTRING(1 2 3, 1 4 3)') As geom) As foo;
           st_asewkt
-------------------------------
 LINESTRING(-1 -2 -3,-1 -4 -3)
(1 row)