Danny Van de Pol >
Math-Geometry-Planar-1.18-withoutworldwriteables >
Math::Geometry::Planar

Module Version: 1.18
- NAME
- SYNOPSIS
- METHODS
- $polygon->points(arg);
- $contour->polygons(arg);
- $contour->num_polygons;
- $contour->add_polygons(arg);
- $contour->get_polygons(arg_1,arg_2, ... );
- $polygon->cleanup;
- $polygon->isconvex;
- $polygon->issimple;
- $polygon->perimeter;
- $polygon->area;
- $polygon->centroid;
- $polygon->isinside($point);
- $polygon->rotate($angle,$center);
- $polygon->move($dx,$dy);
- $polygon->mirrorx($center);
- $polygon->mirrory($center);
- $polygon->mirror($axos);
- $polygon->scale($csale,$center);
- $polygon->bbox;
- $polygon->minrectangle;
- $polygon->convexhull;
- $polygon->convexhull2;
- $polygon->triangulate;
- $polygon->offset_polygon($distance);
- $polygon->convert2gpc;

- EXPORTS
- SegmentLength[$p1,$p2];
- Determinant(x1,y1,x2,y2);
- DotProduct($p1,$p2,$p3,$p4);
- CrossProduct($p1,$p2,$p3);
- TriangleArea($p1,$p2,$p3);
- Colinear($p1,$p2,$p3);
- SegmentIntersection($p1,$p2,$p3,$p4);
- LineIntersection($p1,$p2,$p3,$p4);
- RayIntersection($p1,$p2,$p3,$p4);
- RayLineIntersection($p1,$p2,$p3,$p4);
- SegmentLineIntersection($p1,$p2,$p3,$p4);
- SegmentRayIntersection($p1,$p2,$p3,$p4);
- Perpendicular($p1,$p2,$p3,$p4);
- PerpendicularFoot($p1,$p2,$p3);
- DistanceToLine($p1,$p2,$p3);
- DistanceToSegment($p1,$p2,$p3);
- Gpc2Polygons($gpc_contour);
- GpcClip($operation,$gpc_contour_1,$gpc_contour_2);
- CircleToPoly($i,$p1,$p2,$p3);
- CircleToPoly($i,$center,$p1);
- CircleToPoly($i,$center,$radius);
- ArcToPoly($i,$p1,$p2,$p3);
- ArcToPoly($i,$center,$p1,$p2,$direction);

Math::Geometry::Planar - A collection of planar geometry functions

use Math::Geometry::Planar; $polygon = Math::Geometry::Planar->new; creates a new polygon object; $contour = Math::Geometry::Planar->new; creates a new contour object;

A point is a reference to an array holding the x and y coordinates of the point.

$point = [$x_coord,$y_coord];

A polygon is a reference to an (ordered) array of points. The first point is the begin and end point of the polygon. The points can be given in any direction (clockwise or counter clockwise).

A contour is a reference to an array of polygons. By convention, the first polygon is the outer shape, all other polygons represent holes in the outer shape. The outer shape must enclose all holes ! Using this convention, the points can be given in any direction, however, keep in mind that some functions (e.g. triangulation) require that the outer polygons are entered in counter clockwise order and the inner polygons (holes) in clock wise order. The points, polygons, add_polygons methods will automatically set the right order of points. No points can be assigned to an object that already has polygons assigned to and vice versa.

$points = [[$x1,$y1],[$x2,$y2], ... ]; $polygon->points($points); # assign points to polygon object $points1 = [[$x1,$y1],[$x2,$y2], ... ]; $points2 = [[ax1,by1],[ax2,by2], ... ]; $contour->polygons([$points1,$points2, ...]); # assign polgyons to contour object

The available methods are:

Returns the polygon points if no argument is entered. If the argument is a refence to a points array, sets the points for a polygon object.

Returns the contour polygons if no argument is entered. If the argument is a refence to a polygons array, sets the polygons for a contour object.

Returns the total number of polygons in the contour.

Adds a list of polygons to a contour object (if the contour object doesn't have any polygons yet, the very first polygon reference from the list is used as the outer shape). Returns the total number of polygons in the contour.

Returns a list of polygons where each element of the list corresponds to the polygon at index arg_x - starting at 0, the outer shape. If the index arg_x is out of range, the corresponding value in the result list wil be undefined. If no argument is entered, a full list of all polygons is returned. Please note that this method returns a list rather then a reference.

Remove colinear points from the polygon/contour.

Returns true if the polygon/contour is convex. A contour is considered to be convex if the outer shape is convex.

Returns true if the polygon/contour is simple. A contour is considered to be simple if all it's polygons are simple.

Returns the perimeter of the polygon/contour. The perimeter of a contour is the perimeter of the outer shape.

Returns the signed area of the polygon/contour (positive if the points are in counter clockwise order). The area of a contour is the area of the outer shape minus the sum of the area of the holes.

Returns the centroid (center of gravity) of the polygon/contour.

Returns true if point is inside the polygon/contour (a point is inside a contour if it is inside the outer polygon and not inside a hole).

Returns polygon/contour rotated $angle (in radians) around $center. If no center is entered, rotates around the origin.

Returns polygon/contour moved $dx in x direction and $dy in y direction.

Returns polygon/contour mirrored in x direction with (vertical) axis of reflection through point $center. If no center is entered, axis is the Y-axis.

Returns polygon/contour mirrored in y direction with (horizontal) axis of reflection through point $center. If no center is entered, axis is the X-axis.

Returns polygon mirrored/contour along axis $axis (= array with 2 points defining axis of reflection).

Returns polygon/contour scaled by a factor $scale, center of scaling is $scale. If no center is entered, center of scaling is the origin.

Returns the polygon's/contour's bounding box.

Returns the polygon's/contour's minimal (area) enclosing rectangle.

Returns a polygon representing the convex hull of the polygon/contour.

Returns a polygon representing the convex hull of an arbitrary set of points (works also on a contour, however a contour is a set of polygons and polygons are ordered sets of points so the method above will be faster)

Triangulates a polygon/contour based on Raimund Seidel's algorithm: 'A simple and fast incremental randomized algorithm for computing trapezoidal decompositions and for triangulating polygons' Returns a list of polygons (= the triangles)

Returns reference to an array of polygons representing the original polygon offsetted by $distance

Converts a polygon/contour to a gpc structure and returns the resulting gpc structure

Returns the length of the segment (vector) p1p2

Returns the determinant of the matrix with rows x1,y1 and x2,y2 which is x1*y2 - y1*x2

Returns the vector dot product of vectors p1p2 and p3p4 or the dot product of p1p2 and p2p3 if $p4 is ommited from the argument list

Returns the vector cross product of vectors p1p2 and p1p3

Returns the signed area of the triangle p1p2p3

Returns true if p1,p2 and p3 are colinear

Returns the intersection point of segments p1p2 and p3p4, false if segments don't intersect

Returns the intersection point of lines p1p2 and p3p4, false if lines don't intersect (parallel lines)

Returns the intersection point of rays p1p2 and p3p4, false if lines don't intersect (parallel rays) p1 (p3) is the startpoint of the ray and p2 (p4) is a point on the ray.

Returns the intersection point of ray p1p2 and line p3p4, false if lines don't intersect (parallel rays) p1 is the startpoint of the ray and p2 is a point on the ray.

Returns the intersection point of segment p1p2 and line p3p4, false if lines don't intersect (parallel rays)

Returns the intersection point of segment p1p2 and ray p3p4, false if lines don't intersect (parallel rays) p3 is the startpoint of the ray and p4 is a point on the ray.

Returns true if lines (segments) p1p2 and p3p4 are perpendicular

Returns the perpendicular foot of p3 on line p1p2

Returns the perpendicular distance of p3 to line p1p2

Returns the distance of p3 to segment p1p2. Depending on the point's position, this is the distance to one of the endpoints or the perpendicular distance to the segment.

Converts a gpc contour structure to an array of contours and returns the array

$operation is DIFFERENCE, INTERSECTION, XOR or UNION $gpc_polygon_1 is the source polygon $gpc_polygon_2 is the clip polygon

Returns a gpc polygon structure which is the result of the gpc clipping operation

Converts the circle through points p1p2p3 to a polygon with i segments

Converts the circle with center through point p1 to a polygon with i segments

Converts the circle with center and radius to a polygon with i segments

Converts the arc with begin point p1, intermediate point p2 and end point p3 to a (non-closed !) polygon with i segments

Converts the arc with center, begin point p1 and end point p2 to a (non-closed !) polygon with i segments. If direction is 0, the arc is traversed counter clockwise from p1 to p2, clockwise if direction is 1

syntax highlighting: