Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!deb
From: deb@svax.cs.cornell.edu (David Baraff)
Newsgroups: comp.graphics
Subject: Re: Intersection between a line and a polygon (UNDECIDABLE??)
Keywords: P, NP, Jordan curve separation, Ursyhon Metrization Theorem
Message-ID: <32610@cornell.UUCP>
Date: 28 Sep 89 19:04:46 GMT
References: <2972@ndsuvax.UUCP>
Sender: nobody@cornell.UUCP
Reply-To: deb@charisma.graphics.cornell.edu (David Baraff)
Organization: Program of Computer Graphics
Lines: 69

In article <2972@ndsuvax.UUCP> ncsmith@ndsuvax.UUCP (Timothy Lyle Smith) writes:
>
>  I need to find a formula/algorithm to determine if a line intersects
>  a polygon.  I would perfer a method that would do this in as litte
>  time as possible.  I need this for use in a forward raytracing
>  program.

I think that this is a very difficult problem. To start with,
lines and polygons are semi-algebraic sets which both contain
uncountable number of points. Here are a few off-the-cuff
ideas.

First, we need to check if the line and the polygon are seperated.
Now, the Jordan curve seperation theoreom says that the polygon
divides the plane into exactly two open (and thus non-compact)
regions. Thus, the line lies completely inside the polygon,
the line lies completely outside the polygon, or posssibly
(but this will rarely happen) the line intersects the polyon.

Now, the phrasing of this question says "if a line intersects a polygon",
so this is a decision problem. One possibility (the decision model approach)
is to reduce the question to some other (well known) problem Q, and
then try to solve Q. An answer to Q gives an answer to the original
decision problem.

In recent years, many geometric problems have been successfully
modeled in a new language called PostScript. (See "PostScript Language",
by Adobe Systems Incorporated, ISBN # 0-201-10179-3, co. 1985).
	
So, given a line L and a polygon P, we can write a PostScript program
that draws the line L and the polygon P, and then "outputs"
the answer. By "output", we mean the program executes a command
called "showpage", which actually prints a page of paper containing
the line and the polygon. A quick examination of the paper
provides an answer to the reduced problem Q, and thus the original
problem.

There are two small problems with this approach. 

	(1) There is an infinite number of ways to encode L and P
        into the reduced problem Q. So, we will be forced to invoke
        the Axiom of Choice (or equivalently, Zorn's Lemma). But
	the use of the Axiom of Choice is not regarded in a very
	serious light these days.

	(2) More importantly, the question arises as to whether or
	not the PostScript program Q will actually output a piece
	of paper; or in other words, will it halt?

	Now, PostScript is expressive enough to encode everything
	that a Turing Machine might do; thus the halting problem
	(for PostScript) is undecidable. It is quite possible
	that the original problem will turn out to be undecidable.
	

I won't even begin to go into other difficulties, such as aliasing,
finite precision and running out of ink, paper or both.

A couple of references might be:

1. Principia Mathematica. Newton, I. Cambridge University Press,
   Cambridge, England. (Sorry, I don't have an ISBN# for this).

2. An Introduction to Automata Theory, Languages, and Computation.
   Hopcroft, J and Ulman, J.

3. The C Programming Language. Kernighan, B and Ritchie, D.

4. A Tale of Two Cities. Dickens, C.