Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

One thing that may be confusing your attempts to join the polygons, is that the polygons returned from M::G::V->polygons can contain duplicate points. Are you aware of this?

By way of example, the following creates a regular grid of 9x7 equi-spaced points and the uses M::G::V to compute and return the polys. The result is 35 (7x5) "square" polygons. But each of the polys return has 6 rather than 4 points? With 2 points being duplicated in each poly. This doesn't affect the drawing of the polys, but it gets confusing when trying to manipulate the edges.

#! perl -slw use strict; use Data::Dump qw[ pp ]; $Data::Dump::MAX_WIDTH = 200; use Math::Geometry::Voronoi; my @points = map{ my $y = $_; map [ $_, $y ], map $_ * 100, 1 .. 9; } map $_ * 100, 1 .. 7; my $geo = Math::Geometry::Voronoi->new( points => \@points ); $geo->compute; my @geoPolys = $geo->polygons; pp \@geoPolys;

Produces:

C:\test>voronoi [ ## {**** duplicates ****} {**** duplicates ****} [10, [250, 250], [250, 250], [250, 150], [150, 150], [150, 150], [15 +0, 250]], [11, [350, 250], [350, 250], [350, 150], [250, 150], [250, 150], [25 +0, 250]], [12, [450, 250], [450, 250], [450, 150], [350, 150], [350, 150], [35 +0, 250]], [13, [550, 250], [550, 250], [550, 150], [450, 150], [450, 150], [45 +0, 250]], [14, [650, 250], [650, 250], [650, 150], [550, 150], [550, 150], [55 +0, 250]], [15, [750, 250], [750, 250], [750, 150], [650, 150], [650, 150], [65 +0, 250]], [16, [850, 250], [850, 250], [850, 150], [750, 150], [750, 150], [75 +0, 250]], [19, [250, 350], [250, 350], [250, 250], [150, 250], [150, 250], [15 +0, 350]], [20, [350, 350], [350, 350], [350, 250], [250, 250], [250, 250], [25 +0, 350]], [21, [450, 350], [450, 350], [450, 250], [350, 250], [350, 250], [35 +0, 350]], [22, [550, 350], [550, 350], [550, 250], [450, 250], [450, 250], [45 +0, 350]], [23, [650, 350], [650, 350], [650, 250], [550, 250], [550, 250], [55 +0, 350]], [24, [750, 350], [750, 350], [750, 250], [650, 250], [650, 250], [65 +0, 350]], [25, [850, 350], [850, 350], [850, 250], [750, 250], [750, 250], [75 +0, 350]], [28, [250, 450], [250, 450], [250, 350], [150, 350], [150, 350], [15 +0, 450]], [29, [350, 450], [350, 450], [350, 350], [250, 350], [250, 350], [25 +0, 450]], [30, [450, 450], [450, 450], [450, 350], [350, 350], [350, 350], [35 +0, 450]], [31, [550, 450], [550, 450], [550, 350], [450, 350], [450, 350], [45 +0, 450]], [32, [650, 450], [650, 450], [650, 350], [550, 350], [550, 350], [55 +0, 450]], [33, [750, 450], [750, 450], [750, 350], [650, 350], [650, 350], [65 +0, 450]], [34, [850, 450], [850, 450], [850, 350], [750, 350], [750, 350], [75 +0, 450]], [37, [250, 550], [250, 550], [250, 450], [150, 450], [150, 450], [15 +0, 550]], [38, [350, 550], [350, 550], [350, 450], [250, 450], [250, 450], [25 +0, 550]], [39, [450, 550], [450, 550], [450, 450], [350, 450], [350, 450], [35 +0, 550]], [40, [550, 550], [550, 550], [550, 450], [450, 450], [450, 450], [45 +0, 550]], [41, [650, 550], [650, 550], [650, 450], [550, 450], [550, 450], [55 +0, 550]], [42, [750, 550], [750, 550], [750, 450], [650, 450], [650, 450], [65 +0, 550]], [43, [850, 550], [850, 550], [850, 450], [750, 450], [750, 450], [75 +0, 550]], [46, [250, 650], [250, 650], [250, 550], [150, 550], [150, 550], [15 +0, 650]], [47, [350, 650], [350, 650], [350, 550], [250, 550], [250, 550], [25 +0, 650]], [48, [450, 650], [450, 650], [450, 550], [350, 550], [350, 550], [35 +0, 650]], [49, [550, 650], [550, 650], [550, 550], [450, 550], [450, 550], [45 +0, 650]], [50, [650, 650], [650, 650], [650, 550], [550, 550], [550, 550], [55 +0, 650]], [51, [750, 650], [750, 650], [750, 550], [650, 550], [650, 550], [65 +0, 650]], [52, [850, 650], [850, 650], [850, 550], [750, 550], [750, 550], [75 +0, 650]], ]

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Better maps with Math::Geometry::Voronoi, and a Challenge for Math Monks by BrowserUk
in thread Better maps with Math::Geometry::Voronoi, and a Challenge for Math Monks by samtregar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-28 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found