# OpenSCAD like functionality with Mathematica?

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()
• Boolean operations on geometric objects are not supported (yet). – Yves Klett Mar 10 '13 at 7:49

## 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

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] 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] • Thanks! The approach described in that talk looks the closest to the feature set I was hoping to reproduce. – mshroyer 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"] 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"] extrude[p_Polygon, z_] :=
Module[{pts = p[]},
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"] 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.

• 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 '14 at 20:57