This is a collection of (hopefully) helpful notes concerning the Spatial Database project.
double
s for all coordinates, lengths,
velocties, and times (that is, ignore the instruction in the
original directions about type float
).
write
has been corrected to
mention the rad
command rather than the (nonexistent)
size
command. Also, it asks that you print
commands one per line, and print add commands in
order of increasing ID.
- The
near
command asks for the objects to be printed
in order of increasing ID. This will make testing a little
easier. You should be able to do this with just a few lines of
Java code; do use the sort
methods provided in
java.util.Collections
and
java.util.Arrays
.
- We've clarified the
within
command to make it clear
that we are talking about the distances of their centers from each
other. As for near
, we ask that you print pairs in
increasing order by ID1 and (for equal values of
ID1) by increasing order by
ID2.
- The "Algorithms" section now suggests that to move objects to their
new positions, you should put the objects at their new positions
into a brand new
QuadTree
, and then replace the
old QuadTree
with the new one. The reason for
this is there are cases where one object is "following"
another and moves to the other object's former position before
the program has gotten around to moving the other object. Our
QuadTree representation does not take well to having two
objects at the same place. Since we won't really have need
for the set
method in Set2D
and
QuadTree
, we have filled in a simple-minded
implementation for you (see ~cs61b/code/proj2/util
).
- We have corrected the testcase in the
testing
subdirectory. Make sure to get the updated version from
~cs61b/code/proj2/testing
.
- Please don't move code out of the
tracker
package in order
to avoid dealing with packages. We will be testing that your
tracker
package works with our util
package. In
order for this to work, you must leave track.java
pretty much as
it is (basically just a call to tracker.Main.main
).
We are maintaining two JAR (Java Archive Repository) files containing
the staff's versions of the packages tracker
and util
.
You can use these to supply one half of the assignment while you work
on the other. We are not supplying source, of course, so when you encounter
an error that occurs in one of the staff's classes, you will have to step
upwards in the call stack to find where your part most recently
called the staff's. Don't overuse the staff packages; you should rely
prinicipally on your own unit testing. The staff package, however,
can serve as a "sanity check" that you haven't seriously misunderstood
the assignment.
The staff version of the util package
is in
~cs61b/lib/proj2-util.jar
and the tracker
is
in ~cs61b/lib/proj2-tracker.jar
. To use either of these,
you must include the appropriate JAR file in your "class path".
For example, to use the staff's version of tracker
with your util
package, start an Eclipse project containing just
the track.java
class and your util
source
directory. Then add ~cs61b/lib/proj2-tracker.jar
to what
Eclipse calls the "build path":
~cs61b/lib/proj2-tracker.jar
.
[3/24/2006] I have added some lines to
~cs61b/code/proj2/track.java
so that you may take the
command input from a named file, as in
java track FILEFULLOFCOMMANDS
It seems that Eclipse is not very good at input redirection. On the UNIX command line, you could simply write
java track < FILEFULLOFCOMMANDSfor this purpose, so you wouldn't need the extra argument.
This feature is entirely optional, since it is not mentioned in the spec.
Main.main
:
public void main () { System.out.print("> "); Scanner inp = new Scanner (System.in); String input = inp.findWithinHorizon(".*", 0).trim(); if (!input.contentEquals("quit")) { processVal(input); main(); } else exit(0); }There are several problems here:
java track < test5.init is the next Scanner that gets the newline, causing findWithinHorizon to return "" on the second and subsequent lines forever. Again, just create one Scanner per file.
Another problem is that Java implementations do not deal well with tail recursion. Unlike Scheme, you cannot expect a tail recursive procedure to use constant space. It matters here because the number of commands to be entered can be arbitrarily large. Use a loop instead.
Contrary to what you'll read in some books, there are perfectly good uses for == in floating point, such as
if (x == 0.0) y = 1.0; else y = Math.sin (x) / x;but they probably won't come up in this project.
The following call returns 6.574491741640564E-17 ucb.proj2.Physics.collide([0.0730206927947019, 3.360736212390728, 1.2, 2.1], [-0.17774220073960237, 3.2762901868696694, 3.232, 1.132], 0.1323). I'm not sure whether or not this value is correct, but it is so small that when subtracted from the time the simulation is supposed to run, the value does not change. That is t-6.574491741640564E-17==t is true. And so the simulator runs into an infinite loop because t is not decreasing. Is this a correct result from Physics? Or else what should I do about this problem?
Our response: It is correct, and the looping problem is not caused by the problem you mention. If you compute the new positions of the particles after this period of time, you will find that they are touching to within the precision of floating-point numbers. What should happen is that you call rebound, and it adjusts the velocities so that the next call to collide for these particles returns Infinity. The fact that this particular round did not advance t is irrelevant.
Yeah, this is kludgy, but our physics here isn't exactly "physical".
oldTime = t; t = t-collisionTime; advance things to their new positions oldTime-t from now;for the reasons you've already observed in your problem report.
Page was last modified on Mon Apr 3 20:02:42 2006.