tags:

views:

119

answers:

3

I have a collection of points displayed in a graphic:

alt text

I'd like to know if there is any command that will connect them automatically along the xx and yy axis. This can be better understood looking at the following picture: alt text (I am not asking how to implement the algorithm myself!).

Thanks

+4  A: 

I suspect the answer is no, there's no such command. It would be interesting to write something to do that though, ie, given a list of points, output the corresponding lines. I guess that would just be a matter of:

For each unique x-coordinate get the list of y-coordinates for points with that x-coordinate and make a line from the min to the max y-coordinate. Then repeat for the y-coordinates.

If you do that, it would be interesting to post it here as a follow-up. Or if you want to make that the question, I'm sure you'll get some nice solutions.

dreeves
+2  A: 

Some of what you are looking for is in the ComputationalGeometry Package. In particular, ConvexHull will give you the outer points listed in counterclockwise direction. At which point you can use Line to connect them together. The inner paths are a bit trickier, and I don't think there is an exact match. But, a DelaunayTriangulation comes closest. It essentially breaks your list of points up into sets of triangles. I don't know of a built in function that would break it into rectangles, though.

rcollyer
+2  A: 

I vote for dreeves' suggestion. It doesn't use a "built-in" function, but it's a one-liner using functional programming and level specifications. An implementation is:

gridify[pts : {{_?NumericQ, _?NumericQ} ...}] :=
  Map[Line, GatherBy[pts, #]& /@ {First, Last}, {2}]
Pillsy
Nice. Simple and clean.
rcollyer