Geometric Modeling, Spring 2001
Homework 1 (Due: Feb 1, 2001)

How to hand in your solution: please email me a "jar file" containing the following files:

  • (1) README file with instructions,
  • (2) Makefile for automatic compilation and testing, I should be able to type "make test" to run your program!
  • (3) The .java files, and
  • (4) Some input data files for automatic testing

    In this homework, we want you to program in Java to implement a simple algorithm to compute the pairwise intersections of a set of line segments. We will proceed in stages.

    STEP 1:

    Write a Java program called
    		SegIntersect.java
    	
    which, reads a list of line segments from a file and computes all their intersections using naive quadratic time algorithm. For output, print a list of the pairs of intersecting segments, and their intersection points, to an output file.
    ASSUME: the input has ``no degeneracies'' (you are free determine what this means). So your code should be quite simple!
    HINT: The goal is to make the program work, and not to worry too much about object-oriented niceties at this point!
    INPUT FILE FORMAT:
    The following specifications MUST be followed (we want to test your program using our own inputs).
    1. The input file is an ascii (text) file.
    2. Input is line-based. White spaces (space, tabs) are only used to separate tokens.
    3. Rest-of-Line Comment symbol is "#". The rest of an input lines, beginning from the "#" character, are ignored. We want you to liberally insert comments in your input files for human verification!
    4. Line continuation symbol is "\". This way, you can nicely format long input lines, using indentation, etc.
    5. Each segment is specified by
      		SEG x1 , y1, x2 , y2
      	
      where SEG is a keyword, and (x1,y1) and (x2,y2) are the integer coordinates of the endpoints of the segment. The commas are mandatory. If you want highly readable version of this, you could have
      		SEG \
      		   x1 , y1 , \  # first endpoint
      		   x2 , y2	# second endpoint
      	
    6. The rest of file is ignored when we read a command EOF.

    STEP 2:

    We now add GUI interfaces. Write a Java awt (or swing) program
    		GuiSegIntersect.java
    	
    which couples the program from STEP 1 to a GUI interface. We want the user to specify input segments by clicking end points. There are radio buttons called "Mouse Input", "File Input", "Graphical Output" and "File Output". When the "Mouse Input" button is depressed, you clear the screen and start reading the mouse clicks to define segments. When the "Graphical Output" button is depressed, you compute the intersections and display the segments AND mark all intersections with small circles. The file input and output radio buttons are obvious, but you need to read in a file name.

    STEP 3:

    Do not attempt this until you solved the first two steps. This step is optional. Write a program called SweepSegIntersect.java. In this case, we want to re-do STEP 1 but using the line-sweep algorithm discussed in class (and in the text). Perform some timings to compare your two programs.

    In order to do this, you will need to implement two different kinds of balanced binary trees. I am just as happy to have you take code from ANY legal source (as long as you acknowledge this).

    If you want to implement your own, there are many choices, but I recommend the use of Splay Trees. I can give you more information on how to do this quite simply if you talk to me.