{"id":686,"date":"2015-12-30T13:03:56","date_gmt":"2015-12-30T19:03:56","guid":{"rendered":"http:\/\/www.scorchworks.com\/Blog\/?p=686"},"modified":"2024-04-30T21:27:42","modified_gmt":"2024-05-01T02:27:42","slug":"openscad-modules-for-automatic-fillets-and-radii","status":"publish","type":"post","link":"https:\/\/www.scorchworks.com\/Blog\/openscad-modules-for-automatic-fillets-and-radii\/","title":{"rendered":"OpenSCAD Modules for Automatic Fillets (and Radii)"},"content":{"rendered":"<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/before_after.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-718 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/before_after.png\" alt=\"before_after\" width=\"320\" height=\"241\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/before_after.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/before_after-300x226.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p>Fillets in OpenSCAD are not a straight forward endeavor.\u00a0 There have been many posts about the subject and many proposed solutions including libraries of generic fillet parts to be added to models.\u00a0 The fillet type that I have been experimenting with uses minkowski sums to achieve the task on a model of any geometry.\u00a0 Well, theoretically any model anyways.\u00a0 The use of two minkowski sums in the process makes the procedure unpractical for models of significant complexity because of the time required to produce the result.\u00a0 I do provide a partial solution to this limitation.\u00a0 My partial solution is to isolate an area of a larger model for local fillet generation.\u00a0 At the end of this BLOG post I provide a file containing modules for producing global or local fillets and radii within OpenSCAD.\u00a0 If you want to know more about the steps taken to generate the fillets continue reading otherwise you can jump to the end to download the SCAD file with the modules.<\/p>\n<p><strong>The following steps are performed automatically by the modules included in the file at the end of this post.\u00a0 These detailed steps and illustrations are provided for information purposes.<\/strong><\/p>\n<p><strong>Original sample part:<\/strong> Here is our sample part, the second image shows the sample part with a transparent overlay of the sample part for reference.\u00a0 The transparent part overlay will be included in the following steps for a visual reference of the original shape.<\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step0a-Custom.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-687 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step0a-Custom.png\" alt=\"auto_fillet_step0a (Custom)\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step0a-Custom.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step0a-Custom-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step0-Custom.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-680 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step0-Custom.png\" alt=\"auto_fillet_step0 (Custom)\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step0-Custom.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step0-Custom-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p><strong>STEP 1:\u00a0 <\/strong>Perform a minkowski sum of the sample part with a sphere (or cylinder if only rounding one axis of the part).\u00a0 (The image shows a slice of the minkowski sum for illustration purposes.\u00a0 The full minkowski sum completely encloses the sample part.)<\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step1-Custom.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-681 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step1-Custom.png\" alt=\"auto_fillet_step1 (Custom)\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step1-Custom.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step1-Custom-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>STEP 2:<\/strong>\u00a0 Subtract the result from STEP 1 from a very large cube using a difference operation.\u00a0 The large cube needs to be larger than the object being worked on.\u00a0 This is analogous to inverting the normals on the model making a negative volume.\u00a0 (CGAL and OpenSCAD do not support negative volumes so this is a work around)<\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step2-Custom.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-682 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step2-Custom.png\" alt=\"auto_fillet_step2 (Custom)\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step2-Custom.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step2-Custom-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>STEP 3:<\/strong>\u00a0 Perform a second Minkowski sum of the results from STEP 2 and the same sphere (or cylinder) used in STEP 1. <strong>NOTE: This is the most computationally intense step in the filleting process.<\/strong><\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step3-Custom.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-683 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step3-Custom.png\" alt=\"auto_fillet_step3 (Custom)\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step3-Custom.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step3-Custom-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p><strong>STEP 4:\u00a0<\/strong> Perform a difference operation to subtract the result from STEP 3 from a large cube.\u00a0 The cube used in this step is slightly smaller than the cube used in STEP 2.\u00a0 The remaining object has internal fillets with a radius equal to the radius of the sphere (or cylinder) used in the previous steps.\u00a0 The top picture shows the object with the original shape shown transparent.\u00a0 The lower image has the transparent original shape removed.<\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step4-Custom.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-684 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step4-Custom.png\" alt=\"auto_fillet_step4 (Custom)\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step4-Custom.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step4-Custom-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step5-Custom.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-685 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step5-Custom.png\" alt=\"auto_fillet_step5 (Custom)\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step5-Custom.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/auto_fillet_step5-Custom-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p>This procedure works in the generalized 3D case with the size limitations I mentioned earlier. Additionally there is an analogous procedure to produce radii on external corners.\u00a0 Below are images of a sample three dimensional parts with fillets and radii generated automatically using the module file I provide below.<\/p>\n<p><strong>Base 3D part:<\/strong><\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_base_shape.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-723 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_base_shape.png\" alt=\"3D_fillets_base_shape\" width=\"320\" height=\"241\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_base_shape.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_base_shape-300x226.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p><strong>3D part with Fillets (31 minute build time):<\/strong><\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_31min.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-700 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_31min.png\" alt=\"3D_fillets_31min\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_31min.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_31min-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p><strong>3D part with rounds (&lt;1 minute build time):<\/strong><\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_rounds_Xmin.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-702 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_rounds_Xmin.png\" alt=\"3D_rounds_Xmin\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_rounds_Xmin.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_rounds_Xmin-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p><strong>3D part with fillets and rounds (80 minute build time):<\/strong><\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_n_rounds_80min.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-703 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_n_rounds_80min.png\" alt=\"3D_fillets_n_rounds_80min\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_n_rounds_80min.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_fillets_n_rounds_80min-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p>As I mentioned earlier there is a partial solution to the model size limitation of this procedure.\u00a0 This partial solution involves selecting a specific region of the model to be operated on and removing that region from the model while performing the operations.\u00a0 After the operations are complete the removed section of the model is inserted back into the larger model via a union command.\u00a0 This removal and re-installation of the sub-model is incorporated in the modules\u00a0 provided in the .scad file linked at the end of this BLOG post.\u00a0 To use the sub-modeling you just need to include a second object (child) in the module call to indicate the region to be operated on.\u00a0 For example using the SCAD file provided if the module add_fillets is called on an object alone all of the internal corners will be filleted<\/p>\n<pre><strong>add_fillets(R=sample_R)\r\n{\r\n    sample_object();\r\n}<\/strong><\/pre>\n<p>If you call the add_fillets module and you include a second object only the areas of the first object that intersect the second object will be filleted.\u00a0 (in the example below the second object is a 10x10x10 cube.<\/p>\n<pre><strong>add_fillets(R=sample_R)\r\n{\r\n    sample_object();\r\n    cube([10,10,10])\r\n}<\/strong><\/pre>\n<p>Below are a couple of pictures of our sample object with localized region fillets and radii.\u00a0 All of the pictures below used a sphere with $fn=20 for the radius generation.\u00a0 The default in the module file provided is $fn=6 to ensure reasonable run times for the example object.<\/p>\n<p><strong>Local region illustrated by a transparent box:<\/strong><\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_box.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-713 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_box.png\" alt=\"3D_local_box\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_box.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_box-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p><strong>3D part with local fillets:<\/strong><\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_fillets_41min.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-712 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_fillets_41min.png\" alt=\"3D_local_fillets_41min\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_fillets_41min.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_fillets_41min-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p><strong>3D part with local radii:<br \/>\n<\/strong><\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_rounds_Xmin.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-701 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_rounds_Xmin.png\" alt=\"3D_local_rounds_Xmin\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_rounds_Xmin.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_rounds_Xmin-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p><strong>3D part with local fillets and radii:<\/strong><\/p>\n<p><a href=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_fillets_n_rounds_67min.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-715 aligncenter\" src=\"http:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_fillets_n_rounds_67min.png\" alt=\"3D_local_fillets_n_rounds_67min\" width=\"320\" height=\"240\" srcset=\"https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_fillets_n_rounds_67min.png 320w, https:\/\/www.scorchworks.com\/Blog\/wp-content\/uploads\/3D_local_fillets_n_rounds_67min-300x225.png 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/p>\n<p>Finally, below is the link to the the .scad file containing the modules for fillets and radii.\u00a0 The file also contains the simple examples shown in this post.\u00a0 In addition to generalized fillets and radii the modules can be used to do single axis fillets and radii.\u00a0 The single axis options (&#8220;x&#8221;,&#8221;y&#8221; and &#8220;z&#8221;) are much faster than the general option (&#8220;xzy&#8221;) so if you are only looking for a fillet in one axis it is better to use the specific axis you need.\u00a0 Play with the examples to see how each option works.\u00a0 The default &#8220;fn&#8221; value is 6 to keep the render time low.\u00a0 To get more usable results that number will need to be increased.\u00a0 (The sample images above used an fn=20).<\/p>\n<p><strong>Get the file here: <a href=\"http:\/\/www.scorchworks.com\/MISC\/fillets_and_rounds.scad\">fillets_and_rounds.scad<\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fillets in OpenSCAD are not a straight forward endeavor.\u00a0 There have been many posts about..<\/p>\n","protected":false},"author":1,"featured_media":703,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/posts\/686"}],"collection":[{"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/comments?post=686"}],"version-history":[{"count":30,"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/posts\/686\/revisions"}],"predecessor-version":[{"id":727,"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/posts\/686\/revisions\/727"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/media\/703"}],"wp:attachment":[{"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/media?parent=686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/categories?post=686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scorchworks.com\/Blog\/wp-json\/wp\/v2\/tags?post=686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}