{"id":119,"date":"2018-03-19T18:03:34","date_gmt":"2018-03-19T18:03:34","guid":{"rendered":"http:\/\/www.vandelle.com\/blog\/3dprinting\/?p=119"},"modified":"2018-03-19T18:03:34","modified_gmt":"2018-03-19T18:03:34","slug":"modelize-your-first-3d-shape-with-openscad-3","status":"publish","type":"post","link":"https:\/\/www.vandelle.com\/blog\/3dprinting\/2018\/03\/19\/modelize-your-first-3d-shape-with-openscad-3\/","title":{"rendered":"Modelize your first 3D shape with openSCAD #3"},"content":{"rendered":"<h2>3. Combining objects<\/h2>\n<p>Create simple shapes is cool but we want to create more complexes objects by combining multiple shapes to render exactly what we want.<\/p>\n<p>&nbsp;<\/p>\n<h3>a. Union<\/h3>\n<p>First of all let\u2019s do combination with using union():<\/p>\n<pre>$fn = 100;\n\nunion(){\n\n\u00a0\u00a0\u00a0 cube(10);\n\n\u00a0\u00a0\u00a0 cylinder(10,10,10);\n\n}\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-155\" src=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/wp-content\/uploads\/sites\/6\/2018\/03\/1-1-300x192.png\" alt=\"\" width=\"300\" height=\"192\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>b. Difference<\/h3>\n<p>You will tell me what\u2019s the point by doing a union of shapes? When you do difference, union becomes essential very fast.<\/p>\n<p><strong>difference()<\/strong> will allowed you to suppress a part of a shape with an other shape, example:<\/p>\n<pre>difference(){\u00a0\u00a0\u00a0\n\n\u00a0\u00a0\u00a0 translate([0,0,-1]) cylinder(20,5,5);\n\n\u00a0\u00a0\u00a0 cube(10);\n\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-156\" src=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/wp-content\/uploads\/sites\/6\/2018\/03\/2-1-300x196.png\" alt=\"\" width=\"300\" height=\"196\" \/><\/p>\n<p>Here we used a cylinder and removed matter from it with the angle of a cube. When you do a difference it\u2019s always the first object who is display and the second one who is removed.<\/p>\n<p><strong>Tip<\/strong>: sometimes the object became very complicated and we don\u2019t see clearly the objects it\u2019s why you can use the <strong>#<\/strong> at the beginning of the line to visualize the removed object.<\/p>\n<p>&nbsp;<\/p>\n<pre>difference(){\u00a0\u00a0\u00a0\n\n\u00a0\u00a0\u00a0 translate([0,0,-1]) cylinder(20,5,5);\n\n\u00a0\u00a0\u00a0 #cube(10);\n\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-157\" src=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/wp-content\/uploads\/sites\/6\/2018\/03\/3-2-300x176.png\" alt=\"\" width=\"305\" height=\"179\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>It\u2019s why union is very useful because you can do a difference on a more complexes object, example:<\/p>\n<pre>$fn = 100;\n\ndifference(){\n\n\u00a0\u00a0\u00a0 union(){\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cube(10);\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cylinder(10,10,10);\n\n\u00a0\u00a0\u00a0 }\n\n\u00a0\u00a0\u00a0 translate([0,0,-1]) cylinder(20,5,5);\n\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-158\" src=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/wp-content\/uploads\/sites\/6\/2018\/03\/4-2-300x220.png\" alt=\"\" width=\"300\" height=\"220\" \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-159\" src=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/wp-content\/uploads\/sites\/6\/2018\/03\/5-2-300x211.png\" alt=\"\" width=\"316\" height=\"222\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>c. Hull<\/h3>\n<p>A last functionality to combine shapes that can be very useful is <strong>hull()<\/strong><strong>.<\/strong> With hull you can combine 2 shapes with a link, example:<\/p>\n<pre>$fn=100;\n\nhull() {\n\n\u00a0\u00a0 cube([20,20,1],center=true);\n\n\u00a0\u00a0 translate([0,0,20]) cylinder(1,8,8);\n\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-160\" src=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/wp-content\/uploads\/sites\/6\/2018\/03\/6-2.png\" alt=\"\" width=\"277\" height=\"210\" \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-161\" src=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/wp-content\/uploads\/sites\/6\/2018\/03\/7-2.png\" alt=\"\" width=\"307\" height=\"210\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>d. Exercise 3<\/h3>\n<p>Try to reproduce this shape (<a href=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/modelize-your-first-3d-shape-with-openscad-correction\/\" target=\"_blank\" rel=\"noopener\">correction<\/a>)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-162\" src=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/wp-content\/uploads\/sites\/6\/2018\/03\/8-1-300x236.png\" alt=\"\" width=\"306\" height=\"241\" \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-163\" src=\"http:\/\/www.vandelle.com\/blog\/3dprinting\/wp-content\/uploads\/sites\/6\/2018\/03\/9-1-300x243.png\" alt=\"\" width=\"298\" height=\"241\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>3. Combining objects Create simple shapes is cool but we want to create more complexes objects by combining multiple shapes to render exactly what we want. &nbsp; a. Union First of all let\u2019s do combination with using union(): $fn = 100; union(){ \u00a0\u00a0\u00a0 cube(10); \u00a0\u00a0\u00a0 cylinder(10,10,10); } &nbsp; b. Difference You will tell me what\u2019s [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":88,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":0,"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vandelle.com\/blog\/3dprinting\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}