<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Shape generator]]></title><description><![CDATA[<p dir="auto">While working on the design below in OpenSCAD, I realized that Boolean construction of a shape can become a bit counter intuitive when you start working with curves. The bottom of this box curves up but the curve is elliptical as well as the curves on either side. All curves are tangential to each other.<br />
<img src="/assets/uploads/files/1612565894259-frame.png" alt="frame.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">In order to construct shapes easily, I have been looking for a code based way to generate a shape outline.  For that I have been taking queues from the <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths" rel="nofollow ugc">SVG path specifications</a> where you start at a given point and a sequence of instructions defines the path. I like that those commands can use either relative or absolute coordinates depending on the command.</p>
<p dir="auto">However, I also want easy ways to fillet or chamfer corners, tangent align an arc to another line or arc and so on.</p>
<p dir="auto">Some thoughts:</p>
<ul>
<li>Shape generator gives me a points list or a polygon.</li>
<li>All points to be calculated without the use of boolean construction.</li>
<li>Commands need to be high level. A render step is required at the end.</li>
<li>Didn't think about constraints much but edges could be named and referenced.</li>
</ul>
<p dir="auto">Consider this shape:</p>
<p dir="auto"><img src="/assets/uploads/files/1612563197791-shape.png" alt="shape.png" class=" img-responsive img-markdown" /></p>
<p dir="auto">The code could look like this compliant with <a href="https://jscad.xyz/docs/tutorial-01_gettingStarted.html" rel="nofollow ugc">JSCAD Conventions...</a> which states function parameters should be passed as a JSON object.</p>
<pre><code>var boxWidth = 50;
var boxLength = 100;
var boxHeight = 40;
var boxCut = 15;
var boxRadius = 30;
      
//  Sets start point and global fillet parameter for all edge joins
Shape.init({point:[3,4], fillet:2});

//  move to point relative from the init point and fillet that corner with given value
Shape.move({point:[-boxWidth/2,-boxHeight/2], fillet:6});

//  draws vertically along y axis by given distance and chamfer that corner with given value
Shape.vert({dist:boxWidth, chamfer:6});

//  draws horizontally along y axis by given distance
Shape.horz({dist:boxLength - 15});

//  draws an arc tangential to the previous edge to given point with given radius. Other parameters can modify that behavior.
Shape.arc ({point:[15,15], radius: boxRadius});

//  draws vertically along y axis by given distance and chamfer that corner with given value
Shape.vert({d:-boxWidth + 15});

var boxPolygon = polygon(Shape.points);
//or
var boxPolygon = Shape.polygon;
</code></pre>
<p dir="auto">The "JSCAD Conventions..." cause us to loose Autocomplete and code suggestion in our editors though. But as we use JSON notation we might as well do the whole thing like that.</p>
<pre><code>      var boxWidth = 50;
      var boxLength = 100;
      var boxHeight = 40;
      var boxCut = 15;
      var boxRadius = 30;
      
      Shape.steps = [
        { c: 'start', point:[0,0], fillet:2 },
        { c: 'move', point:[-boxWidth/2,-boxHeight/2], fillet:6 },
        { c: 'vert', dist:boxWidth, chamfer:6 },
        { c: 'horz', dist:boxLength - boxCut },
        { c: 'arc', point:[boxCut,-boxCut], r: boxRadius },
        { c: 'vert', dist: -boxWidth + boxCut}
      ]

      var boxPolygon = polygon(Shape.points);

      //or

      var boxPolygon = Shape.polygon;
</code></pre>
<p dir="auto">Of course now you loose even more of the editors autocomplete logic. But it's clean and very versatile.</p>
<p dir="auto">Essentially the command list represents the edges of the shape. From here we can even start to look at edge fillet etc.</p>
<p dir="auto">Note: A fillet cuts into the corner while an arc starts and ends at a precise coordinate.</p>
<p dir="auto">The shape generator should also have turtle like behavior such as</p>
<pre><code>Shape.turn({angle: 20});   //  turns relative to the current direction
Shape.Turn({angle:20});    //  sets current direction to angle value
Shape.forward({dist:25});  //  draws line in current direction

//Capitalization of a command determines relative or absolute behavior where sensible.
</code></pre>
<p dir="auto">Not even sure if code like this should be an external library of incorporated in JSCAD.<br />
I love to hear what you guys think of the whole shape generator thing.</p>
]]></description><link>https://openjscad.nodebb.com/topic/227/shape-generator</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 21:27:47 GMT</lastBuildDate><atom:link href="https://openjscad.nodebb.com/topic/227.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 05 Feb 2021 23:04:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Shape generator on Tue, 09 Feb 2021 23:10:39 GMT]]></title><description><![CDATA[<p dir="auto">I have had similar thoughts about getting a drawing tool like this into jscad, I believe it could not only be useful for extruding simple shapes, but also, if constraints are possible, for the layout of all sorts of things.</p>
<p dir="auto">This project looks interesting <a href="https://github.com/IjzerenHein/kiwi.js" rel="nofollow ugc">https://github.com/IjzerenHein/kiwi.js</a> .. though I admit I dont quite understand how you would get anything complicated into the calculations.</p>
]]></description><link>https://openjscad.nodebb.com/post/668</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/668</guid><dc:creator><![CDATA[Dunk Fordyce]]></dc:creator><pubDate>Tue, 09 Feb 2021 23:10:39 GMT</pubDate></item><item><title><![CDATA[Reply to Shape generator on Mon, 08 Feb 2021 23:36:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://openjscad.nodebb.com/uid/520">@Dinther</a> Excellent! I didn’t know about constraints as well. Interesting...</p>
<p dir="auto">But the example is horrid to read, and even worse to understand. <img src="https://openjscad.nodebb.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f632.png?v=k4h1pp0pk3c" class="not-responsive emoji emoji-android emoji--astonished" title=":astonished:" alt="😲" /></p>
<p dir="auto">Maybe that’s why SVG has adopted a more simple approach to defining paths. Simple is best and even better if it actually makes sense to ordinary people.</p>
<p dir="auto">Having said that... the underlying implementation could use a constraints based object, and there could be a simple API above that. For example, users don’t use mat4 (matrix) but the transforms create matrices for all operations on geometry.</p>
]]></description><link>https://openjscad.nodebb.com/post/667</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/667</guid><dc:creator><![CDATA[z3dev]]></dc:creator><pubDate>Mon, 08 Feb 2021 23:36:59 GMT</pubDate></item><item><title><![CDATA[Reply to Shape generator on Mon, 08 Feb 2021 00:31:18 GMT]]></title><description><![CDATA[<p dir="auto">I had never heard of maker.js That is an impressive piece of kit although I found it very hard to read the code for their sample models. Pulled a bunch of good ideas from it though.</p>
<p dir="auto">In my initial post I had not considered constraints.</p>
<p dir="auto">That might be a mistake. I picked up FreeCAD again and spend some time learning to use a constraint system. Blame it to years of using grid systems but only now the penny drops that with constraints you have no need for coordinates!</p>
<p dir="auto">Looked around for some javascript based solvers and only found <a href="https://github.com/tmpvar/2d-constraints-bfgs" rel="nofollow ugc">https://github.com/tmpvar/2d-constraints-bfgs</a> which lacks constraints such as tangent and it's rather old. Another promising but not complete solver is <a href="https://github.com/tab58/assemble2d" rel="nofollow ugc">https://github.com/tab58/assemble2d</a>. But let's assume this get's solved (pun intended).</p>
<p dir="auto">Pseudo code for the same example shape could be:</p>
<pre><code>0    var shapePoints = Chain.clear().
1      edge().vert().length(boxWidth).fillet(2).chamfer(6).fillet(2).
2      edge().horz().length(boxLength - boxCut).fillet(2).
3      edge().radius(boxRadius).out().distH(boxCut).distV(-boxCut]).fillet(2).
4      edge().vert().length(-boxWidth + boxCut).fillet(2).
5      edge().fillet(6).points;
</code></pre>
<p dir="auto">In the above code the shape is build up out of edges going clockwise which are straight by default and the then following constraints apply to that edge with at the end corner modifiers. This way each function has only zero or one parameter. The assumption is made that the end point of each edge coincides with the start point of the next edge.</p>
<p dir="auto">Not sure yet how the syntax would look like to position the shape relative to the origin point as it requires constraints to multiple arbitrary points in the shape.</p>
]]></description><link>https://openjscad.nodebb.com/post/666</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/666</guid><dc:creator><![CDATA[Dinther]]></dc:creator><pubDate>Mon, 08 Feb 2021 00:31:18 GMT</pubDate></item><item><title><![CDATA[Reply to Shape generator on Sat, 06 Feb 2021 01:09:53 GMT]]></title><description><![CDATA[<p dir="auto">Really nice start. Thanks, <a class="plugin-mentions-user plugin-mentions-a" href="https://openjscad.nodebb.com/uid/520">@Dinther</a></p>
<p dir="auto">One of the best libraries in this space is <a href="https://github.com/microsoft/maker.js" rel="nofollow ugc">Makerjs</a> by <a class="plugin-mentions-user plugin-mentions-a" href="https://openjscad.nodebb.com/uid/530">@danmarshall</a></p>
<p dir="auto">You could take some hints from here.</p>
]]></description><link>https://openjscad.nodebb.com/post/664</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/664</guid><dc:creator><![CDATA[z3dev]]></dc:creator><pubDate>Sat, 06 Feb 2021 01:09:53 GMT</pubDate></item></channel></rss>