Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I got a screw .obj model with the head diameter of 2cm, and a board .obj model of 10cmx10cmx4cm in dimension. I would like the screw duplicated in 25 copies painted with different color and "screw" on the board in an array of 5x5 with random heights. How can I attain this in Mathematica?

enter image description here

(* assuming the .obj files are located in the c: root *)
scw = Import["c:\\screw.obj"];
brd = Import["c:\\board.obj"];
Show[brd, Graphics3D[{
    Rotate[First[scw], 2 Pi , {0, 0, 1}], {1, 0.8, -1}] ,
    Rotate[First[scw], 2 Pi , {0, 0, 1}], { 3, 1, -1}],
    Rotate[First[scw], 2 Pi , {0, 0, 1}], {5, 1.1, -1}] ,
    Rotate[First[scw], 2 Pi , {0, 0, 1}], {7, 0.7, -1}] ,
    Rotate[First[scw], 2 Pi , {0, 0, 1}], {9, 1.0, -1}] 

With the code shown above, I got something like this:

enter image description here

I need a better(faster) way to do this, and need to knew how to "paint" the nails and the board.

share|improve this question
I don't understand what exactly you mean by "screw on the board". Do you mean align the screw so the head is flush with a face of the board? Can you show what you have tried so far, or what you are having difficulty with? – mfvonh Aug 24 '14 at 4:35
user16069: please consider choosing a more "human" user name. Thanks! – Mr.Wizard Aug 24 '14 at 9:00
Yes, from now on I'll call myself "Putterboy". – Putterboy Aug 25 '14 at 4:11
up vote 5 down vote accepted

How about this:

s = Import["screw.obj"];

b = Import["board.obj"];

scr = First[s];
brd = First[b];

screwList = 
  Table[{Hue[(5 i + j)/25], 
    Translate[scr, {2 i - 1, RandomReal[{-.5, 2}], 1 - 2 j}]}, {i, 
    5}, {j, 5}];

Graphics3D[Join[{Brown, brd}, screwList],Lighting->"Neutral"]


I added the board to the same Graphics3D as the screws, instead of using Show. Also, I abbreviated the application of First, and used colors from Hue. The "height" measured from the board is a random number.

share|improve this answer
Thanks a lot, and I see that the rotations in my code are completely not necessary. – Putterboy Aug 24 '14 at 5:10

Your Answer


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.