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 keep seeing reference to use of Mathematica as a CAD tool (for instance: http://www.makerbot.com/support/guides/design/). I'd like to use it as such if feasible, but I'm having trouble locating equivalents of the functionality I use in my current design tool, OpenSCAD.

I know how to create simple shapes (Graphics3D[], Cylinder[], etc.) and I'm aware that Mathematica can export to STL format. But does Mathematica have equivalents of the following OpenSCAD functions, or is it the wrong tool for the kind of thing I'm trying to do?

  • linear_extrude()
  • union()
  • intersection()
  • difference()
  • translate()
  • rotate()
share|improve this question
    
Boolean operations on geometric objects are not supported (yet). –  Yves Klett Mar 10 '13 at 7:49

2 Answers 2

up vote 8 down vote accepted

Quick answers to some points:

My guess is you are interested in the operations related to 3D printing. Mathematica provides computational approach - which is very general and allows to compute a lot of things. To see possibilities I would really recommend to watch Yu-Sung Chang recent talk "Scan, Convert, and Print: Playing with 3D Objects in Mathematica":

In the notebook on slide 12 you find how to define Union, Difference, Intersection. Quick sample from that slide for Difference between a cube and a sphere:

sphereQ[{x_, y_, z_}, r_, center_: {0, 0, 0}] := Norm[{x, y, z} - center] < r;

cubeQ[{x_, y_, z_}, r_] := (Abs[x] < r && Abs[y] < r && Abs[z] < r);

RegionPlot3D[
 cubeQ[{x, y, z}, 1] && \[Not] 
   sphereQ[{x, y, z}, 1, {1, 1, 1}], {x, -1, 2}, {y, -1, 2}, {z, -1, 
  2}, PlotRangePadding -> .5, Mesh -> None, PlotPoints -> 50]

enter image description here

You can do other neat things like computing and thickening thin surfaces - all this is in the video:

ParametricPlot3D[{1.16^v Cos[v] (1 + Cos[u]), -1.16^v Sin[
    v] (1 + Cos[u]), -2 1.16^v (1 + Sin[u])}, {u, 0, 2 Pi}, {v, -15, 
  6}, Mesh -> False, PlotRange -> All, PlotStyle -> Thickness[.5], 
 PlotPoints -> 35]

enter image description here

share|improve this answer
    
Thanks! The approach described in that talk looks the closest to the feature set I was hoping to reproduce. –  Niten Mar 12 '13 at 2:24

Most of these are pretty easy in Mathematica. Here are a few to get you started:

Graphics3D[{Gray, 
  Translate[
   Cylinder[{{0, 0, -1}, {0, 0, 1}}, 0.5], {{0, 0, 0}, {2, 0, 0}}]}, 
 Lighting -> "Neutral"]

enter image description here

Graphics3D[{Gray, Cylinder[{{0, 0, -1}, {0, 0, 1}}, 0.5], 
  Rotate[Cylinder[{{0, 0, -1}, {0, 0, 1}}, 0.5], \[Pi]/2, {0, 1, 0}]},
  Lighting -> "Neutral"]

enter image description here

extrude[p_Polygon, z_] := 
 Module[{pts = p[[1]]}, 
  Polygon /@ {Append[#, 0] & /@ pts, Append[#, z] & /@ pts, 
    Join[Append[#, 0] & /@ #, Append[#, z] & /@ Reverse[#]] & /@ 
     Partition[List @@ pts, 2, 1, 1]}]
pentagon = Polygon[Array[{Cos[2 \[Pi] #/5], Sin[2 \[Pi] #/5]} &, 5]];
Graphics3D[{Gray, extrude[pentagon, 2]}, Lighting -> "Neutral"]

enter image description here

A union is basically just a list of objects, but intersection and difference would take a bit more thought than I can spare tonight. I'm sure someone could cook it up in minutes, though.

share|improve this answer
    
It is worth noting that these are probably not printable objects. They aren't solid and their shell thickness is probably too thin to be translated into gcode. You can check this by limiting the plot range and inspecting the interior form. –  image_doctor Aug 5 at 20:57

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.