RayCasting - Is the point inside?

Romero, a game developer wants to design an algorithm to tell whether the dark monster is inside his polygonal hideout. But because the hideout is really strangely shaped, it's hard to tell.

So, to find out, Romero draws out a ray from the location monster. The ray intersects the hideout walls at exactly 8 points.

What Romero drew What Romero drew

Is the monster inside his hideout?

Yes, he is inside No, he is outside

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Steven Chase
Apr 11, 2017

If you start inside, draw a straight line, and end up outside, that means that you do the following:

1) Leave once (1 intersection)............and then
2) Enter and leave an integer number of times (2 intersections times an integer is an even number)

One plus an even number of intersections is an odd number. Since the actual number is even, he must be outside.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...