in reply to Subroutine Subtrefuge

Let me see if I can grok your problem.

1. The data in the <points>...</points> element is a list of points in 3-space. You are only interested in the first two coordinates, so you are treating them as points in 2-space (or ordered pairs). These coordinates represent the vertices of a polygon (inferred by the name of your variable.)

2. Each <tag>...</tag> element specifies two polygons (or perhaps even more than two), and they are given names specified by the <name>...</name> element.

3. Given two polygons, p1 and p2, you want to call a function, f(e1, e2), on all pairs of edges where e1 is an edge of p1 and e2 is an edge of p2. An edge of a polygon is defined by two adjacent vertices of the polygon.

Is this essentially what you are trying to do?

Replies are listed 'Best First'.
Re^2: Subroutine Subtrefuge
by AF_One (Novice) on Jun 08, 2008 at 03:40 UTC

    pc88mxer,

    You've got it. <tag> would normally contain many polygons. Every edge is compared to all others.

    Cartographers and surveyors use this method of analysis. It's native to a methodology that is universally employed by a Geospatial Information System (GIS).

    The file being sucked-in is a Google Earth KML (Keyhole Markup Language). GE is known in the GIS industry as a "geo-browser" because it does not offer the above proximity analysis, among other things.

    Come to think of it...I should have asked if it were possible to have the sub return true on the first occurrence of intersection within each key's values.

    Thanks for the reply,

    This newbie appreciates it!

      I think it would be easier to have the sub return true on every occurrence of intersection and let the caller sort that out, because there the necessary information is at hand

      foreach my $key (keys %points_by_name) { my $intersectionfound=0; for (my $i=0; $i<=@{$points_by_name{$key}}-4; $i+=2) { if (sub(@{$points_by_name{$key}}[$i..$i+3],$x2, $y2, $x3, $y3) and not $intersectionfound) { # found the first intersection of $key } } }
      If you really need the info in the sub, just pass $intersectionfound to the sub, as long as it is 0 (false) an intersection is the first intersection of a key (provided that the sub really returns true on found intersections and false otherwise).

      PS: I dropped your "excessive" indentation, so that the code fits into the editor window of the website ;-).