Due: Monday Feb 17, 2003

Homework 2

  1. In this homework, we start to implement some basic 2-dimensional geometric classes. Specifically, we want to implement 3 classes: Point2d, Line2d and Segment2d. However, we want all these classes to be extensions of an abstract class called GeomObj. One reason is that very often we want to return an object that can be either a point, a line or a segment! Other common features of all geometric objects can be embodied here.
  2. I have put together three files Point2d.j, Line2d.java, Segment2d.j which contain the specifications of what we will (eventually) need for each class. They are not quite Java Code yet, because they are roughly converted from actual C++ programs. Please use them as starting point for your coding.
    -- The relationship among these 3 classes are as follows: Point2d class is absolutely basic, and it should not know anything about lines or segments. Line2d class knows about Point2d, but not about Segment2d. Finally, Segment2d class should extend Line2d.
  3. IMPLEMENTATION NOTES AND HINTS:
    -- It seems best to first implement various linear algebra routines in two classes called Vector2d and Matrix2d. I have implemented both classes and stored them in Vector2d.java. A useful work horse in Vector2d is the method called "solve" which solves a system of 2 linear equations.
    -- Here is the math for computing the projection of a point on to a line. After you set up the equations, you can use the "solve" method in Vector2d to compute the projection point.
    -- Here is a sample implementation of Point2d. Note that I have implemented Point2d as an extension of the Vector2d class. You can use this, as is, if you like.
    -- When implementing the classes, you can initially make most of them do nothing. Slowly add the functionalities to your classes.
    -- Each class should have a main program so that you can do self-testing and debugging of the class.
    -- My philosophy in this course is to minimize the burden of "object oriented philosophy" when they get in the way of understanding the geometry. Therefore, I will be quite happy if all your methods and variables in a class are made public.
    -- Try to use the Java standard library's Collection structures (List, Vector, Set) as appropriate. Its Iterator interface is also useful.
  4. INSTRUCTIONS FOR SUBMITTING THIS HOMEWORK:
    -- A reminder about working in teams.
    -- Send me an email with the SUBJECT "hw2" and with a tar file as attachment. Your tar file should contain (1) ALL java programs that are needed to run your code, and (2) a Makefile (similar to the one in hw1). I want to be able to type "make" and immediately test your code.
    -- Be sure to cc your email to EACH member of the team. This helps me when I send my response to the whole team.
    -- Please do not rename "Makefile" to "Makefile.txt" because the make program looks for a file named "Makefile". Be sure to include ALL classes that are needed to run your program (if you use "ApplicationFrame.java", then make sure this file is inside your "tar" file).
    -- Here are three targets you should have in your Makefile:
    (a) point: compile and test your point class
    (b) line: compile and test your line class
    (c) segment: compile and test your segment class In this case, you must implement the O(n2) algorithm to test if a set of segments do not properly intersect.
    -- Please be sure that all your programs are minimally commented, and can compile before you submit.