12
$\begingroup$

I keep seeing reference to use of Mathematica as a CAD tool (for instance, this). 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()
$\endgroup$
1
  • $\begingroup$ Boolean operations on geometric objects are not supported (yet). $\endgroup$
    – Yves Klett
    Commented Mar 10, 2013 at 7:49

2 Answers 2

16
$\begingroup$

UPDATE

With release of Mathematica 10 built-in functionality we have new things and continue to add - please see:

Geometric Computation examples

Geometric Computation guide

Especially: Derived Geometric Regions

OLDER

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

$\endgroup$
1
  • $\begingroup$ Thanks! The approach described in that talk looks the closest to the feature set I was hoping to reproduce. $\endgroup$
    – mshroyer
    Commented Mar 12, 2013 at 2:24
6
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ Commented Aug 5, 2014 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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