1 # Created by Octave 3.6.2, Sun Jun 10 09:53:40 2012 UTC <root@brouzouf>
13 # name: <cell-element>
17 -- Function File: KAPPA = curvature (T, PX, PY,METHOD,DEGREE)
18 -- Function File: KAPPA = curvature (T, POLY,METHOD,DEGREE)
19 -- Function File: KAPPA = curvature (PX, PY,METHOD,DEGREE)
20 -- Function File: KAPPA = curvature (POINTS,METHOD,DEGREE)
21 -- Function File: [KAPPA POLY T] = curvature (...)
22 Estimate curvature of a polyline defined by points.
24 First compute an approximation of the curve given by PX and PY,
25 with the parametrization T. Then compute the curvature of
26 approximated curve for each point. METHOD used for approximation
27 can be only: 'polynom', with specified degree. Further methods
28 will be provided in a future version. T, PX, and PY are N-by-1
29 array of the same length. The points can be specified as a single
32 If the argument T is not given, the parametrization is estimated
33 using function `parametrize'.
35 If requested, POLY contains the approximating polygon evlauted at
36 the parametrization T.
38 See also: parametrize, polygons2d
44 # name: <cell-element>
48 Estimate curvature of a polyline defined by points.
52 # name: <cell-element>
59 # name: <cell-element>
63 -- Function File: DIST = distancePointPolygon (POINT,POLY)
64 Compute shortest distance between a point and a polygon
66 See also: polygons2d, points2d, distancePointPolyline,
67 distancePointEdge, projPointOnPolyline
73 # name: <cell-element>
77 Compute shortest distance between a point and a polygon
82 # name: <cell-element>
89 # name: <cell-element>
93 -- Function File: DIST = distancePointPolyline (POINT,POLY)
94 Compute shortest distance between a point and a polyline Example:
97 poly = [10 10;50 10;50 50;10 50];
98 distancePointPolyline([pt1;pt2], poly)
103 See also: polygons2d, points2d, distancePointEdge,
110 # name: <cell-element>
114 Compute shortest distance between a point and a polyline Example:
119 # name: <cell-element>
126 # name: <cell-element>
130 -- Function File: DIST = distancePolygons (POLY1,POLY2)
131 Compute the shortest distance between 2 polygons
137 # name: <cell-element>
141 Compute the shortest distance between 2 polygons
146 # name: <cell-element>
153 # name: <cell-element>
157 -- Function File: H = drawPolygon (COORD)
158 -- Function File: H = drawPolygon (PX, PY)
159 -- Function File: H = drawPolygon (POLYS)
160 Draw a polygon specified by a list of points.
162 drawPolygon(COORD); Packs coordinates in a single [N*2] array.
164 drawPolygon(PX, PY); Specifies coordinates in separate arrays.
166 drawPolygon(POLYS) Packs coordinate of several polygons in a
167 cell array. Each element of the array is a Ni*2 double array.
169 H = drawPolygon(...); Also return a handle to the list of line
172 See also: polygons2d, drawCurve
178 # name: <cell-element>
182 Draw a polygon specified by a list of points.
186 # name: <cell-element>
193 # name: <cell-element>
197 -- Function File: LOOPS = expandPolygon (POLY, DIST)
198 Expand a polygon by a given (signed) distance
200 Associates to each edge of the polygon POLY the parallel line
201 located at distance DIST from the current edge, and compute
202 intersections with neighbor parallel lines. The resulting
203 polygon is simplified to remove inner "loops", and can be
204 disconnected. The result is a cell array, each cell containing
205 a simple linear ring.
207 This is a kind of dilation, but behaviour on corners is different.
208 This function keeps angles of polygons, but there is no direct
209 relation between length of 2 polygons.
211 It is also possible to specify negative distance, and get all
212 points inside the polygon. If the polygon is convex, the result
213 equals morphological erosion of polygon by a ball with radius
214 equal to the given distance.
222 # name: <cell-element>
226 Expand a polygon by a given (signed) distance
231 # name: <cell-element>
238 # name: <cell-element>
242 -- Function File: [N E] = medialAxisConvex (POLYGON)
243 Compute medial axis of a convex polygon
245 POLYGON is given as a set of points [x1 y1;x2 y2 ...], returns
246 the medial axis of the polygon as a graph. N is a set of nodes.
247 The first elements of N are the vertices of the original polygon.
248 E is a set of edges, containing indices of source and target
249 nodes. Edges are sorted according to order of creation. Index
250 of first vertex is lower than index of last vertex, i.e. edges
251 always point to newly created nodes.
253 Notes: - Is not fully implemented, need more development
254 (usually crashes for polygons with more than 6-7 points...)
255 - Works only for convex polygons. - Complexity is not optimal:
256 this algorithm is O(n*log n), but linear algorithms exist.
258 See also: polygons2d, bisector
264 # name: <cell-element>
268 Compute medial axis of a convex polygon
273 # name: <cell-element>
280 # name: <cell-element>
284 -- Function File: PAR = parametrize (POLY)
285 -- Function File: PAR = parametrize (PX,PY)
286 -- Function File: PAR = parametrize (...,NORMALIZE)
287 Parametrization of a curve, based on edges length
289 Returns a parametrization of the curve defined by the serie of
290 points, based on euclidean distance between two consecutive points.
291 POLY is a N-by-2 array, representing coordinates of vertices. The
292 result PAR is N-by-1, and contains the cumulative length of edges
293 until corresponding vertex. The function also accepts the polygon
294 as two inputs PX and PY representinx coordinates x and y
295 respectively. When optional argument NORMALIZE is non-empty PAR
296 is rescaled such that the last element equals 1, i.e.
300 % Parametrize a circle approximation
301 poly = circleToPolygon([0 0 1], 200);
302 p = parametrize(poly);
306 p = parametrize(poly,'norm');
310 p = parametrize(poly,true);
315 See also: polygons2d, polylineLength
321 # name: <cell-element>
325 Parametrization of a curve, based on edges length
330 # name: <cell-element>
337 # name: <cell-element>
341 -- Function File: SHAPE = polygon2shape (POLYGON)
342 Converts a polygon to a shape with edges defined by smooth
345 POLYGON is a N-by-2 matrix, each row representing a vertex. SHAPE
346 is a N-by-1 cell, where each element is a pair of polynomials
347 compatible with polyval.
349 In its current state, the shape is formed by polynomials of degree
350 1. Therefore the shape representation costs more memory except for
351 colinear points in the polygon.
353 See also: shape2polygon, simplifypolygon, polyval
359 # name: <cell-element>
363 Converts a polygon to a shape with edges defined by smooth polynomials.
367 # name: <cell-element>
374 # name: <cell-element>
378 -- Function File: LOOPS = polygonLoops (POLY)
379 Divide a possibly self-intersecting polygon into a set of simple
382 POLY is a polygone defined by a series of vertices, LOOPS is a
383 cell array of polygons, containing the same vertices of the
384 original polygon, but no loop self-intersect, and no couple of
385 loops intersect each other.
388 poly = [0 0;0 10;20 10;20 20;10 20;10 0];
389 loops = polygonLoops(poly);
394 See also: polygons2d, polygonSelfIntersections
400 # name: <cell-element>
404 Divide a possibly self-intersecting polygon into a set of simple loops
409 # name: <cell-element>
413 polygonSelfIntersections
416 # name: <cell-element>
420 -- Function File: PTS = polygonSelfIntersections (POLY)
421 -- Function File: [PTS POS1 POS2] = polygonSelfIntersections (POLY)
422 Find-self intersection points of a polygon
424 Return the position of self intersection points
426 Also return the 2 positions of each intersection point (the
427 position when meeting point for first time, then position when
428 meeting point for the second time).
431 # use a '8'-shaped polygon
432 poly = [10 0;0 0;0 10;20 10;20 20;10 20];
433 polygonSelfIntersections(poly)
437 See also: polygons2d, polylineSelfIntersections
443 # name: <cell-element>
447 Find-self intersection points of a polygon
452 # name: <cell-element>
459 # name: <cell-element>
463 -- Function File: polygons2d ()
464 Description of functions operating on 2D polygons
466 The 'polygons' module contains functions operating on shapes
467 composed of a vertex list, like polygons or polylines.
469 We call 'polyline' the curve defined by a series of vertices. A
470 polyline can be either closed or open, depending on whether the
471 last vertex is connected to the first one or not. This can be
472 given as an option is some functions in the module. A
473 'polygon' is the planar domain delimited by a closed polyline. We
474 sometimes want to consider 'complex polygons', whose boundary is
475 composed of several disjoint domains. The domain defined by a
476 single closed polyline is called 'simple polygon'. We call
477 'curve' a polyline with many vertices, such that the polyline
478 can be considered as a discrete approximation of a "real" curve.
480 A simple polygon or polyline is represented by a N-by-2 array,
481 each row of the array representing the coordinates of a vertex.
482 Simple polygons are assumed to be closed, so there is no need to
483 repeat the first vertex at the end. As both polygons and
484 polylines can be represented by a list of vertex coordinates,
485 some functions also consider the vertex list itself. Such
486 functions are prefixed by 'pointSet'. Also, many functions
487 prefixed by 'polygon' or 'polyline' works also on the other type
490 For multiple-connected polygons, the different connected
491 boundaries are separated by a row [NaN NaN].
493 For some functions, the orientation of the polygon can be
494 relevant: CCW stands for 'Conter-Clockwise' (positive
495 orientation), CW stands for 'Clockwise'.
497 Polylines are parametrized in the following way: * the i-th
498 vertex is located at position i-1 * points of the i-th edge have
499 positions ranging linearly from i-1 to i The parametrization
500 domain for an open polyline is from 0 to Nv-1, and from 0 to Nv
501 for a closed polyline (positions 0 and Nv correspond to the same
504 Example: % Simple polygon: P1 = [1 1;2 1;2 2;1 2];
505 drawPolygon(P1); axis([0 5 0 5]); % Multiple polygon: P2 =
506 [10 10;40 10;40 40;10 40;NaN NaN;20 20;20 30;30 30;30 20];
507 figure;drawPolygon(P2); axis([0 50 0 50]);
509 Point Sets pointSetBounds - Bounding box of a set of
510 points pointSetsAverage - Compute the average of
511 several point sets minimumCaliperDiameter - Minimum caliper
512 diameter of a set of points findPoint - Find
513 index of a point in an set from its coordinates
515 Polylines polylinePoint - Extract a point from a
516 polyline polylineLength - Return length of a polyline
517 given as a list of points polylineCentroid - Compute
518 centroid of a curve defined by a series of points
519 polylineSubcurve - Extract a portion of a polyline
520 reversePolyline - Reverse a polyline, by iterating
521 vertices from the end isPointOnPolyline - Test if a
522 point belongs to a polyline projPointOnPolyline - Compute
523 position of a point projected on a polyline
524 distancePointPolyline - Compute shortest distance between a
525 point and a polyline distancePolylines - Compute the
526 shortest distance between 2 polylines intersectPolylines
527 - Find the common points between 2 polylines
528 polylineSelfIntersections - Find self-intersections points of a
531 Curves (polylines with lot of vertices) parametrize
532 - Parametrization of a curve, based on edges length curvature
533 - Estimate curvature of a polyline defined by points
534 cart2geod - Convert cartesian coordinates to
535 geodesic coord. geod2cart - Convert geodesic
536 coordinates to cartesian coord. curveMoment -
537 Compute inertia moment of a 2D curve curveCMoment -
538 Compute centered inertia moment of a 2D curve curveCSMoment
539 - Compute centered scaled moment of a 2D curve
541 Polygons polygonPoint - Extract a point from a
542 polygon polygonSubcurve - Extract a portion of a
543 polygon reversePolygon - Reverse a polygon, by
544 iterating vertices from the end projPointOnPolygon -
545 Compute position of a point projected on a polygon splitPolygons
546 - Convert a NaN separated polygon list to a cell array
547 of polygons clipPolygon - Clip a polygon with a
548 rectangular box clipPolygonHP - Clip a polygon with
549 a Half-plane defined by a directed line intersectLinePolygon
550 - Intersection points between a line and a polygon
551 intersectRayPolygon - Intersection points between a ray and
552 a polygon polygonSelfIntersections - Find-self intersection
553 points of a polygon convexHull - Convex hull of a
554 set of points polygonLoops - Divide a possibly
555 self-intersecting polygon into a set of simple loops
556 expandPolygon - Expand a polygon by a given (signed)
557 distance medialAxisConvex - Compute medial axis of a
560 Measures on Polygons isPointInPolygon - Test if a point
561 is located inside a polygon polygonContains - Test if
562 a point is contained in a multiply connected polygon
563 polygonCentroid - Compute the centroid (center of mass)
564 of a polygon polygonArea - Compute the signed area
565 of a polygon polygonLength - Perimeter of a polygon
566 polygonNormalAngle - Compute the normal angle at a vertex
567 of the polygon polygonBounds - Compute the bounding
568 box of a polygon distancePointPolygon - Compute shortest
569 distance between a point and a polygon distancePolygons
570 - Compute the shortest distance between 2 polygons
572 Triangles isPointInTriangle - Test if a point is located
573 inside a triangle triangleArea - Area of a triangle
575 Functions from stochastic geometry steinerPoint -
576 Compute steiner point (weighted centroid) of a polygon
577 steinerPolygon - Create a Steiner polygon from a set of
578 vectors supportFunction - Compute support function of
579 a polygon convexification - Compute the
580 convexification of a polygon
582 Input, Output and conversions readPolygon - Read a
583 polygon stored in a file polygonToRow - Convert
584 polygon coordinates to a row vector rowToPolygon -
585 Create a polygon from a row vector rectAsPolygon -
586 Convert a (centered) rectangle into a series of points
588 Drawing functions drawPolyline - Draw a polyline
589 specified by a list of points drawPolygon - Draw a
590 polygon specified by a list of points fillPolygon
591 - Fill a polygon specified by a list of points
593 Credits: * function intersectPolylines uses the 'interX'
594 contribution from "NS" (file exchange 22441, called
595 'curve-intersections')
597 ---- Author: David Legland e-mail: david.legland@grignon.inra.fr
598 created the 07/11/2005. Homepage:
599 `http://matgeom.sourceforge.net/'
600 `http://www.pfl-cepia.inra.fr/index.php?page=geom2d' Copyright
601 INRA - Cepia Software Platform.
607 # name: <cell-element>
611 Description of functions operating on 2D polygons
616 # name: <cell-element>
620 polylineSelfIntersections
623 # name: <cell-element>
627 -- Function File: PTS = polylineSelfIntersections (POLY)
628 Find self-intersections points of a polyline
630 Return the position of self intersection points
632 Also return the 2 positions of each intersection point (the
633 position when meeting point for first time, then position when
634 meeting point for the second time).
637 # use a gamma-shaped polyline
638 poly = [0 0;0 10;20 10;20 20;10 20;10 0];
639 polylineSelfIntersections(poly)
643 # use a 'S'-shaped polyline
644 poly = [10 0;0 0;0 10;20 10;20 20;10 20];
645 polylineSelfIntersections(poly)
649 See also: polygons2d, intersectPolylines, polygonSelfIntersections
655 # name: <cell-element>
659 Find self-intersections points of a polyline
664 # name: <cell-element>
671 # name: <cell-element>
675 -- Function File: POLY2 = reversePolygon (POLY)
676 Reverse a polygon, by iterating vertices from the end
678 POLY2 = reversePolygon(POLY) POLY2 has same vertices as POLY,
679 but in different order. The first vertex of the polygon is still
682 See also: reversePolyline
688 # name: <cell-element>
692 Reverse a polygon, by iterating vertices from the end
697 # name: <cell-element>
704 # name: <cell-element>
708 -- Function File: POLY2 = reversePolyline (POLY)
709 Reverse a polyline, by iterating vertices from the end
711 POLY2 = reversePolyline(POLY) POLY2 has same vertices as POLY,
712 but POLY2(i,:) is the same as POLY(END-i+1,:).
714 See also: reversePolygon
720 # name: <cell-element>
724 Reverse a polyline, by iterating vertices from the end
729 # name: <cell-element>
736 # name: <cell-element>
740 -- Function File: SPOLY = simplifypolygon (POLY)
741 Simplify a polygon using the Ramer-Douglas-Peucker algorithm.
743 POLY is a N-by-2 matrix, each row representing a vertex.
745 See also: simplifypolyline, shape2polygon
751 # name: <cell-element>
755 Simplify a polygon using the Ramer-Douglas-Peucker algorithm.
759 # name: <cell-element>
766 # name: <cell-element>
770 -- Function File: [PLINE2 IDX] = simplifypolyline (PLINE)
771 -- Function File: ... = simplifypolyline (...,PROPERTY,VALUE,...)
772 Simplify or subsample a polyline using the Ramer-Douglas-Peucker
773 algorithm, a.k.a. the iterative end-point fit algorithm or the
774 split-and-merge algorithm.
776 The PLINE as a N-by-2 matrix. Rows correspond to the verices
777 (compatible with `polygons2d'). The vector IDX constains the
778 indexes on vetices in PLINE that generates PLINE2, i.e. `pline2 =
783 Maximum number of vertices. Default value `1e3'.
786 Tolerance for the error criteria. Default value `1e-4'.
789 Maximum number of iterations. Default value `10'.
794 Run `demo simplifypolyline' to see an example.
796 See also: curve2polyline, curveval
802 # name: <cell-element>
806 Simplify or subsample a polyline using the Ramer-Douglas-Peucker
811 # name: <cell-element>
818 # name: <cell-element>
822 -- Function File: POLYGONS = splitPolygons (POLYGON)
823 Convert a NaN separated polygon list to a cell array of polygons.
825 POLYGON is a N-by-2 array of points, with possibly couples of NaN
826 values. The functions separates each component separated by NaN
827 values, and returns a cell array of polygons.
835 # name: <cell-element>
839 Convert a NaN separated polygon list to a cell array of polygons.
843 # name: <cell-element>
850 # name: <cell-element>
854 -- Function File: H = suppportFunction (POLYGON)
855 -- Function File: H = suppportFunction (POLYGON, N)
856 -- Function File: H = suppportFunction (POLYGON, V)
857 Compute support function of a polygon
859 H = supportFunction(POLYGON, N) uses N points for suport
860 function approximation
862 H = supportFunction(POLYGON) assume 24 points for approximation
864 H = supportFunction(POLYGON, V) where V is a vector, uses vector
865 V of angles to compute support function.
867 See also: convexification
873 # name: <cell-element>
877 Compute support function of a polygon