Re: How to roll up multiple Line calls into a loop
- To: mathgroup at smc.vnet.net
- Subject: [mg118350] Re: How to roll up multiple Line calls into a loop
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 23 Apr 2011 07:51:38 -0400 (EDT)
gr = Graphics[{ Line[{{0, 10}, {1, 0}}], Line[{{0, 9}, {2, 0}}], Line[{{0, 8}, {3, 0}}], Line[{{0, 7}, {4, 0}}], Line[{{0, 6}, {5, 0}}], Line[{{0, 5}, {6, 0}}], Line[{{0, 4}, {7, 0}}], Line[{{0, 3}, {8, 0}}], Line[{{0, 2}, {9, 0}}], Line[{{0, 1}, {10, 0}}]}] End points: endPts = Cases[gr, Line[pts__] :> Last[pts], Infinity] {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {10, 0}} Start points: startPts = Cases[gr, Line[pts__] :> First[pts], Infinity] {{0, 10}, {0, 9}, {0, 8}, {0, 7}, {0, 6}, {0, 5}, {0, 4}, {0, 3}, {0, 2}, {0, 1}} gr = Graphics[Line /@ Thread[{startPts, endPts}]] True Bob Hanlon ---- Sol Lederman <sol.lederman at gmail.com> wrote: ============= Hi, I'm new to Mathematica. I have the following bit of graphics: Graphics[{ Line[{{0, 10}, {1, 0}}], Line[{{0, 9}, {2, 0}}], Line[{{0, 8}, {3, 0}}], Line[{{0, 7}, {4, 0}}], Line[{{0, 6}, {5, 0}}], Line[{{0, 5}, {6, 0}}], Line[{{0, 4}, {7, 0}}], Line[{{0, 3}, {8, 0}}], Line[{{0, 2}, {9, 0}}], Line[{{0, 1}, {10, 0}}], }] I want to simplify it to do some sort of iteration to compute the end points of the lines. I can do this easily in a variety of procedural languages but I haven't yet grokked how Mathematica would do this. Would someone please show me the short way, I imagine using Table somehow? Thanks. Sol