MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: planar polygon plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16619] Re: [mg16442] Re: planar polygon plot
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Fri, 19 Mar 1999 12:53:47 -0500
  • References: <7cngie$4tp$8@dragonfly.wolfram.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Richard S Hsu wrote in message <7cngie$4tp$8 at dragonfly.wolfram.com>...
>Dear Allan,
>Thank you for help.
>I tried
>
>   Show[ Graphics3D[ Polygon[ { {0,0,0}, {1,0.5,0}, {2,0,0},
>   {2,2,0}, {1,1.5,0}, {0,2,0} } ] /.Polygon[lst_]:>
>   {Line[#],EdgeForm[], Polygon[ Prepend[#,
>       Plus@@lst/Length[lst]]]}&[Append[lst,First[lst]] ]   ] ];
>
>It works, but get a error message:
>
>First::normal: Nonatomic expression expected at position 1 in
>First[lst].
>Append::normal:
>   Nonatomic expression expected at position 1 in Append[lst, First[lst]].
>
>I want to know why.
>
>Richard Hsu
>

Dear Richard,
Thanks for pointing this out.

I should have use some parentheses:

Polygon[ { {0,0,0}, {1,0.5,0}, {2,0,0},
{2,2,0}, {1,1.5,0}, {0,2,0} } ] /.Polygon[lst_]:>
(
   {Line[#],EdgeForm[], Polygon[ Prepend[#,
Plus@@lst/Length[lst]]]}&[Append[lst,First[lst]]
    ]
)

The first step with this is the following (where {..} stands for the list of
points)

Polygon[{Line[#],EdgeForm[], Polygon[ Prepend[#,
Plus at {..}/Length[{..}]]]}
)&[Append[{..},First[{..}]] ]]


But the code as posted

Polygon[ { {0,0,0}, {1,0.5,0}, {2,0,0},
{2,2,0}, {1,1.5,0}, {0,2,0} } ] /.Polygon[lst_]:>
{Line[#],EdgeForm[], Polygon[ Prepend[#,
Plus@@lst/Length[lst]]]}&[Append[lst,First[lst]] ]

Parses as
(
Polygon[ { {0,0,0}, {1,0.5,0}, {2,0,0},
{2,2,0}, {1,1.5,0}, {0,2,0} } ] /.Polygon[lst_]:>
{Line[#],EdgeForm[], Polygon[ Prepend[#,
Plus@@lst/Length[lst]]]}
)&[Append[lst,First[lst]] ]

Append[lst,First[lst]]  is evaluated and gives the messages.
Then the unaltered expression is taken insde the function.
(
Polygon[ { {0,0,0}, {1,0.5,0}, {2,0,0},
{2,2,0}, {1,1.5,0}, {0,2,0} } ] /.Polygon[lst_]:>
{Line[Append[lst,First[lst]],EdgeForm[],
              Polygon[ Prepend[Append[lst,First[lst],
Plus@@lst/Length[lst]]]}
)
The evaluation of this gives the result required but, besides the messages,
this code is less efficient, involving, for example, an extra use of Append.


Regards,

Allan

.---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


Allan








  • Prev by Date: Header/Footer settings in StyleSheets
  • Next by Date: Re: Manipulating Solutions
  • Previous by thread: Re: Re: planar polygon plot
  • Next by thread: creating a frontend