Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting points in Mathematica

I have a collection of points displayed in a graphic:

alt text http://img69.imageshack.us/img69/874/plc1k1lrqynuyshgrdegvfy.jpg

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 http://img341.imageshack.us/img341/5926/tr53exnkpeofcuiw40koyks.jpg (I am not asking how to implement the algorithm myself!).

Thanks

like image 359
devoured elysium Avatar asked Nov 27 '09 10:11

devoured elysium


2 Answers

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.

like image 137
dreeves Avatar answered Oct 07 '22 03:10

dreeves


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}]
like image 42
Pillsy Avatar answered Oct 07 '22 04:10

Pillsy