1math::geometry(n) Tcl Math Library math::geometry(n)
2
3
4
5______________________________________________________________________________
6
8 math::geometry - Geometrical computations
9
11 package require Tcl ?8.3?
12
13 package require math::geometry ?1.0.3?
14
15 ::math::geometry::angle line
16
17 ::math::geometry::calculateDistanceToLine P line
18
19 ::math::geometry::calculateDistanceToLineSegment P linesegment
20
21 ::math::geometry::calculateDistanceToPolyline P polyline
22
23 ::math::geometry::findClosestPointOnLine P line
24
25 ::math::geometry::findClosestPointOnLineSegment P linesegment
26
27 ::math::geometry::findClosestPointOnPolyline P polyline
28
29 ::math::geometry::lengthOfPolyline polyline
30
31 ::math::geometry::movePointInDirection P direction dist
32
33 ::math::geometry::lineSegmentsIntersect linesegment1 linesegment2
34
35 ::math::geometry::findLineSegmentIntersection linesegment1 linesegment2
36
37 ::math::geometry::findLineIntersection line1 line2
38
39 ::math::geometry::polylinesIntersect polyline1 polyline2
40
41 ::math::geometry::polylinesBoundingIntersect polyline1 polyline2 granu‐
42 larity
43
44 ::math::geometry::intervalsOverlap y1 y2 y3 y4 strict
45
46 ::math::geometry::rectanglesOverlap P1 P2 Q1 Q2 strict
47
48 ::math::geometry::bbox polyline
49
50 ::math::geometry::pointInsidePolygon P polyline
51
52 ::math::geometry::rectangleInsidePolygon P1 P2 polyline
53
54 ::math::geometry::areaPolygon polygon
55
56_________________________________________________________________
57
59 The math::geometry package is a collection of functions for computa‐
60 tions and manipulations on two-dimensional geometrical objects, such as
61 points, lines and polygons.
62
63 The geometrical objects are implemented as plain lists of coordinates.
64 For instance a line is defined by a list of four numbers, the x- and y-
65 coordinate of a first point and the x- and y-coordinates of a second
66 point on the line.
67
68 The various types of object are recognised by the number of coordinate
69 pairs and the context in which they are used: a list of four elements
70 can be regarded as an infinite line, a finite line segment but also as
71 a polyline of one segment and a point set of two points.
72
73 Currently the following types of objects are distinguished:
74
75 · point - a list of two coordinates representing the x- and y-
76 coordinates respectively.
77
78 · line - a list of four coordinates, interpreted as the x- and y-
79 coordinates of two distinct points on the line.
80
81 · line segment - a list of four coordinates, interpreted as the x-
82 and y-coordinates of the first and the last points on the line
83 segment.
84
85 · polyline - a list of an even number of coordinates, interpreted
86 as the x- and y-coordinates of an ordered set of points.
87
88 · polygon - like a polyline, but the implicit assumption is that
89 the polyline is closed (if the first and last points do not
90 coincide, the missing segment is automatically added).
91
92 · point set - again a list of an even number of coordinates, but
93 the points are regarded without any ordering.
94
96 The package defines the following public procedures:
97
98 ::math::geometry::angle line
99 Calculate the angle from the positive x-axis to a given line (in
100 two dimensions only).
101
102 line list Coordinates of the line
103
104
105 ::math::geometry::calculateDistanceToLine P line
106 Calculate the distance of point P to the (infinite) line and
107 return the result
108
109 P list List of two numbers, the coordinates of the point
110
111 line list List of four numbers, the coordinates of two points
112 on the line
113
114
115 ::math::geometry::calculateDistanceToLineSegment P linesegment
116 Calculate the distance of point P to the (finite) line segment
117 and return the result.
118
119 P list List of two numbers, the coordinates of the point
120
121 linesegment list List of four numbers, the coordinates of the
122 first and last points of the line segment
123
124
125
126 ::math::geometry::calculateDistanceToPolyline P polyline
127 Calculate the distance of point P to the polyline and return the
128 result.
129
130 P list List of two numbers, the coordinates of the point
131
132 polyline list List of numbers, the coordinates of the
133 vertices of the polyline
134
135
136 ::math::geometry::findClosestPointOnLine P line
137 Return the point on a line which is closest to a given point.
138
139 P list List of two numbers, the coordinates of the point
140
141 line list List of four numbers, the coordinates of two points
142 on the line
143
144
145 ::math::geometry::findClosestPointOnLineSegment P linesegment
146 Return the point on a line segment which is closest to a given
147 point.
148
149 P list List of two numbers, the coordinates of the point
150
151 linesegment list List of four numbers, the first and last
152 points on the line segment
153
154
155 ::math::geometry::findClosestPointOnPolyline P polyline
156 Return the point on a polyline which is closest to a given
157 point.
158
159 P list List of two numbers, the coordinates of the point
160
161 polyline list List of numbers, the vertices of the polyline
162
163
164 ::math::geometry::lengthOfPolyline polyline
165 Return the length of the polyline (note: it not regarded as a
166 polygon)
167
168 polyline list List of numbers, the vertices of the polyline
169
170
171 ::math::geometry::movePointInDirection P direction dist
172 Move a point over a given distance in a given direction and
173 return the new coordinates (in two dimensions only).
174
175 P list Coordinates of the point to be moved
176
177 direction double Direction (in degrees; 0 is to the right, 90
178 upwards)
179
180 dist list Distance over which to move the point
181
182
183 ::math::geometry::lineSegmentsIntersect linesegment1 linesegment2
184 Check if two line segments intersect or coincide. Returns 1 if
185 that is the case, 0 otherwise (in two dimensions only).
186
187 linesegment1 list First line segment
188
189 linesegment2 list Second line segment
190
191
192 ::math::geometry::findLineSegmentIntersection linesegment1 linesegment2
193 Find the intersection point of two line segments. Return the
194 coordinates or the keywords "coincident" or "none" if the line
195 segments coincide or have no points in common (in two dimensions
196 only).
197
198 linesegment1 list First line segment
199
200 linesegment2 list Second line segment
201
202
203 ::math::geometry::findLineIntersection line1 line2
204 Find the intersection point of two (infinite) lines. Return the
205 coordinates or the keywords "coincident" or "none" if the lines
206 coincide or have no points in common (in two dimensions only).
207
208 line1 list First line
209
210 line2 list Second line
211
212
213 ::math::geometry::polylinesIntersect polyline1 polyline2
214 Check if two polylines intersect or not (in two dimensions
215 only).
216
217 polyline1 list First polyline
218
219 polyline2 list Second polyline
220
221
222 ::math::geometry::polylinesBoundingIntersect polyline1 polyline2 granu‐
223 larity
224 Check whether two polylines intersect, but reduce the correct‐
225 ness of the result to the given granularity. Use this for
226 faster, but weaker, intersection checking.
227
228 How it works:
229
230 Each polyline is split into a number of smaller polylines, con‐
231 sisting of granularity points each. If a pair of those smaller
232 lines' bounding boxes intersect, then this procedure returns 1,
233 otherwise it returns 0.
234
235 polyline1 list First polyline
236
237 polyline2 list Second polyline
238
239 granularity int Number of points in each part (<=1 means check
240 every edge)
241
242
243 ::math::geometry::intervalsOverlap y1 y2 y3 y4 strict
244 Check if two intervals overlap.
245
246 y1,y2 double Begin and end of first interval
247
248 y3,y4 double Begin and end of second interval
249
250 strict logical Check for strict or non-strict overlap
251
252
253 ::math::geometry::rectanglesOverlap P1 P2 Q1 Q2 strict
254 Check if two rectangles overlap.
255
256 P1 list upper-left corner of the first rectangle
257
258 P2 list lower-right corner of the first rectangle
259
260 Q1 list upper-left corner of the second rectangle
261
262 Q2 list lower-right corner of the second rectangle
263
264 strict list choosing strict or non-strict interpretation
265
266
267 ::math::geometry::bbox polyline
268 Calculate the bounding box of a polyline. Returns a list of four
269 coordinates: the upper-left and the lower-right corner of the
270 box.
271
272 polyline list The polyline to be examined
273
274
275 ::math::geometry::pointInsidePolygon P polyline
276 Determine if a point is completely inside a polygon. If the
277 point touches the polygon, then the point is not completely
278 inside the polygon.
279
280 P list Coordinates of the point
281
282 polyline list The polyline to be examined
283
284
285 ::math::geometry::rectangleInsidePolygon P1 P2 polyline
286 Determine if a rectangle is completely inside a polygon. If
287 polygon touches the rectangle, then the rectangle is not com‐
288 plete inside the polygon.
289
290 P1 list Upper-left corner of the rectangle
291
292 P2 list Lower-right corner of the rectangle
293
294
295 polygon list The polygon in question
296
297
298 ::math::geometry::areaPolygon polygon
299 Calculate the area of a polygon.
300
301 polygon list The polygon in question
302
304 angle, distance, line, math, plane geometry, point
305
307 Copyright (c) 2004 by Ideogramic ApS and other parties
308
309
310
311
312math 1.0.3 math::geometry(n)