<--1D implementation ^--systems--^ 3D implementation-->

Masses and Springs

2D

Two dimensions lends itself to much more useful representation. Anything that can be represented on a plane is now possible with two dimensions. Anything with two axes of location can also now be shown. Also, single-dimension directional relationships, such as files IN directories, can be represented in a left-to-right or top-to-bottom method if desired.

For our purposes, though, we're using the second dimension to allow the Masses and Springs to spread out from each other, especially if one Mass has many other Masses attached to it. Let's take a look at the new classes in 2D.

Extended classes

Vector2d

As mentioned before, the 2D classes all inherit from their 1D counterparts. For now, using them together throws an exception, but that can be relaxed to allow them to work in harmony. After all, there's no reason a 2D object can't act like a 1D one.

Vector2d provides two-dimension positioning in Cartesian space. As mentioned before, there's no requirement that locations are in Cartesian space, but for now, all I've implemented is the good old X and Y that we all know and love.

While this might be jumping the gun a bit, one system I might try is the IP address space, which can be seen as a four-dimensional space, one for each of the octets you may be used to seeing, such as 136.159.5.15. This would definitely make any kind of Internet or network system easy to implement from the Collector's point-of-view, but would make the Physics and Viewer interesting -- how do IP addresses interact? And how do you display the four-dimensional data on a two-dimensional screen? Food for thought.

RandomCollector2d

Very similar to its 1D version, RandomCollector2d picks pairs of random numbers to place new data into the system.

StaticCollector2d

This collector is of limited value, as it always creates the same Masses and Springs each time. Where it is useful, however, is in testing your Physics implementation. Having the same dataset available lets you tweak your Physics and compare the result with previous attempts, where using a RandomCollector doesn't allow this.

WebAccessCollector2d

Finally we've got a Collector that does something useful! This class takes a gzipped copy of an access logfile from an Apache web server, and makes Masses out of the requesting IP address and the URL that is requested. The IP Masses have their starting location computed from the IP value, and the URL Masses use random locations. A Spring is, of course, created for each IP/URL pair in the file.

SimplePhysics2d

A 2D version of SimplePhysics1D. Not much more to say about it!

BetterPhysics2d

This is an attempt to have a better Physics system. Note that I said attempt. More on that later. Momentum was the biggest addition over the SimplePhysics, to give it a more realistic look and quicker stabilization.

TextViewer2d

Just like TextViewer1d, but in two dimensions. This makes it a little unwieldy, but is still a nice quick tester. As the 1D version, it zooms in and out to accommodate the domain and range of the Masses.

GraphicViewer2d

Finally we're getting somewhere. This is heavily based on the Viewer portion of the first implementation of this system. It, too, zooms in and out to encompass all of the data points, using a grey grid to visually indicate the automatic zooming. There is no interaction from the user in this Viewer.
The code that uses these newer 2D versions is practically the same as the 1D code seen earlier, with some ones changed to twos. Here's a sample of the RandomCollector2d, SimplePhysics2d and TextViewer2d:
...........*.........*...................
.........................................
.........................................
.........................................
.........................................
.........................................
.........................................
.................*.......................
.........................................
...*.....................................
.........................................
.............................*...........
.............*...........................
.........................................
.........................................
.........................................
....*................*...................
.........................................
.........................................
.................*.........*...*.........
.........................................
.........................................
...................................*.....
.........................................
.........................................
..................*......................
.........................................
*...............................*........
........*...............................*
.........................................
.............................*...........
.........................................
.........................................
.........................................
............*............................
.........................................
........................*................
.........................................
.........................................
.........................................
.........................................
  minx=-94.15333954691457 maxx=864.533462422671 width=958.6868019695856
  miny=-239.0157764473397 maxy=631.0180539629421 width=870.0338304102818
And here's a screenshot of RandomCollector2d, SimplePhysics2d and GraphicViewer2d:

Here's the WebAccessCollector2d in action. You might be able to make out some faint grey lines coming from an invisible Mass in the center -- that Mass was inserted to hold all of the Masses together, since as you can see, not all of the Masses and Springs are related (there are a lot of single green lines), and I didn't want my data to float away forever, constantly being pushed away by the other Masses.

Here's a JAR with the above-mentioned classes, including the test programs above.
<--1D implementation ^--systems--^ 3D implementation-->

©2002-2017 Wayne Pearson