<p>For stuff like this, OpenSCAD is your friend. There are several different approaches you could take:</p>
<ol>
<li><p>Generate an image file with grayscale color representing the height of the function on an XY grid, and use the <a href="https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Surface" rel="nofollow noreferrer"><code>surface</code></a> feature to import it as a heightmap.</p>
</li>
<li><p>Write the function as a mathematical expression in OpenSCAD language, and write a module to generate a <a href="https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#polyhedron" rel="nofollow noreferrer"><code>polyhedron</code></a> by iterating over a sufficiently fine coordiante grid, sampling the function, and producing points and triangles.</p>
</li>
<li><p>Use a library someone else has already written for this purpose. I'm not aware of specific ones but pretty sure there are quite a few.</p>
</li>
</ol>

CC BY-SA 4.0
2021-10-04T17:55:11.430Z
I try to use OpenSCAD when designing and it was my first thought when seeing the question. I have insufficient brain cells to contribute in the manner you did, however.
fred_dot_u
CC BY-SA 4.0
2021-10-04T17:02:04.450Z
2021-10-04T17:02:04.450Z
R.. GitHub STOP HELPING ICE
<p>Another option is to use <a href="https://fullcontrolgcode.com/" rel="nofollow noreferrer">Full Control Designer</a> where you can define the path using Excel formulas and it will generate the GCode for you.</p>

CC BY-SA 4.0
2021-10-11T09:54:23.720Z
2021-10-11T09:54:23.720Z
FarO
<p>Not sure what you're asking exactly, but you can use this workflow:</p>
<ol>
<li>SideFX Houdini: math function + STL file generation
<a href="https://i.sstatic.net/28jr1.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/28jr1.jpg" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/E0Itn.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/E0Itn.jpg" alt="enter image description here" /></a></li>
<li>(optional) FreeCAD: Import STL as mesh, do whatever you need to do in FreeCAD, export to STL
<a href="https://i.sstatic.net/txRno.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/txRno.png" alt="enter image description here" /></a></li>
<li>a slicer: import the STL and slice it.
<a href="https://i.sstatic.net/Ofydl.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Ofydl.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/zCxgG.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zCxgG.jpg" alt="enter image description here" /></a></li>
</ol>

CC BY-SA 4.0
2021-11-02T21:11:44.973Z
2021-11-02T21:11:44.973Z
alecail
<p>You may generate a .stl file from your mathematical definition. You may write a program using a language of your choice to compute the .stl file.</p>
<p>Your image shows a lot of rectangles, each rectangle may be described as two triangles. The .stl file is a (very long) list of all that triangles. Each triangle is defined by the X, Y, and Z coordinates of the three corners.</p>
<pre><code>solid name

facet normal ni nj nk
    outer loop
        vertex v1x v1y v1z
        vertex v2x v2y v2z
        vertex v3x v3y v3z
    endloop
endfacet

endsolid name
</code></pre>
<p>Each n or v is a floating-point number in sign-mantissa-&quot;e&quot;-sign-exponent format, e.g., &quot;2.648000e-002&quot;. The triangle vertices should be sorted using the &quot;right-hand rule&quot;, i.e. the vertices are listed in counter-clockwise order from outside.</p>
<p>The normal vector ni nj nk is set to zero.</p>
<p>The G-code file is generated from the .stl file using the slicing software for your 3D printer.</p>
<p>See <a href="https://en.wikipedia.org/wiki/STL_(file_format)" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/STL_(file_format)</a> for details.</p>

CC BY-SA 4.0
2021-10-29T12:01:54.763Z
2021-10-29T15:16:28.547Z
2021-10-29T15:16:28.547Z
Uwe
<p>Suppose I have the X, Y, and Z coordinates (either in a list or a function z = f(x,y)) that defines a shape as the one provided and I want to 3D print it with a solid bottom, is there an easy way to do this? If not, how can a functionally well-defined shape be put into a 3D modeling software like FreeCAD?</p>
<p><a href="https://i.sstatic.net/5bcSU.jpg" rel="nofollow noreferrer" title="3D graph"><img src="https://i.sstatic.net/5bcSU.jpg" alt="3D graph" title="3D graph" /></a></p>

<3d-models><cad><freecad>
How can I convert a mathematically defined shape into a 3D printable G-code file?
james
# How can I convert a mathematically defined shape into a 3D printable G-code file?

(Asked by: username_0 on 2021-10-04)

Suppose I have the X, Y, and Z coordinates (either in a list or a function z = f(x,y)) that defines a shape as the one provided and I want to 3D print it with a solid bottom, is there an easy way to do this? If not, how can a functionally well-defined shape be put into a 3D modeling software like FreeCAD?

[![3D graph](https://i.sstatic.net/5bcSU.jpg "3D graph")](https://i.sstatic.net/5bcSU.jpg "3D graph")

**Tags:** 3d-models, cad, freecad


---

## 4 answers

### Answer by username_1 on 2021-10-04. Score: 2

For stuff like this, OpenSCAD is your friend. There are several different approaches you could take:

1. Generate an image file with grayscale color representing the height of the function on an XY grid, and use the [`surface`](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Surface) feature to import it as a heightmap.
2. Write the function as a mathematical expression in OpenSCAD language, and write a module to generate a [`polyhedron`](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#polyhedron) by iterating over a sufficiently fine coordiante grid, sampling the function, and producing points and triangles.
3. Use a library someone else has already written for this purpose. I'm not aware of specific ones but pretty sure there are quite a few.

> **Comments:**
> **username_2**: I try to use OpenSCAD when designing and it was my first thought when seeing the question. I have insufficient brain cells to contribute in the manner you did, however.  

---

### Answer by username_3 on 2021-10-11. Score: 1

Another option is to use [Full Control Designer](https://fullcontrolgcode.com/) where you can define the path using Excel formulas and it will generate the GCode for you.


---

### Answer by username_4 on 2021-11-02. Score: 1

Not sure what you're asking exactly, but you can use this workflow:

1. SideFX Houdini: math function + STL file generation
   [![enter image description here](https://i.sstatic.net/28jr1.jpg)](https://i.sstatic.net/28jr1.jpg)
   [![enter image description here](https://i.sstatic.net/E0Itn.jpg)](https://i.sstatic.net/E0Itn.jpg)
2. (optional) FreeCAD: Import STL as mesh, do whatever you need to do in FreeCAD, export to STL
   [![enter image description here](https://i.sstatic.net/txRno.png)](https://i.sstatic.net/txRno.png)
3. a slicer: import the STL and slice it.
   [![enter image description here](https://i.sstatic.net/Ofydl.png)](https://i.sstatic.net/Ofydl.png)
   [![enter image description here](https://i.sstatic.net/zCxgG.jpg)](https://i.sstatic.net/zCxgG.jpg)


---

### Answer by username_5 on 2021-10-29. Score: 1

You may generate a .stl file from your mathematical definition. You may write a program using a language of your choice to compute the .stl file.

Your image shows a lot of rectangles, each rectangle may be described as two triangles. The .stl file is a (very long) list of all that triangles. Each triangle is defined by the X, Y, and Z coordinates of the three corners.

```
solid name

facet normal ni nj nk
    outer loop
        vertex v1x v1y v1z
        vertex v2x v2y v2z
        vertex v3x v3y v3z
    endloop
endfacet

endsolid name

```

Each n or v is a floating-point number in sign-mantissa-"e"-sign-exponent format, e.g., "2.648000e-002". The triangle vertices should be sorted using the "right-hand rule", i.e. the vertices are listed in counter-clockwise order from outside.

The normal vector ni nj nk is set to zero.

The G-code file is generated from the .stl file using the slicing software for your 3D printer.

See <https://en.wikipedia.org/wiki/STL_(file_format)> for details.


---

