Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm new to Mathematica and have no background whatsoever in programming, although I will teach myself soon. I was wondering if one of you programming pros could help me out. I received a code from an online source. The code is supposed to draw some form of geometry (ie: remove faces from say a cube and make a shell/pipe structure out of its edges) I was under the impression that I had to copy/paste the code in the browser and enter it for it to run. However it doesn't seem to do anything. I'm wondering if the code was meant for an old version of Mathematica, has errors in or perhaps I just don't know how to get it running. Would really appreciate if someone could help me until I get my head around Mathematica/coding.

edgeIndicesOfFace[face_] := 
 Select[Transpose[{face, RotateLeft[face]}], (#[[1]] < #[[2]]) &]; 
edgeIndices[gc_] := Apply[Join, Map[edgeIndicesOfFace, gc[[1, 2, 1]]]];
edges[gc_] := Map[vertices[gc][[#]] &, edgeIndices[gc], {2}]; 

translateVertices[name_, scale_, xyz_] := 
  Map[(xyz + #) &, scale vertices[PolyhedronData[name]]];

strut[name_, scale_, edge_] := 
 cHull[Join[translateVertices[name, scale, edge[[1]]], 
   translateVertices[name, scale, edge[[2]]]]];

edgeModel[name_, nameVertex_, scale_] := 
 Apply[Join, Map[strut[nameVertex, scale, #] &, edges[PolyhedronData[name]]]];

view[edgeModel["Cube", "Cube", .2]]

Manipulate[
 view[edgeModel[big, small, scale]], {big, PolyhedronData[All]}, {small, 
  PolyhedronData[All]}, {scale, 0.001, 1}]
share|improve this question
4  
It seems to lack of definitions of vertices, cHull, view in your code? –  Silvia Aug 4 '12 at 21:12
    
do you mean I needs an input object (eg: cube) and another to make the hull? hmmm i don't understand xD –  Jen Aug 4 '12 at 21:23
    
as @cormullion said in his answer, these functions are not built-in in Mathematica, and may be defined in earlier sections of your notebook. Without details about them, it will be hard for others to know what exactly your code do.. –  Silvia Aug 5 '12 at 11:13

1 Answer 1

I think that your 'online source' has given you only part of a longer Mathematica notebook. This extract is from a notebook by the great George Hart, who's an artist and Mathematica-gician. You'll find it in:

Procedural Generation of Sculptural Forms George W. Hart, Stony Brook University, http://www.georgehart.com, Jan 2008 This notebook contains all the examples from my Bridges 2008 paper.

Some of the functions required by your extract have been defined in earlier sections of the notebook.

The image produced by the view[] expression near the end is:

cube

Although the notebook was written for Mathematica 6, it works OK in Mathematica 8. It's better to evaluate the notebook sequentially, as sections use functions defined in earlier sections.

share|improve this answer
    
ah yes, that is what its supposed to look like. thanks for the sweet link.. I downloaded his notebook and will take a look into his other parts. I was wondering are you able to get it code to work? Do I have to include all the other parts to get this extract to work also? –  Jen Aug 4 '12 at 22:41
    
Can anyone of you recommend me any books, tutorials, rescources so I can learn programming in Mathematica in relation to geometry and make better sense of such code I posted please? –  Jen Aug 5 '12 at 0:03
1  
@Jen There's a ton of stuff on the web - your problem will be how to avoid overload. For a curated set of resource links, see mathematica.stackexchange.com/questions/18/…. –  cormullion Aug 5 '12 at 7:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.