GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MATH::POLYGON::TREE (3)

.ds Aq ’

NAME

Math::Polygon::Tree - fast check if point is inside polygon

CONTENTS

VERSION

version 0.08

SYNOPSIS



    use Math::Polygon::Tree;

    my $poly  = [ [0,0], [0,2], [2,2], ... ];
    my $bound = Math::Polygon::Tree->new( $poly );

    if ( $bound->contains( [1,1] ) )  { ... }



DESCRIPTION

Math::Polygon::Tree creates a tree of polygon parts for fast check if object is inside this polygon. This method is effective if polygon has hundreds or more segments.

METHODS

    new

Takes contours and creates a tree structure. All polygons are outers, inners are not implemented.

Contour is an arrayref of points:



    my $poly1 = [ [0,0], [0,2], [2,2], ... ];  
    ...
    my $bound = Math::Polygon::Tree->new( $poly1, $poly2, ..., \%opt );



or a .poly file



    my $bound1 = Math::Polygon::Tree->new( \*STDIN );
    my $bound2 = Math::Polygon::Tree->new( boundary.poly );



Options:



    prepare_rough



    contains



    my $is_inside = $bound->contains( [1,1] );
    if ( $is_inside ) { ... }



Checks if point is inside bound polygon.

Returns 1 if point is inside polygon, -1 if it lays on polygon boundary, or 0 otherwise.

    contains_points



    # list of points
    if ( $bound->contains_points( [1,1], [2,2] ... ) )  { ... }

    # arrayref of points
    if ( $bound->contains_points( [[1,1], [2,2] ...] ) )  { ... }



Checks if all points are inside or outside polygon.

Returns 1 if all points are inside polygon, 0 if all outside, or <B>undefB> otherwise.

    contains_bbox_rough



    my $bbox = [ 1, 1, 2, 2 ];
    if ( $bound->contains_bbox_rough( $bbox, \%opt ) )  { ... }



Rough check if box is inside bound polygon.

Returns 1 if box is inside polygon, 0 if box is outside polygon or <B>undefB> if it ’doubts’.

Options:



    inaccurate - allow false positive results



    contains_polygon_rough

Checks if polygon is inside bound polygon.

Returns 1 if inside, 0 if outside or <B>undefB> if ’doubts’.



    if ( $bound->contains_polygon_rough( [ [1,1], [1,2], [2,2], ... ] ) )  { ... }



    bbox



    my $bbox = $bound->bbox();
    my ($xmin, $ymin, $xmax, $ymax) = @$bbox;



Returns polygon’s bounding box.

FUNCTIONS

    read_poly_file



    my @contours = read_poly_file( \*STDIN );
    my @contours = read_poly_file( bound.poly )



Reads content of .poly-file. See http://wiki.openstreetmap.org/wiki/.poly

    polygon_bbox



    my $bbox = polygon_bbox( [[1,1], [1,2], [2,2], ... ] );
    my ($xmin, $ymin, $xmax, $ymax) = @$bbox;



Returns polygon’s bounding box.

    bbox_union



    my $united_bbox = bbox_union($bbox1, $bbox2);



Returns united bbox for two bboxes/points.

    polygon_centroid



    my $center_point = polygon_centroid( [ [1,1], [1,2], [2,2], ... ] );



Returns polygon’s weightened center.

Math::Polygon 1.02+ has the same function, but it is very inaccurate.

    polygon_contains_point



    my $is_inside = polygon_contains_point($point, $polygon);



Function that tests if polygon contains point (modified one from Math::Polygon::Calc).

Returns -1 if point lays on polygon’s boundary

AUTHOR

liosha <liosha@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by liosha.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MATH::POLYGON::TREE (3) 2015-04-06

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.