Broke things out into files, adding some basic functionality to allow
Broke things out into files, adding some basic functionality to allow
creating nodes in a quasi-meaningful arrangement.

file:b/Coords.php (new)
--- /dev/null
+++ b/Coords.php
@@ -1,1 +1,80 @@
+<?php 
+abstract class Coords {
+	// This is a stub that may contain functions or parameters that apply universally to all coordinate systems,
+	// but may never be instantiated itself.
+}
 
+class SphericalCoords extends Coords {
+	public function __construct($r, $t, $p) {
+		$this->radius = $r;
+		$this->theta = $t;
+		$this->phi = $p;
+			
+		return $this;
+	}
+
+	public function triplet() {
+		return array(
+		$this->radius,
+		$this->theta,
+		$this->phi
+		);
+	}
+
+	public function to_Cartesian() {
+		return new CartesianCoords(
+			$this->radius * sin($this->theta) * cos($this->phi),
+			$this->radius * sin($this->theta) * sin($this->phi),
+			$this->radius * cos($this->theta)
+		);
+	}
+
+	protected $radius = 0;
+	protected $theta  = 0;
+	protected $phi = 0;
+}
+
+class CartesianCoords extends Coords {
+	public function __construct($x, $y, $z) {
+		$this->x = $x;
+		$this->y = $y;
+		$this->z = $z;
+		 
+		return $this;
+	}
+	 
+	public function triplet() {
+		return array(
+		$this->x,
+		$this->y,
+		$this->z
+		);
+	}
+	 
+	public function to_Spherical() {
+		$r = pow($this->x,2) * pow($this->y,2) * pow($this->z,2);
+		$t = acos($this->z / $r);
+		$p = acos($this->y / $this->x);
+		return new SphericalCoords($r, $t, $p);
+	}
+	 
+	protected $x = 0;
+	protected $y = 0;
+	protected $z = 0;
+}
+
+class LinearCoords extends CartesianCoords {
+	public function __construct($d) {
+		// make a car;tesian object, with just one axis
+		$this->y = 0;
+		$this->z = 0;
+		$this->x = $d;
+		 
+		return $this;
+	}
+	
+	public function magnitude() {
+		return $this->x;
+	}
+}
+?>

--- a/SpaceNode.php
+++ b/SpaceNode.php
@@ -1,143 +1,94 @@
 <?php

-	class SpaceNode {

-		public function __construct($name, $radius, $coords, $ultra = null) {

-			$this->name = $name;

-   		    $this->mean_radius = $radius;

-		    $this->relative_coords = $coords;

-		    if (is_object($ultra)) {

-		        //add the ultra node as a parent

-				$this->ultra = $ultra;

-		    } else {

-		        // If we don't have an ultra node, we should belong to the universe.

-		        if (is_object($GLOBALS["universe"])) {

-		            $this->ultra = $GLOBALS["universe"];

-		        // If there is no universe, WE ARE THE UNIVERSE.

-		        } else {

-		            $GLOBALS["universe"] = $this;

-		        }

-		    }

-		    

-		    $this->id = uniqid();

-		    

-			return $this;

+class SpaceNode {

+	public function __construct($name, $radius, $coords, $ultra = null) {

+		$this->name = $name;

+		$this->mean_radius = $radius;

+		$this->relative_coords = $coords;

+		if (is_object($ultra)) {

+			//add the ultra node as a parent

+			$this->ultra = $ultra;

+			$this->ultra->add_infra($this);

+		} else {

+			// If we don't have an ultra node, we should belong to the universe.

+			if (!empty($GLOBALS["universe"]) && is_object($GLOBALS["universe"])) {

+				$this->ultra = $GLOBALS["universe"];

+				// If there is no universe, WE ARE THE UNIVERSE.

+			} else {

+				$GLOBALS["universe"] = $this;

+			}

 		}

-		

-		public change_ultra($ultra) {

-		    // remove from the current parent

-		    if ($this->ultra->remove_infra($this)) {

-		        // add to the new parent

-		        if ($ultra->add_infra($this)) {

-		            // change the parent

-		            $this->ultra = $ultra;

-		        }

-		    }

-		}

-		

-		public add_infra($infra) {

-		    if (empty($this->child_list[$infra->id()])) {

-		        $this->child_list[$infra->id()] = $infra;

-		    } else {

-		        throw new Exception("Tried to add duplicate child object '" . $infra->name() . "'to '" . $this->name . "'");

-		    }

-		}

-		

-		public remove_infra($infra) {

-		    if (!empty($this->child_list[$infra->id()])) {

-		        unset($this->child_list[$infra->id()]);

-		    } else {

-		        throw new Exception("Tried to remove non-child object '" . $infra->name(). "' from '" . $this->name . "'");

-		    }

-		}

-		

-		protected $name = "";

-		protected $id = "";

-		protected $child_list = array();

-		protected $super = null;

-		protected $mean_radius = 0;

-		protected $relative_coords = null;

+

+		$this->id = uniqid();

+

+		return $this;

 	}

 	

-	abstract class Coords {

-	    // This is a stub that may contain functions or parameters that apply universally to all coordinate systems,

-	    // but may never be instantiated itself.

-	    

+	public function name() {

+		return $this->name;

+	}

+

+	public function change_ultra($ultra) {

+		// remove from the current parent

+		if ($this->ultra->remove_infra($this)) {

+			// add to the new parent

+			if ($ultra->add_infra($this)) {

+				// change the parent

+				$this->ultra = $ultra;

+			}

+		}

 	}

 	

-	class SphericalCoords extends Coords {

-		public function __construct($r, $t, $p) {

-			$this->radius = $r;

-			$this->theta = $t;

-			$this->phi = $p;

-			

-			return $this;

+	public function get_ultra() {

+		return $this->ultra;

+	}

+

+	public function add_infra($infra) {

+		if (empty($this->child_list[$infra->name()])) {

+			$infra_r = $infra->get_location(T_DNUMBER) + $infra->get_radius();

+			if ($infra_r > $this->mean_radius) {

+				$this->grow_radius($infra_r);

+			}

+			$this->child_list[$infra->name()] = $infra;

+		} else {

+			throw new Exception("Tried to add duplicate child object '" . $infra->name() . "'to '" . $this->name . "'");

 		}

-		

-		public function triplet() {

-			return array(

-				$this->radius,

-				$this->theta,

-				$this->phi

-				);

+	}

+

+	public function remove_infra($infra) {

+		if (!empty($this->child_list[$infra->id()])) {

+			unset($this->child_list[$infra->id()]);

+		} else {

+			throw new Exception("Tried to remove non-child object '" . $infra->name(). "' from '" . $this->name . "'");

 		}

-		

-		public function to_Cartesian() {

-		    return new CartesianCoords(

-		    	$this->radius * sin($this->theta) * cos($this->phi),

-		    	$this->radius * sin($this->theta) * sin($this->phi),

-		    	$this->radius * cos($this->theta)

-		    );

-		}

-		

-		protected $radius = 0;

-		protected $theta  = 0;

-		protected $phi = 0;

 	}

 	

-	class CartesianCoords extends Coords {

-	    public function __construct($x, $y, $z) {

-	        $this->x = $x;

-	        $this->y = $y;

-	        $this->z = $z;

-	        

-	        return $this;

-	    }

-	    

-	    public function triplet() {

-	        return array(

-	        	$this->x,

-	        	$this->y,

-	        	$this->z

-	        	);

-	    }

-	    

-	    public function to_Spherical() {

-	        $r = pow($this->x,2) * pow($this->y,2) * pow($this->z,2);

-	        $t = acos($this->z / $r);

-	        $p = acos($this->y / $this->x);

-	        return new SphericalCoords($r, $t, $p);

-	    }

-	    

-	    protected $x = 0;

-	    protected $y = 0;

-	    protected $z = 0;

+	protected function grow_radius($new_r) {

+		$this->mean_radius = $new_r;

 	}

 	

-	class LinearCoords extends CartesianCoords {

-	    public function __construct($d) {

-	        // make a car;tesian object, with just one axis

-	        $this->y = 0;

-	        $this->z = 0;

-	        $this->x = $d;

-	        

-	        return $this;

-	    }

-	    

-	    public funct_d($d) {

-

-		protected $distance = 0;

+	public function get_radius() {

+		return $this->mean_radius;

 	}

 	

-	    //Do we need a 

-	$universe = new SpaceNode("universe node", 50, new LinearCoords(0), null);

-	

+	public function get_location($type) {

+		list($a, $b, $c) = $this->relative_coords->triplet();

+		switch ($type) {

+			case T_STRING:

+				return "x = $a, y = $b, z = $c";

+				break;

+			case T_DNUMBER:

+				return $this->relative_coords->magnitude();

+			default:

+				break;

+		}

+	}

+

+	protected $name = "";

+	protected $id = "";

+	protected $child_list = array();

+	protected $ultra = null;

+	protected $mean_radius = 0;

+	protected $relative_coords = null;

+}

+

 ?>

file:b/UniSim.php (new)
--- /dev/null
+++ b/UniSim.php
@@ -1,1 +1,14 @@
+<?php
 
+require_once("SpaceNode.php");
+require_once("Coords.php");
+
+$universe = new SpaceNode("universe node", 0, new LinearCoords(0), null);
+printf("Made new node '%s' with radius %.2g at coordinates %s.\n", $universe->name(), $universe->get_radius(), $universe->get_location(T_STRING));
+
+$node1 = new SpaceNode("node1", 40, new LinearCoords(40), $universe);
+printf("Made new node '%s' with parent '%s' with radius %.2g at coordinates %s.\n", $node1->name(), $node1->get_ultra()->name(), $node1->get_radius(), $node1->get_location(T_STRING));
+
+printf("'%s' has new radius %.2f\n", $universe->name(), $universe->get_radius());
+
+?>