MathGroup Archive 1999

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

Search the Archive

Re: planar polygon plot 2

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16555] Re: planar polygon plot 2
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 16 Mar 1999 04:00:24 -0500
  • References: <7c6fad$i0s$7@dragonfly.wolfram.com> <7cjmh8$5q9$2@dragonfly.wolfram.com>
  • Sender: owner-wri-mathgroup at wolfram.com

In the posting copied below the line ***********************
Adam Smith writes
>I am not sure what you mean by the shading being off.  But try changing the
>order of the points.  I think the input below will produce what you want. I
>found it by trial and error -  I don't understand why it makes a difference
to
>Mathematica.

Adam:

In 3D the polygon poly = Polygon[{p1,p2,p3,p4....pn}} is shown by

1) drawing the line Line[{p1,p2,p3,p4....pn,p1}] as its edge;
2) drawing the triangles Polygon[{p1,p2,p3}], Polygon[{p1,p3,p4}], ..,
Polygon[{p1,p(n-1),pn}] with the coloring given to the first one and without
edges.

Not all planar polygons can be shown satisfactorily in 3D by choosing the
first point; for example

Show[Graphics3D[ Polygon[{{0,0,0},
{3,0,0},{2,3,0},{2,1,0},{1,1,0},{1,3,0}}],
ViewPoint -> {0,0,5}]

( 3D version of
Show[Graphics[Polygon[{{0, 0}, {3, 0}, {2, 3}, {2, 1}, {1, 1}, {1, 3}}]]]
)

The method that I gave earlier (triangulating from the centroid) does not
work for this polygon either.

I am grateful to Richard Hsu for letting me know that although my coding of
this was working it was also generating warning messages.
It turns out that I should have some parentheses to deal with the way (...)&
grabs expression on its right:

It should have been

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]]]
    )
]]

instead of

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]]]

]]

The latter is also less efficient

---------------------
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

****************************************************************************
**
adam.smith at hillsdale.edu wrote in message
<7cjmh8$5q9$2 at dragonfly.wolfram.com>...
>In article <7c6fad$i0s$7 at dragonfly.wolfram.com>,
>  Richard S Hsu <rhsu at U.Arizona.EDU> wrote:
>> Hi,
>>
>> I want to plot a planar polygon in 3D with shading.
>> when the polygon is concave, the shading could be wrong.
>>
>> For a simple example:
>>
>>  Show[ Graphics3D[ Polygon[ { {0,0,0}, {1,0.5,0}, {2,0,0},
>>        {2,2,0}, {1,1.5,0}, {0,2,0} }  ]  ]  ];
>>
>> I know what Mathematica is doing here, but want to know
>> if there is a easy way to get correct shading for general
>> 3D planar polygons.
>>
>> Thanks
>>
>>
>
>I am not sure what you mean by the shading being off.  But try changing the
>order of the points.  I think the input below will produce what you want. I
>found it by trial and error -  I don't understand why it makes a difference
to
>Mathematica.
>
>Show[ Graphics3D[  Polygon[ {  {1,0.5,0}, {2,0,0}, {2,2,0}, {1,1.5,0},
>{0,2,0},{0,0,0} } ]  ];
>
>Adam Smith





  • Prev by Date: Re: Interpolation of 3D data problem
  • Next by Date: Re: Modulus Question
  • Previous by thread: Re: Real variables (i.e. non-complex)
  • Next by thread: FrontEndExecute returns Null