## Name

ST_Affine — 对几何体应用 3D 仿射变换。

## Synopsis

`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`)`;

## 描述

`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```

`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 /
\ 0 0 0    1 /```

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

 在 1.3.4 之前，此函数在与包含曲线的几何图形一起使用时崩溃。 此问题已在 1.3.4 及更高版本中得到纠正

## 示例

```--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)
```