4.8. 几何函数和操作符

有许多内置函数和操作符支持 几何类型 point,box,lseg,line,path,polygon 和 circle 等.

Table 4-15. 几何函数和操作符

操作符描述用法
+ 平移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))'
## 最近点point '(0,0)' ## lseg '((2,0),(0,2))'
&& 重叠?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 '((0,0),1)' << circle '((5,0),1)'
<^ 低于?circle '((0,0),1)' <^ circle '((0,5),1)'
>> 在右边?circle '((5,0),1)' >> circle '((0,0),1)'
>^ 高于?circle '((0,5),1)' >^ circle '((0,0),1)'
?# 相交或重叠?lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))';
?- 水平?point '(1,0)' ?- point '(0,0)'
?-| 垂直?lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))'
@-@ 长度或周长@-@ path '((0,0),(1,0))'
?| 竖直?point '(0,1)' ?| point '(0,0)'
?|| 平行?lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))'
@ 包含或在...上point '(1,1)' @ circle '((0,0),2)'
@@ ...的中心@@ circle '((0,0),10)'
~= 与...相同polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))'

Table 4-16. 几何函数

函数返回描述例子
area(object)double precision目标的面积area(box '((0,0),(1,1))')
box(box,box)box方的交box(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))')
pclose(path)path把路径转换为闭合popen(path '[(0,0),(1,1),(2,0)]')
npoint(path)integer点数npoints(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 4-17. 几何类型转换函数

函数返回描述例子
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转换成12点的多边形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))')