9.9. 几何函数和操作符

有许多内置函数和操作符支持 几何类型pointboxlseglinepathpolygoncircle 等, 在Table 9-28Table 9-29,和 Table 9-30

Table 9-28. 几何函数和操作符

操作符描述例子
+平移box '((0,0),(1,1))' + point '(2.0,0)'
-平移box '((0,0),(1,1))' - point '(2.0,0)'
*伸缩/旋转box '((0,0),(1,1))' * point '(2.0,0)'
/伸缩/旋转box '((0,0),(2,2))' / point '(2.0,0)'
#交点或者交面'((1,-1),(-1,1))' # '((1,1),(-1,-1))'
#多边形顶点数# '((1,0),(0,1),(-1,0))'
@-@ 长度或者周长@-@ path '((0,0),(1,0))'
@@ 中心@@ circle '((0,0),10)'
##第一个操作数相对第二个操作数的最近点point '(0,0)' ## lseg '((2,0),(0,2))'
<-> 间距circle '((0,0),1)' <-> circle '((5,0),1)'
&&重叠?box '((0,0),(1,1))' && box '((0,0),(2,2))'
&<重叠或者在左边?box '((0,0),(1,1))' &< box '((0,0),(2,2))'
&>重叠或者在右边?box '((0,0),(3,3))' &> box '((0,0),(2,2))'
<<在左边?circle '((0,0),1)' << circle '((5,0),1)'
>> 在右边?circle '((5,0),1)' >> circle '((0,0),1)'
<^低于?circle '((0,0),1)' <^ circle '((0,5),1)'
>^高于?circle '((0,5),1)' >^ circle '((0,0),1)'
?#相交?lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))';
?-水平??- lseg '((-1,0),(1,0))'
?- 是水平对齐吗?point '(1,0)' ?- point '(0,0)'
?|竖直??| lseg '((-1,0),(1,0))'
?|竖直对齐吗?point '(0,1)' ?| point '(0,0)'
?-|垂直?lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))'
?||平行?lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))'
~ 包含?circle '((0,0),2)' ~ point '(1,1)'
@包含或在...上point '(1,1)' @ circle '((0,0),2)'
~=与...相同polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))'

Table 9-29. 几何函数

函数返回类型描述例子
area(object)double precision目标的面积area(box '((0,0),(1,1))')
box_intersect(box, box)box方的交box_intersect(box '((0,0),(1,1))',box '((0.5,0.5),(2,2))')
center(object)point对象中心center(box '((0,0),(1,2))')
diameter(circle)double precision圆直径diameter(circle '((0,0),2.0)')
height(box)double precision方的竖直高度height(box '((0,0),(1,1))')
isclosed(path)boolean是闭合路径吗?isclosed(path '((0,0),(1,1),(2,0))')
isopen(path)boolean是开环路径吗?isopen(path '[(0,0),(1,1),(2,0)]')
length(object)double precision长度length(path '((-1,0),(1,0))')
npoints(polygon)integer点数npoints(path '[(0,0),(1,1),(2,0)]')
npoints(polygon)integer点数npoints(polygon '((1,1),(0,0))')
pclose(path)path把路径转换为闭合popen(path '[(0,0),(1,1),(2,0)]')
popen(path)path把路径转换为开放的popen(path '((0,0),(1,1),(2,0))')
radius(circle)double precision圆半径radius(circle '((0,0),2.0)')
width(box)double precision方的水平尺寸width(box '((0,0),(1,1))')

Table 9-30. 几何类型转换函数

函数返回类型描述例子
box(circle)box将圆转换成长方形box(cricle '((0,0),2.0)')
box(point, point)box将点转换成长方形box(point '(0,0)', point '(1,1)')
box(polygon)box将多边形转换成长方形box(polygon '((0,0),(1,1),(2,0))')
circle(box)circle方转换成圆circle(box '((0,0),(1,1))')
circle(point, double precision)circle点和到圆的半径circle(point '(0,0)',2.0)
lseg(box)lseg长方形对角线转化成线段lseg(box '((-1,0),(1,0))')
lseg(point, point)lseg点转换成线段lseg(point '(-1,0)',point '(1,0)')
path(polygon)point多边形转换成路径path(polygon '((0,0),(1,1),(2,0))')
point(circle)point圆心point(circle '((0,0),2.0)')
point(lseg, lseg)point转换成点(相交)point(lseg '((-1,0),(1,0))', lseg '((-2,-2),(2,2))')
point(polygon)point多边形中心point(polygon '((0,0),(1,1),(2,0))')
polygon(box)polygon方形转换成4点多边形polygon(box '((0,0),(1,1))')
polygon(circle)polygon圆转换成12点多边形polygon(circle '((0,0),2.0)')
polygon(npts, circle)polygon圆转换成npts 点多边形polygon(12, circle '((0,0),2.0)')
polygon(path)polygon路径转换成多边形polygon(path '((0,0),(1,1),(2,0))')

我们可以把一个 point 的两个组成部分当作索引分别为 0 和 1 的数组元素进行访问。比如,如果 t.p 是一个 point 字段,那么 SELECT p[0] from t 检索 X 座标而 UPDATE t SET p[1] = ... 改变 Y 座标。同样, box 或者 lseg 的值可以当作两个 point 的数组看待。