These are the basic functions I use for most of my other modelling.
File: pwlib_boards.scad
Functions to generate cases for PCBs.
File: pw_funcs.scad
Functions:
dovetail_outer(x, y, spread, thick, clear=0.0, leftward=true)- Generates a list of points for a linear_extruded polygon that forms the 'outside' of a dovetail joint.
x,y- total size of the jointthick- the thickness of the walls at the back of the dovetailspread- the distance 'in' from each side the 'mouth' of the dovetail goes. Ifspreadis zero, there is no angle to the dovetail and it becomes a finger joint.clearis the clearance (see below).
dovetail_inner(x, y, spread, thick, clear=0.0, leftward=true)- Generates a list of points for a linear_extruded polygon that forms the
'inside' of a dovetail joint of the given dimensions.
clearis the amount of clearance on each part - whenclearis zero, they fit exactly; if set to 1 there would be 1mm of clearance between dovetail and outer.
- Generates a list of points for a linear_extruded polygon that forms the
'inside' of a dovetail joint of the given dimensions.
arith_spiral(start_rad, end_rad, steps, angle=360)- Generates a list of points that forms an arithmetic spiral - i.e. a fixed distance between arcs of the spiral. This is only one side - you need to wrap this in with other points to form a 'solid' polygon that can be extruded. Points start on the X axis and the arc goes anti-clockwise from there - you can make the angle negative to go in the other direction. The start can be larger or smaller than the end.
start_rad- the radius distance from the centre at the start of the spiralend_rad- the radius distance from the centre at the end of the spiralsteps- number of steps - a bit like the $fn parameter.angle- total arc covered. This can be greater than 360 if you want multiple revolutions of the spiral.
File: pw_primitives.scad
The basic modules I use to base a lot of my other modelling on.
Modules:
- Arrangers
txl(x=0, y=0, z=0)- an abbreviated translate, usually if you just want to move in one axis
rot(x=0, y=0, z=0)- an abbreviated rotate, usually if you just want to rotate about one axis
hex_distribute(num_x, num_y, diameter)- arrange children in a hexagonal lattice. Every alternate Y row is
offset by half the diameter, and the rows are offset such that the
centres are always
diameterapart (i.e. the distance in the Y axis between rows isdiameter*sin(60)). num_x- the number of children in the X directionnum_y- the number of children in the Y directiondiameter- the distance between each centre.
- arrange children in a hexagonal lattice. Every alternate Y row is
offset by half the diameter, and the rows are offset such that the
centres are always
rotate_distribute(number, angle=360, last_fencepost=false)- arrange children by rotating them by successive increments. Only the rotation is done; children must be translated off the origin in order to be in different positions.
linear_distribute(start, step, end, tvec = [1, 0, 0])- Distribute children in a for loop, but multiplying the translation
vector
tvecby the loop value.
- Distribute children in a for loop, but multiplying the translation
vector
- Modifiers
flatten(height)- Take any child object and trim off the bits below the XY plane, and
above a plane
heightabove the XY plane. Useful for flattening round objects onto a plane. ` Twist generators
- Take any child object and trim off the bits below the XY plane, and
above a plane
arith_twist(start_angle, stop_angle, height, steps)- Produces a series of
linear_extruded segments of a child 2D object, extruded with gradually increasing twist angles. The final object will beheighthigh. The final total twist (should you need to align something with the final position of your object) is echoed.
- Produces a series of
- Simple cubic modules
rounded_box(length, width, height, outer_r, remove_top_face=true, method="mink")- A box with rounded corners (chamfered), with the top face rounded or flat.
This can be generated by a
minkowskioperator, which is simpler but may be more computationally complicated, or ahullof cylinders and spheres which is more objects but may be more computationally simple to render. So far tests don't show one being much faster than the other. Rumours of a third,unionmethod, are so far unconfirmed.
- A box with rounded corners (chamfered), with the top face rounded or flat.
This can be generated by a
chamfered_cube(x, y, z, side, chamfer_x=true, chamfer_y=true, chamfer_z=true)filleted_cube(x, y, z, fillet_rad)hexahedron(corners, convexity=1)filleted_hexahedron(x1, y1, x2, y2, height, fillet_rad)- A six-sided object, with bottom and top parallel to the XY plane
(bottom thereon, top
heightaway). Its 'vertical' edges are at positive and negative (x1,y1) at the base and (x2,y2) at top, and these edges are formed by cylinders of radiusfillet_rad.
- A six-sided object, with bottom and top parallel to the XY plane
(bottom thereon, top
r_diamond_2d(x, y, r)- A diamond of maximum dimension
x,ywith rounded corners of radiusr.
- A diamond of maximum dimension
r_diamond_screw_plate(x, y, r, hole_x, hole_r, thick)- A rounded diamond-shaped plate with two holes that you can use as a
base for other objects. The plate diamond is of maximum dimensions
x,y, the corners are of radiusr. The two screw holes arehole_xfrom the centre away in positive and negative X, and are of radiushole_r. The whole plate isthickheight in Z.
- A rounded diamond-shaped plate with two holes that you can use as a
base for other objects. The plate diamond is of maximum dimensions
- Rings and Cones
- function
radius_from_d_or_r(d=undef, r=undef)- Used in the below functions that take either a
dorrparameter similar to thecircleandcylinderprimitives. This produces a calculated radius that other modules can use, and makes sure that one and only one of thedandrparameters is given.
- Used in the below functions that take either a
cylinder_outer(h, d=undef, r=undef)cylinder_mid(h, d=undef, r=undef)circle_outer(d=undef, r=undef)circle_mid(d=undef, r=undef)cylinder_from_to(from, to, d=undef, r=undef)- Move and rotate a cylinder so its start is the
fromvector and its end is thetovector. Specify at least one ofrord, similar to a cylinder.
- Move and rotate a cylinder so its start is the
chamfered_cylinder(height, d=undef, r=undef, chamfer=0)rounded_cylinder(h, d=undef, r=undef, corner_r, mink=false)- A cylinder with rounded edges. If
minkis left as false this is generated using arotate_extrude, otherwise aminkowskioperation is used.
- A cylinder with rounded edges. If
rounded_cylinder_hole(h, d=undef, r=undef, corner_r, top_r=undef)- A cylinder 'hole' to cut out of another object, so that its bottom is rounded inward and a rounded lip is taken out of the surrounding material.
ellipse(x, y)ellipsoid(x, y, height)elliptical_pipe(x, y, height, thick)pipe_rt(height, radius, thickness)pipe_oi(height, o_radius, i_radius)hollow_cone_rt(height, bottom_radius, top_radius, thickness)hollow_cone_oi(height, o_bot_radius, i_bot_radius, o_top_radius, i_top_radius)sphericone(sphere_r, cone_base_r, angle=40, truncate_at_xy_plane=false)- A sphere of
sphere_rradius, standing on a cone whose base is ofcone_base_rradius, where the angle of the cone isanglefrom the horizontal. The cone height is calculated such that it meets the sphere at a tangent. - This is for printing a sphere, sitting on some other object such as a cylinder or flat surface, without needing support. This will emit the total height, which is calculated; if you need an absolute maximum height you will need to put something like a cylinder underneath it based on that total sphericone height.
- A sphere of
- function
- Cylinder segments
half_cylinder(height, radius)cylinder_segment(height, radius, angle=360)pipe_rt_segment(radius, thickness, height, angle)
- Cylinders going places
cylinder_from_to(from, to, d, r)- A cylinder from a source 3D place to a destination 3D place. This is achieved by moving and then rotating a cylinder into position.
rounded_cylinder_from_to(from, to, d, r)- The same thing but with spheres on the ends. Really easy because this
is just a
hull()operation on two spheres; this may be at the expense of CGAL computation. Note that thefromandtocoordinates are the centres of the spheres, not the tips.
- The same thing but with spheres on the ends. Really easy because this
is just a
cylinder_xyzs(x1, y1, x2, y2, height, r)- A cylinder, going from
[x1, y1, 0]to[x2, y2, height]. The cylinder is sheared and translated, so its top and bottom are still parallel to the XY plane. Again, the X and Y coordinates are the centres of the cylinders, not the outside edges.
- A cylinder, going from
- Toroids and pipe bends
torus(outer, inner, x_stretch=1, angle=360)- The standard torus, with the ability to scale it in the X dimension,
and get a toroidal arc (because, of course, this is produced with a
rotate_extrude).
- The standard torus, with the ability to scale it in the X dimension,
and get a toroidal arc (because, of course, this is produced with a
toroidal_pipe(bend_radius, pipe_i_radius, thickness, angle=360)- A hollow toroid, given the inner radius and the wall thickness.
quarter_torus_bend_snub_end(outer_rad, width, angle, outer=true)- A quarter circle in a toroidal arc, either on the outer or inner bottom quarter of the circle.
- This can be used to subtract from a surface to fillet the join between a base and a circular fitting.
conduit_angle_bend(bend_radius, pipe_radius, bend_angle, thickness, join_length, join_radius=undef, join_a=true, join_b=true, flare_a=true, flare_b=true, curved_a=false, curved_b=false)- The handy dandy all-purpose generator for curved parts to join two
pipes together.
pipe_radiusis the internal pipe diameter, and the thickness is then added to that. - Each end, 'a' (the one on the XZ plane) and 'b' (the other one), can be
manipulated in several ways:
- If
join_(a|b)isfalse, then no join segment is added on that end. - If
flare_(a|b)isfalse, then that end is the same diameter as the overall pipe; otherwise it's wider, so that a similar pipe of the same diameter would fit into it. - If
curved_(a|b)isfalsethen that join end is straight (to fit a straight pipe); iftruethat join end is curved (to fit into another curved pipe).curved_(a|b)=trueallows multiple curved segments to be joined together into a bend of a radius greater than would fit in a printer or would be printed without supports.
- If
- See
Test_pieces/conduit_angle_bend*.scadfor examples and tests.
- The handy dandy all-purpose generator for curved parts to join two
pipes together.
- Rectangular tubes and toroids
rectangular_pipe(width, height, thickness, length)rectangular_tube(x, y, thickness, height)rectangular_cone(x1, y1, x2, y2, height)rectangular_torus(outer, inner, height, angle=360)rectangular_pipe_bend_basic(width, height, thickness, inner_radius, bend_angle)rectangular_pipe_bend( width, height, thickness, inner_radius, bend_angle, join_length, overlap_len, join_a=true, join_b=true, flare_a=true, flare_b=true, curved_a=false, curved_b=false )- A curved rectangular pipe, rotating around the Z axis so X=width and Z=height. This can produce straight or curved join segments at either end ('a' is the end at the XZ plane, 'b' is the other), either flared (i.e. accepting a pipe of this width and height) or not.
- Springs
coil_spring(spring_r, wire_r, rise_per_rev, turns, step_deg)flat_spring(length, width, height, gap_length, segments)rect_circ_spring(in_radius, out_radius, angle, segments, height, thickness)
- Bolt shapes
- These are used for 'cutting out' a hole for a bolt in something else.
countersunk_bolt_hole(shaft_d, shaft_len, head_d, head_len)flat_head_bolt_hole(shaft_d, shaft_len, head_d, head_len)hex_head_bolt_hole(shaft_d, shaft_len, head_d, head_len)- A bolt with a hexagonal head - useful for holding the nut or the bolt still while you screw the other in.
- Triangles
equ_triangle(side)- An equilateral triangle, with one point on the origin and one side along the X axis.
arb_triangle(ab, bc, ac)- An arbitrary triangle, given three side lengths. Point A is at the
origin, and point B is along the X axis (i.e. at
(ab, 0)). Point C has its X and Y coordinates calculated.
- An arbitrary triangle, given three side lengths. Point A is at the
origin, and point B is along the X axis (i.e. at
- Hexagons
hexagon(radius)- A 2D hexagon
hexagon_solid(radius=0, height=0, side2side=0)- A
linear_extruded hexagon. Can be specified by either radius (the length of one side, or the distance from the center to one corner), or the 'side to side' measurement of the distance between two parallel side.
- A
tapered_hexagon(radius1, radius2, height)- A hexagon that goes from radius1 to radius2 as it goes up.
File: gears.scad
A borrowed gears library. Source: https://github.com/chrisspen/gears