Polygons & Nodal Points...

cabney cabney at cyberpass.net
Mon Jul 16 01:42:43 CDT 2001

On Sun, 15 Jul 2001 schoon at amgt.com wrote:

> Yes, this is true, using a ray... But it fails when a point is right on
> a boundary, and the polygon is odd shaped which would make an even
> amount of crossings... Still a valid point, but fails the test...

K, i have to admit... you need to handle when you are leaving the
polyon and your y-value is on the edge:

sub in_poly
	# @isect are x,y quads from the polygon that cross at x
	my ($x, $y, @isect) = @_;

	return "hit!" if is_node($x,$y, at isect);
	my $c = 0;

	# slice gives you y at x for each x,y quad
	my @ladder = slice  ($x, @isect);
	@ladder = sort {$a <=> $b} @ladder;

	while (@ladder)
		my $rung = shift @ladder;
		if ( $y == $rung ) {
			unless ($c % 2) { $c-- }
		last if ( $y <  $rung );
	return ($c % 2) ? "hit!" : "miss!";

There was a time
A wind that blew so young
For this could be the biggest sky
And I could have the faintest idea


The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.

More information about the San-Diego-pm mailing list