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