6.9. Geometric Functions and Operators

The geometric types point, box, lseg, line, path, polygon, and circle have a large set of native support functions and operators, shown in Table 6-20, Table 6-21, and Table 6-22.

Table 6-20. Geometric Operators

OperatorDescriptionUsage
+ Translationbox '((0,0),(1,1))' + point '(2.0,0)'
- Translationbox '((0,0),(1,1))' - point '(2.0,0)'
* Scaling/rotationbox '((0,0),(1,1))' * point '(2.0,0)'
/ Scaling/rotationbox '((0,0),(2,2))' / point '(2.0,0)'
# Intersection'((1,-1),(-1,1))' # '((1,1),(-1,-1))'
# Number of points in path or polygon# '((1,0),(0,1),(-1,0))'
## Point of closest proximitypoint '(0,0)' ## lseg '((2,0),(0,2))'
&& Overlaps?box '((0,0),(1,1))' && box '((0,0),(2,2))'
&< Overlaps to left?box '((0,0),(1,1))' &< box '((0,0),(2,2))'
&> Overlaps to right?box '((0,0),(3,3))' &> box '((0,0),(2,2))'
<-> Distance betweencircle '((0,0),1)' <-> circle '((5,0),1)'
<< Left of?circle '((0,0),1)' << circle '((5,0),1)'
<^ Is below?circle '((0,0),1)' <^ circle '((0,5),1)'
>> Is right of?circle '((5,0),1)' >> circle '((0,0),1)'
>^ Is above?circle '((0,5),1)' >^ circle '((0,0),1)'
?# Intersects or overlapslseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))'
?- Is horizontal?point '(1,0)' ?- point '(0,0)'
?-| Is perpendicular?lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))'
@-@ Length or circumference@-@ path '((0,0),(1,0))'
?| Is vertical?point '(0,1)' ?| point '(0,0)'
?|| Is parallel?lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))'
@ Contained or onpoint '(1,1)' @ circle '((0,0),2)'
@@ Center of@@ circle '((0,0),10)'
~= Same aspolygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))'

Table 6-21. Geometric Functions

FunctionReturnsDescriptionExample
area(object)double precisionarea of itemarea(box '((0,0),(1,1))')
box(box, box)boxintersection boxbox(box '((0,0),(1,1))',box '((0.5,0.5),(2,2))')
center(object)pointcenter of itemcenter(box '((0,0),(1,2))')
diameter(circle)double precisiondiameter of circlediameter(circle '((0,0),2.0)')
height(box)double precisionvertical size of boxheight(box '((0,0),(1,1))')
isclosed(path)booleana closed path?isclosed(path '((0,0),(1,1),(2,0))')
isopen(path)booleanan open path?isopen(path '[(0,0),(1,1),(2,0)]')
length(object)double precisionlength of itemlength(path '((-1,0),(1,0))')
npoints(path)integernumber of pointsnpoints(path '[(0,0),(1,1),(2,0)]')
npoints(polygon)integernumber of pointsnpoints(polygon '((1,1),(0,0))')
pclose(path)pathconvert path to closedpopen(path '[(0,0),(1,1),(2,0)]')
popen(path)pathconvert path to open pathpopen(path '((0,0),(1,1),(2,0))')
radius(circle)double precisionradius of circleradius(circle '((0,0),2.0)')
width(box)double precisionhorizontal sizewidth(box '((0,0),(1,1))')

Table 6-22. Geometric Type Conversion Functions

FunctionReturnsDescriptionExample
box(circle)boxcircle to boxbox(circle '((0,0),2.0)')
box(point, point)boxpoints to boxbox(point '(0,0)', point '(1,1)')
box(polygon)boxpolygon to boxbox(polygon '((0,0),(1,1),(2,0))')
circle(box)circleto circlecircle(box '((0,0),(1,1))')
circle(point, double precision)circlepoint to circlecircle(point '(0,0)', 2.0)
lseg(box)lsegbox diagonal to lseglseg(box '((-1,0),(1,0))')
lseg(point, point)lsegpoints to lseglseg(point '(-1,0)', point '(1,0)')
path(polygon)pointpolygon to pathpath(polygon '((0,0),(1,1),(2,0))')
point(circle)pointcenterpoint(circle '((0,0),2.0)')
point(lseg, lseg)pointintersectionpoint(lseg '((-1,0),(1,0))', lseg '((-2,-2),(2,2))')
point(polygon)pointcenterpoint(polygon '((0,0),(1,1),(2,0))')
polygon(box)polygon4-point polygonpolygon(box '((0,0),(1,1))')
polygon(circle)polygon12-point polygonpolygon(circle '((0,0),2.0)')
polygon(npts, circle)polygonnpts polygonpolygon(12, circle '((0,0),2.0)')
polygon(path)polygonpath to polygonpolygon(path '((0,0),(1,1),(2,0))')

It is possible to access the two component numbers of a point as though it were an array with subscripts 0, 1. For example, if t.p is a point column then SELECT p[0] FROM t retrieves the X coordinate; UPDATE t SET p[1] = ... changes the Y coordinate. In the same way, a box or an lseg may be treated as an array of two points.