Message Boards Message Boards

0
|
8904 Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Is PolyhedronData a list?

Posted 10 years ago

Hello,

I defined a cube as follows: One = PolyhedronData["Cube"];

And then when I execute this function: First[One], I get:

GraphicsComplex[{
{-(1/2), -(1/2), -(1/2)}, {-(1/2), -(1/2), 1/2}, 
{-(1/2), 1/2, -(1/2)}, {-(1/2), 1/2, 1/2}, 
{1/2, -(1/2), -(1/2)}, {1/2, -(1/2), 1/2}, 
{1/2, 1/2, -(1/2)}, {1/2, 1/2, 1/2}}, 

Polygon[{{8, 4, 2, 6}, {8, 6, 5, 7}, {8, 7, 3, 4}, {4, 3, 1, 2}, {1, 3, 7, 5}, {2, 1, 5, 6}}]]

This is a definition of the cube itself but shouldn't First[ ] pull out the first element of the GraphicsComplex Function?

Best, Vijay

POSTED BY: Vijay Sharma
7 Replies

Try FullForm[One] to see what a beast One is and where, in some depth of the expression tree, the points of the cube shine up. BTW, it is not advisable to use Capitalized names for user-defined quantities, since they may belong to the Wolfram Language. As you certainly know, to show your cube graphically you have to obmit the semicolon.

POSTED BY: Ulrich Mutze

Dear Ulrich,

Here are the steps: what = PolyhedronData["Cube"] And if I call "what" it gives me a cube. Then, FullForm[what], gives me a list structure. But I am not getting how if I call First[what],

I get: GraphicsComplex[{{-(1/2), -(1/2), -(1/2)}, {-(1/2), -(1/2), 1/ 2}, {-(1/2), 1/2, -(1/2)}, {-(1/2), 1/2, 1/2}, {1/ 2, -(1/2), -(1/2)}, {1/2, -(1/2), 1/2}, {1/2, 1/2, -(1/2)}, {1/2, 1/2, 1/2}}, Polygon[{{8, 4, 2, 6}, {8, 6, 5, 7}, {8, 7, 3, 4}, {4, 3, 1, 2}, {1, 3, 7, 5}, {2, 1, 5, 6}}]]

Any tips?

Best, Vijay

POSTED BY: Vijay Sharma
Posted 10 years ago

How about:

In[1]:= one = PolyhedronData["Cube"];

In[2]:= FullForm@one

Out[2]//FullForm= \!\(
TagBox[
StyleBox[
RowBox[{"Graphics3D", "[", 
RowBox[{"GraphicsComplex", "[", 
RowBox[{
RowBox[{"List", "[", 
RowBox[{
RowBox[{"List", "[", 
RowBox[{
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}]}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}]}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}]}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}]}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}]}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}]}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "2"}], "]"}]}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}]}], "]"}]}], "]"}], ",", 
RowBox[{"Polygon", "[", 
RowBox[{"List", "[", 
RowBox[{
RowBox[{"List", "[", 
RowBox[{"8", ",", "4", ",", "2", ",", "6"}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{"8", ",", "6", ",", "5", ",", "7"}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{"8", ",", "7", ",", "3", ",", "4"}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{"4", ",", "3", ",", "1", ",", "2"}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{"1", ",", "3", ",", "7", ",", "5"}], "]"}], ",", 
RowBox[{"List", "[", 
RowBox[{"2", ",", "1", ",", "5", ",", "6"}], "]"}]}], "]"}], "]"}]}], 
      "]"}], "]"}],
ShowSpecialCharacters->False,
ShowStringCharacters->True,
NumberMarks->True],
FullForm]\)

In[3]:= one[[1, 1]]

Out[3]= {{-(1/2), -(1/2), -(1/2)}, {-(1/2), -(1/2), 1/2}, {-(1/2), 1/
  2, -(1/2)}, {-(1/2), 1/2, 1/2}, {1/2, -(1/2), -(1/2)}, {1/2, -(1/2),
   1/2}, {1/2, 1/2, -(1/2)}, {1/2, 1/2, 1/2}}
POSTED BY: David Keith

Dear Vijay, First[what] would give the first element of a list if what would be a list. However, 'what' is not a list: We have Head[what]=Graphics3D and not Head[what]=List. FullForm[what], gives you an expression tree. You can access all its parts by (possibly multiple) application of index operations [[]]. Which part is obtained by 'First' seems not be entirely clear from the documentation going with First (you know how to access it conveniently?). But comparing FullForm[what] with First[one] shows which part of FullForm[what] is thrown away to arrive at First[what].

POSTED BY: Ulrich Mutze

Dear Ulrich,

I guess David's input explains it now why First[what] is giving us the first input of Graphics complex. The FullForm[what] tells as how the PolyhedronData is represented internally. If we look closely it is a list with combination of coordinates.

Best, Vijay

POSTED BY: Vijay Sharma

If you do simple InputForm:

InputForm[One]

(* Graphics3D[GraphicsComplex[{
{-1/2, -1/2, -1/2}, {-1/2, -1/2, 1/2}, 
{-1/2, 1/2, -1/2}, {-1/2, 1/2, 1/2}, 
{1/2, -1/2, -1/2}, {1/2, -1/2, 1/2}, 
{1/2, 1/2, -1/2}, {1/2, 1/2, 1/2}}, 
Polygon[{{8, 4, 2, 6}, {8, 6, 5, 7}, {8, 7, 3, 4}, {4, 3, 1, 2}, {1, 3, 7, 5}, {2, 1, 5, 6}}]]] *)

you can see that the first head is Graphics3D so First[One] will get you the argument of it which is GraphicsComplex. You can also see it as:

TreeForm[One]

enter image description here

POSTED BY: Vitaliy Kaurov

TreeForm is really useful and extremely powerful command. Thank you Vitaliy.

POSTED BY: Vijay Sharma
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract