OpenSCAD用戶手冊/2D 到 3D 拉伸

維基教科書,自由的教學讀本


擠壓成型是以固定截面形狀來創建工件的一道工序。OpenSCAD為從2D形狀創建3D實體提供了兩種命令:linear_extrude()與rotate_extrude()。線性擠型就如同把橡皮泥放入特定形狀的模具,再通過擠壓成型。

linear_extrude()的工作方式就像一台橡皮泥的擠壓機

旋轉擠型就類似於在陶輪上製作碗的過程。Potter's wheel.

rotate_extrude() emulates throwing a vessel

兩種擠型方法處理的目標都是位於X-Y平面上的(可能是不連續的)2D幾何圖形。While transformations that operates on both 2D shapes and 3D solids can move a shape off the X-Y plane, when the extrusion is performed the end result is not very intuitive. What actually happens is that any information in the third coordinate (the Z coordinate) is ignored for any 2D shape, this process amounts to an implicit projection() performed on any 2D shape before the extrusion is executed. It is recommended to perform extrusion on shapes that remains strictly on the X-Y plane.

線性擠型[編輯]

線性擠型(Linear Extrusion)是一種以2D多邊形作為輸入,並令其在3D空間進行擴展的建模操作。這樣,就可創建出一個3D幾何形狀。請牢記,擠型總是以XY平面開始,並按照高度的指示沿Z軸來擠壓3D形狀;因此,如果您在擠型之前運用了旋轉或其他變換的話,擠型函數將依照2D多邊形在XY平面上的投影進行處理。

用法[編輯]

linear_extrude(height = fanwidth, center = true, convexity = 10, twist = -fanrot, slices = 20, scale = 1.0, $fn = 16) {...}

由於向後兼容的問題,您必須使用參數名。

height必須為正數。

$fn是指定linear_extrude解析度的可選項(值越大圖形越「平滑」,但計算時間也將隨之增加)。

If the extrusion fails for a non-trivial 2D shape, try setting the convexity parameter (the default is not 10, but 10 is a "good" value to try). See explanation further down.

Twist[編輯]

Twist is the number of degrees of through which the shape is extruded. Setting the parameter twist = 360 will extrude through one revolution. The twist direction follows the left hand rule.

twist = 0

0° of Twist

linear_extrude(height = 10, center = true, convexity = 10, twist = 0)
translate([2, 0, 0])
circle(r = 1);

twist = -100

-100° of Twist

linear_extrude(height = 10, center = true, convexity = 10, twist = -100)
translate([2, 0, 0])
circle(r = 1);

twist = 100

100° of Twist

linear_extrude(height = 10, center = true, convexity = 10, twist = 100)
translate([2, 0, 0])
circle(r = 1);

twist = -500

-500° of Twist

linear_extrude(height = 10, center = true, convexity = 10, twist = -500)
translate([2, 0, 0])
circle(r = 1);

Center[編輯]

It is similar to the parameter center of cylinders. If center is false the linear extrusion Z range is from 0 to height; if it is true, the range is from -height/2 to height/2.


center = true

center = true

linear_extrude(height = 10, center = true, convexity = 10, twist = -500)
translate([2, 0, 0])
circle(r = 1);


center = false

center = false

linear_extrude(height = 10, center = false, convexity = 10, twist = -500)
translate([2, 0, 0])
circle(r = 1);

Mesh Refinement[編輯]

The slices parameter defines the number of intermediate points along the Z axis of the extrusion. Its default increases with the value of twist. Explicitly setting slices may improve the output refinement.

slices = 100

linear_extrude(height = 10, center = false, convexity = 10, twist = 360, slices = 100)
translate([2, 0, 0])
circle(r = 1);

The special variables $fn, $fs and $fa can also be used to improve the output. If slices is not defined, its value is taken from the defined $fn value.

$fn = 100

linear_extrude(height = 10, center = false, convexity = 10, twist = 360, $fn = 100)
translate([2, 0, 0])
circle(r = 1);

Scale[編輯]

Scales the 2D shape by this value over the height of the extrusion. Scale can be a scalar or a vector:

 linear_extrude(height = 10, center = true, convexity = 10, scale=3)
 translate([2, 0, 0])
 circle(r = 1);

OpenScad linear_extrude scale example

 linear_extrude(height = 10, center = true, convexity = 10, scale=[1,5], $fn=100)
 translate([2, 0, 0])
 circle(r = 1);

OpenScad linear_extrude scale example2

Note that if scale is a vector, the resulting side walls may be nonplanar. Use twist=0 and the slices parameter to avoid asymmetry.

 linear_extrude(height=10, scale=[1,0.1], slices=20, twist=0)
 polygon(points=[[0,0],[20,10],[20,-10]]);

Rotate Extrude[編輯]

Rotational extrusion spins a 2D shape around the Z-axis to form a solid which has rotational symmetry. One way to think of this operation is to imagine a Potter's wheel placed on the X-Y plane with its axis of rotation pointing up towards +Z. Then place the to-be-made object on this virtual Potter's wheel (possibly extended down below the X-Y plane towards -Z, take the cross-section of this object on the X-Z plane but keep only the right half (X >= 0). That is the 2D shape that need to be fed to rotate_extrude() as the child in order to generate this solid.

Since a 2D shape is rendered by OpenSCAD on the X-Y plane, an alternative way to think of this operation is as follows: spins a 2D shape around the Y-axis to form a solid. The resultant solid is placed so that its axis of rotation lies along the Z-axis.

It can not be used to produce a helix or screw threads.

The 2D shape needs to lie completely on either the right (recommended) or the left side of the Y-axis. More precisely speaking, each vertex of the shape must have either x >= 0 or x <= 0. If the shape crosses the X axis a warning will be shown in the console windows and the rotate_extrude() will be ignored. For OpenSCAD versions prior to 2016.xxxx, if the shape is in the negative axis the faces will be inside-out, which may cause undesired effects.

參數

用法[編輯]

rotate_extrude(angle = 360, convexity = 2) {...}
Right-hand grip rule

You must use parameter names due to a backward compatibility issue.

convexity
If the extrusion fails for a non-trival 2D shape, try setting the convexity parameter (the default is not 10, but 10 is a "good" value to try). See explanation further down.
angle [請注意: 需要使用版本 2015.09]
Defaults to 360. Specifies the number of degrees to sweep, starting at the positive X axis. The direction of the sweep follows the Right Hand Rule, hence a negative angle will sweep clockwise.

示例[編輯]

A simple torus can be constructed using a rotational extrude.

rotate_extrude(convexity = 10)
translate([2, 0, 0])
circle(r = 1);

Mesh Refinement[編輯]


Increasing the number of fragments that the 2D shape is composed of will improve the quality of the mesh, but take longer to render.

rotate_extrude(convexity = 10)
translate([2, 0, 0])
circle(r = 1, $fn = 100);


The number of fragments used by the extrusion can also be increased.

rotate_extrude(convexity = 10, $fn = 100)
translate([2, 0, 0])
circle(r = 1, $fn = 100);

Using the parameter angle (with OpenSCAD versions 2016.xx), a hook can be modeled .

OpenSCAD - a hook
translate([0,60,0])
   rotate_extrude(angle=270, convexity=10)
       translate([40, 0]) circle(10);
rotate_extrude(angle=90, convexity=10)
   translate([20, 0]) circle(10);
translate([20,0,0]) 
   rotate([90,0,0]) cylinder(r=10,h=80);

Extruding a Polygon[編輯]

Extrusion can also be performed on polygons with points chosen by the user.

Here is a simple polygon and its 200 step rotational extrusion. (Note it has been rotated 90 degrees to show how the rotation will look; the rotate_extrude() needs it flat).

rotate([90,0,0])        polygon( points=[[0,0],[2,1],[1,2],[1,3],[3,4],[0,5]] );
rotate_extrude($fn=200) polygon( points=[[0,0],[2,1],[1,2],[1,3],[3,4],[0,5]] );

For more information on polygons, please see: 2D Primitives: Polygon.

擠型參數的相關描述[編輯]

針對所有擠型模式的擠型參數[編輯]

convexity Integer. The convexity parameter specifies the maximum number of front sides (back sides) a ray intersecting the object might penetrate.

This parameter is only needed for correctly displaying the object in OpenCSG preview mode and has no effect on the polyhedron rendering.


This image shows a 2D shape with a convexity of 4, as the ray indicated in red crosses the 2D shape a maximum of 4 times. The convexity of a 3D shape would be determined in a similar way. Setting it to 10 should work fine for most cases.

僅用於線性擠型的擠型參數[編輯]

height The extrusion height
center If true the solid will be centered after extrusion
twist The extrusion twist in degrees
slices Similar to special variable $fn without being passed down to the child 2D shape.
scale Scales the 2D shape by this value over the height of the extrusion.