public static CoordinateMatrix cube(Coordinate center, Double size, Double step) 
    		throws LengthException{

        Coordinate d1 = null, d2 = null, d3 = null;

        int numberOfRows = 4;
        int numberOfColumns = (int) Math.ceil(Math.pow(size / step, 3));

        if (center.getLength() != numberOfRows) {
            throw new LengthException("The vector must be of size 4.");
        }

        try {
            d1 = new Coordinate(new double[] {1.0, 0.0, 0.0});
            d2 = new Coordinate(new double[] {0.0, 1.0, 0.0});
            d3 = new Coordinate(new double[] {0.0, 0.0, 1.0});
        } catch (LengthException e) {
            assert false : "Fatal programming error";
        }

        CoordinateMatrix newMatrix = new CoordinateMatrix(numberOfRows,
                                                          numberOfColumns);

        Coordinate point = new Coordinate(new double[] {
            center.get(0)-(size/2), center.get(1)-(size/2), center.get(2)-(size/2)    
        });

        CoordinateMatrix.Iterator matrixIterator = newMatrix.new Iterator();

        for (Double i = 0.0; i < size; i += step) {
            for (Double j = 0.0; j < size; j += step) {
                for (Double k = 0.0; k < size; k += step) {
                    try {
                        matrixIterator.set(point.add(d1.mul(i).add(d2.mul(j)).add(d3.mul(k))));
                        matrixIterator.next();
                    } catch (IteratorException e) {
                        assert false : "Fatal programming error";
                    } catch (LengthException e) {
                        assert false : "Fatal programming error";
                    }
                }
            }
        }
        return newMatrix;
    }