Project 1: Intersections
Due Date: Tue, Apr 15th
In computer graphics (including games), an important problem
is to discover if two objects are intersecting. For performance
reasons, we often perform two gross estimates between objects
to determine if they intersect before testing whether
the small parts of the objects intersect.
For example, consider a scenario where a hand is used to pick
a flower. Clearly, the flower has many parts (petals, leaves,
stem, etc), as does the hand (fingers, thumb, palm). By performing
a rough estimate, we can keep from having to test each individual
part of the objects.
Goals of the Project
The primary goals of the project are to:
- Help you understand how we test the intersection of objects
using spheres and bounding boxes
- Help you become more familiar with Java and its features,
including arrays
- Help you learn how to program and debug with Eclipse better
- Help you further understand how to analyze the performance of
algorithms
What to Do
You will need to build at least one class to solve this project:
- Object2D: a class which represents an object by an array of points
in 2-dimensional space.
Object2D has the following methods:
- public Object2D(String filename): a constructor which intializes the object
to a set of points from a file. The format of the file are floating
point numbers, separated by spaces, one vertex of the object per line.
- public void createBoundingBox(): a method which creates a bounding box
around the vertices of the object.
- public void createBoundingCircle(): a method which creates a
bounding circle around the vertices of the object.
- public String toString(): a method which prints out the vertices of the object,
followed by a colon, followed by the center and radius of the circle surrounding
the object, followed by a colon, followed by the vertices of the bounding box.
The output should look similar to the
following to assist in grading: (1,20) (18,14)
(20,35) : (13,23) 15 : (1,14) (20,35)
- public boolean circleIntersects(Object2D obj): a method which returns true if
the circle around this object intersects with the given object, or false if
it doesn't.
- public boolean boxIntersects(Object2D obj): a method which returns true if the
bounding box of this object intersects with the bounding box of the given
object, or false if it doesn't.
In addition, you will need to determine the running time of
each algorithm. How long does it take, if one object has
n
vertices and the other object has
m vertices to run
create a bounding box, create a bounding sphere, and test if
two objects intersect through either method? You must include
the running time in comments at the start of each method.
Turn-in
You will need to use subversion with your group or solo (remember, groups
can be up to 3 people). We will simply check-out your repository at the
end of the day that the project is due, so check-in your project frequently
and of course when you're done.
Grading
Your project will be graded on the correctness of your implementation
and your understanding of its performance. In particular:
- Does your project correctly read in the data file for the objects?
- Does it correctly calculate the bounding box for each object?
- Does it correctly determine if two objects are intersecting?
- Does your project correctly use arrays?
Note that we will test your project with a variety of objects ranging
in sizes (ie, vertices), so it is in your best interest to test your
project. Our test program will consist of a class with a main method
that will create your object based on our test files.
Extra Credit
For extra credit, extend the project to 3 dimensions instead of only two.
Note that objects will have to have 3-dimensional points representing the vertices
instead of only two. Clearly this means creating a class such as Object3D with
appropriately named methods and with additional dimensions.