The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.

Geometric Functions and Operators

Last updated: 2024-08-22 16:22:31

The geometric types supported by the database include point, box, lseg, line, path, polygon, circle. Therefore, the database also provides a series of geometric functions. See the table below for details.

Geometric Operators

Operator
Description
Sample code
Result
+
Translate
box '((0,0),(1,1))' + point '(2.0,0)'
(3,1),(2,0)
-
Translate
box '((0,0),(1,1))' - point '(2.0,0)'
(-1,1),(-2,0)
*
Stretch/Rotate
box '((0,0),(1,1))' * point '(2.0,0)'
(2,2),(0,0)
/
Stretch/Rotate
box '((0,0),(2,2))' / point '(2.0,0)'
(1,1),(0,0)
#
Intersection of two geometries
box '((1,-1),(-1,1))' # box '((1,1),(-1,-1))'
(1,1),(-1,-1)
@-@
Length or Perimeter of the geometry
@-@ path '((0,0),(1,0))'
2
@@
Center
@@ circle '((0,0),10)'
(0,0)
##
The closest point of the first geometry to the second geometry
point '(0,0)' ## lseg '((2,0),(0,2))'
(1,1)
<->
Distance between geometries
circle '((0,0),2)' <-> circle '((4,0),1)'
1
&&
Whether two geometries intersect
box '((0,0),(1,2))' && box '((0,0),(2,3))'
t
<<
Whether geometry 1 is strictly to the left of geometry 2
circle '((0,0),1)' << circle '((5,0),1)'
t
>>
Whether geometry 1 is strictly to the right of geometry 2
circle '((5,0),1)' >> circle '((0,0),1)'
t
&<
Whether the right edge of geometry 1 does not exceed the right edge of geometry 2
box '((0,0),(1,1))' &< box '((0,0),(2,2))'
t
&>
Does the rightmost edge of Graphic 1 not exceed the leftmost edge of Graphic 2
box '((0,0),(3,3))' &> box '((0,0),(2,2))'
t
<<|
Is Graphic 1 strictly below Graphic 2
box '((0,0),(2,2))' <<| box '((4,5),(6,6))'
t
|>>
Is Graphic 1 strictly above Graphic 2
box '((5,6),(7,7))' |>> box '((0,0),(4,4))'
t
<^
Is Graphic 1 below Graphic 2 (contact allowed)
box '((5,6),(7,7))' <^ box '((0,0),(4,4))'
f
>^
Is Graphic 1 above Graphic 2 (contact allowed)
box '((5,6),(7,7))' >^ box '((0,0),(4,4))'
t
?#
Intersect
lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))'
t
?-
Is it horizontal
?- lseg '((-1,0),(1,0))'
t
?-
Are the two graphics horizontally aligned
point '(1,0)' ?- point '(0,0)'
t
?|
Is it vertical
?| lseg '((-1,0),(1,0))'
f
?|
Are the two graphics vertically aligned
point '(1,2)' ?| point '(1,1)'
t
?-|
Are the two lines vertical
lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))'
t
?||
Are the two lines parallel
lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))'
t
@>
Does Graphic 1 include Graphic 2
circle '((0,0),2)' @> circle '((0,0),1)''
t
<@
Is Graphic 1 included by Graphic 2
point '(1,1)' <@ circle '((0,0),2)'
t
~=
Are they identical
polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))'
t

Geometric Functions

Function
Return Type
Description
Sample code
Result
area(object)
double precision
Area
area(box '((0,0),(1,2))')
2
center(object)
point
Centroid
center(box '((0,0),(1,2))')
(0.5,1)
diameter(circle)
double precision
Circle Diameter
diameter(circle '((0,0),2.0)')
4
height(box)
double precision
High
height(box '((0,0),(2,3))')
3
isclosed(path)
boolean
Is Shape Closed
isclosed(path '((0,0),(1,1),(2,0))')
t
isopen(path)
boolean
Is Shape Open
isopen(path '[(0,0),(1,1),(2,0)]')
t
length(object)
double precision
Shape Length
length(path '((-1,0),(1,0))')
2
npoints(path)
int
Number of Vertices
npoints(path '[(0,0),(1,1),(2,0)]')
3
npoints(polygon)
int
Number of Vertices
npoints(polygon '((1,1),(0,0))')
2
radius(circle)
double precision
Circle Radius
radius(circle '((0,0),2.0)')
2
width(box)
double precision
Horizontal Length
width(box '((0,0),(3,2))')
3

Geometric Type Conversion Functions

Function
Return Type
Description
Sample code
Returned values
box(circle)
box
Circle to Rectangle
box(circle '((0,0),3.0)')
(2.12132034355964,2.12132034355964),(-2.12132034355964,-2.12132034355964) (1 row)
box(point, point)
box
Point to Rectangle
box(point '(0,0)', point '(2,2)')
(2,2),(0,0)
box(polygon)
box
Polygon to Rectangle
box(polygon '((0,0),(1,1),(2,0))')
(2,1),(0,0)
circle(box)
circle
Convert Rectangle to Circle
circle(box '((0,0),(2,2))')
<(1,1),1.4142135623731>
circle(point, double precision)
circle
Convert Center and Radius to Circle
circle(point '(0,0)', 3.0)
<(0,0),3>
circle(polygon)
circle
Convert Polygon to Circle
circle(polygon '((0,0),(1,1),(2,0))')
<(1,0.333333333333333),0.924950591148529>
lseg(box)
lseg
Convert Rectangle to Segment
lseg(box'((-1,0),(1,0))')
[(1,0),(-1,0)]
lseg(point, point)
lseg
Convert Multiple Points to Segment
lseg(point '(-1,0)', point '(1,0)')
[(-1,0),(1,0)]
path(polygon)
path
polygon to path
path(polygon '((0,0),(1,1),(2,0))')
((0,0),(1,1),(2,0))
point(double precision, double precision)
point
construct point
point(23.4, -44.5)
(23.4,-44.5)
point(box)
point
Center of Graphics
point(box '((-1,0),(1,0))')
(0,0)
point(circle)
point
Center of Circle
point(circle '((0,0),2.0)')
(0,0)
point(lseg)
point
Center of Segment
point(lseg '((-2,0),(2,0))')
(0,0)
point(polygon)
point
Center of Polygon
point(polygon '((0,0),(1,1),(2,0))')
(1,0.333333333333333)
polygon(box)
polygon
Convert Rectangle to a Four-Point Polygon
polygon(box '((0,0),(1,1))')
((0,0),(0,1),(1,1),(1,0))
polygon(circle)
polygon
Convert Circle to a 12-Point Polygon
polygon(circle '((0,0),2.0)')
-
polygon(npts, circle)
polygon
Convert Circle to a Polygon with n Points
polygon(12, circle '((0,0),2.0)')
((-2,0),(-0.618033988749895,1.90211303259031),(1.61803398874989,1.17557050458495),(1.6180339887499,-1.17557050458495),(-0.618033988749894,-1.90211303259031))
polygon(path)
polygon
Convert Path to Polygon
polygon(path '((0,0),(1,1),(2,0))')
((0,0),(1,1),(2,0))