There are a few fundamental concepts that you should set straight from the start regarding the OpenSCAD scripting language, especially if you don’t have a programming background. In order to create it you need to type the following code in the text editor and hit the preview (first) icon on the action bar below the reference axes. Your first object is going to be a perfect cube with side length of 10. You will be introduced to the available actions and you will use them as the tutorial moves on.Ĭreating your first object One final thing that you should notice is the presence of one action bar over the text editor and one below the reference axes. The bottom of the right column is the console, where OpenSCAD will be printing any error messages or other information as you build your models. The only thing that you should currently be able to find there is the annotated reference axes X, Y and Z. The top of the right column is the "virtual" 3D space where your models will exist. Any model that you are ever going to create is going to be "typed out" in this text editor. The left column is a text editor, where you will be typing the OpenSCAD scripting language to create your models. The first thing that you should notice is that the window of OpenSCAD is divided into two columns. To move on please install OpenSCAD and start from a blank model.īasic information about the OpenSCAD environment As you are following the examples you will be asked to modify and extend them as well as create your own models. This tutorial is a follow-along tutorial. According to this technique, simple objects can be transformed and combined in order to create almost any complex model. Models are created by utilizing a technique called constructive solid geometry. OpenSCAD is a solid 3D modeler that enables the creation of parametric models using its scripting language. 7 The cylinder primitive and rotating objectsĪ few words about OpenSCAD.6 Adding more objects and translating objects.3 Basic information about the OpenSCAD environment.If you want to display these all the points in the list create the module plotList. Step = 18 //height of one layer of the shape First we need to calculate a list of the points of the cylinder. All faces together should enclose the desired shape. Each face contains the indices of 3 or more point. For polyhedron to work we need a list of 3D points instead of 2D points and in addition a list of faces. We use polyhedron function of OpenSCAD instead of polygon. To create a 3D shape is more complex than 2D. Ellipse created with the code above Creating a 3D shape r1 is the radius in the x-direction and r2 is the radius in the y-direction. function ellipse(r1, r2) = ) ] Ī second parameter is added. The ellipse, a generalization of the circle, can now easily be created by slightly changing our function. The radius * cos(phi/2) and radius * sin(phi) calculate each x,y coordinate for every given phi. The loop begin at 0 and ends at 720 with a step of 1. In this case of the circle function the point are generated in a for loop. In OpenSCAD a list of points in a two-dimensional space is represented by ,…] where all x’s and y’s are numbers. Every function generates a value and in this case it is a list of points. Now let’s take a look at the syntax of the function. function circle(radius) = ) ] Ĭolor("red") polygon(circle(20)) Shape created with x = r cos(φ/2) and y = r sin(φ) The circle function can easily be altered thus gaining a new shape. By adding echo(circle(20)) to our script the list of points is printed in the console. When F5 is pressed a circle is drawn however the x,y coordinates of this circle are available to us. The function uses the trigonometric formulas, x = r cos φ and y = sin φ, to convert polar coordinates to Cartesian coordinates. Alternatively we can write a function that generates a list of points needed for a circle and then use polygon with the points as parameter to draw the circle. However OpenSCAD doesn’t allow us to reshape this build-in function to for instance an ellipse. To create a circle with a radius of 20 in OpenSCAD we just have to type circle(20) Shapes created with functions and polygon in OpenSCAD Creating a 2D shape In this blog post I’ll show how to create some simple 2D and 3D shapes and explain how to create more complex shapes. This property can be used to create shapes that are impossible with the 2D and 3D shapes that are build-in in OpenSCAD. A functions can generate a list of points eliminating the need to manually created these lists. Polygon and polyhedron both accept a list of 2D and 3D coordinates (points) respectively as parameters. OpenSCAD allows the user to create complex shapes with the polygon function for 2D and polyhedron for 3D.
0 Comments
Leave a Reply. |