3
$\begingroup$

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[{
   Translate[
    Rotate[First[scw], 2 Pi , {0, 0, 1}], {1, 0.8, -1}] ,
   Translate[
    Rotate[First[scw], 2 Pi , {0, 0, 1}], { 3, 1, -1}],
   Translate[
    Rotate[First[scw], 2 Pi , {0, 0, 1}], {5, 1.1, -1}] ,
   Translate[
    Rotate[First[scw], 2 Pi , {0, 0, 1}], {7, 0.7, -1}] ,
   Translate[
    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.

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – mfvonh Aug 24 '14 at 4:35
  • $\begingroup$ user16069: please consider choosing a more "human" user name. Thanks! $\endgroup$ – Mr.Wizard Aug 24 '14 at 9:00
  • $\begingroup$ Yes, from now on I'll call myself "Putterboy". $\endgroup$ – Putterboy Aug 25 '14 at 4:11
5
$\begingroup$

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

screws

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.

$\endgroup$
  • $\begingroup$ Thanks a lot, and I see that the rotations in my code are completely not necessary. $\endgroup$ – Putterboy Aug 24 '14 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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