omdl  v0.6.1
OpenSCAD Mechanical Design Library
tools_edge.scad
Go to the documentation of this file.
1 //! Shape edge finishing tools.
2 /***************************************************************************//**
3  \file tools_edge.scad
4  \author Roy Allen Sutton
5  \date 2017
6 
7  \copyright
8 
9  This file is part of [omdl] (https://github.com/royasutton/omdl),
10  an OpenSCAD mechanical design library.
11 
12  The \em omdl is free software; you can redistribute it and/or modify
13  it under the terms of the [GNU Lesser General Public License]
14  (http://www.gnu.org/licenses/lgpl.html) as published by the Free
15  Software Foundation; either version 2.1 of the License, or (at
16  your option) any later version.
17 
18  The \em omdl is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with the \em omdl; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26  02110-1301, USA; or see <http://www.gnu.org/licenses/>.
27 
28  \details
29 
30  \ingroup tools tools_edge
31 *******************************************************************************/
32 
33 include <../shapes/shapes2d.scad>;
34 
35 //----------------------------------------------------------------------------//
36 /***************************************************************************//**
37  \addtogroup tools
38 
39  \amu_define caption (Edge)
40 
41  \amu_make png_files (append=dim extension=png)
42  \amu_make eps_files (append=dim extension=png2eps)
43  \amu_shell file_cnt ("echo ${png_files} | wc -w")
44  \amu_shell cell_num ("seq -f '(%g)' -s '^' ${file_cnt}")
45 
46  \htmlonly
47  \amu_image_table
48  (
49  type=html columns=4 image_width="200" cell_files="${png_files}"
50  table_caption="${caption}" cell_captions="${cell_num}"
51  )
52  \endhtmlonly
53  \latexonly
54  \amu_image_table
55  (
56  type=latex columns=4 image_width="1.25in" cell_files="${eps_files}"
57  table_caption="${caption}" cell_captions="${cell_num}"
58  )
59  \endlatexonly
60 *******************************************************************************/
61 
62 /***************************************************************************//**
63  \addtogroup tools
64  @{
65 
66  \defgroup tools_edge Edge
67  \brief Shape edge finishing tools.
68  @{
69 *******************************************************************************/
70 //----------------------------------------------------------------------------//
71 
72 //----------------------------------------------------------------------------//
73 // openscad-amu macros
74 //----------------------------------------------------------------------------//
75 /***************************************************************************//**
76  \amu_define scope (tools_edge_dim)
77  \amu_define size (qvga)
78  \amu_define view (diag)
79 
80  \amu_define example_dim
81  (
82  \image html ${scope}_${size}_${view}_${function}.png "${function}"
83  \image latex ${scope}_${size}_${view}_${function}.eps "${function}" width=2.5in
84  \dontinclude ${scope}.scad \skipline ${function}(
85  )
86 *******************************************************************************/
87 //----------------------------------------------------------------------------//
88 
89 //! A 2d edge-finish profile specified by intersection radius.
90 /***************************************************************************//**
91  \param r <decimal> The radius length.
92  \param p <integer> The profile identifier.
93  \param f <decimal> The mid-point offset factor.
94  \param a <decimal> The sweep angle.
95 
96  \details
97 
98  \b Example
99  \amu_eval ( function=edge_profile_r view=top ${example_dim} )
100 
101  \b Profiles:
102 
103  | p | Description |
104  |:---:|:--------------------------------------|
105  | 0 | Two segment bevel with mid inflection |
106  | 1 | A cove with cut-out offset |
107  | 2 | A quarter round with offset |
108 
109  \note An offset factor greater than 1 moves the mid-point away
110  from the profile edge-vertex. A factor less than 1 move it
111  inwards towards the edge-vertex.
112 *******************************************************************************/
113 module edge_profile_r
114 (
115  r,
116  p = 0,
117  f = 1,
118  a = 90,
119 )
120 {
121  // bevel with mid inflection
122  if ( p == 0 )
123  {
124  c1x = r;
125  c3x = c1x*cos(a);
126  c3y = c1x*sin(a);
127 
128  mpc = f*[(c1x+c3x)/2, c3y/2];
129 
130  polygon([[0,0], [c1x,0], mpc, [c3x,c3y]]);
131  }
132  // cove with cut-out offset
133  else if ( p == 1 )
134  {
135  difference()
136  {
137  c1x = r/tan(a/2);
138  c3x = c1x*cos(a);
139  c3y = c1x*sin(a);
140 
141  polygon([[0,0], [c1x,0], [c3x,c3y]]);
142 
143  translate(f*[c1x,r])
144  circle(r=r);
145  }
146  }
147  // quarter round with offset
148  else if ( p == 2 )
149  {
150  c1x = r;
151  c3x = c1x*cos(a);
152  c3y = c1x*sin(a);
153 
154  mpc = unit_l([(c1x+c3x)/2, c3y/2]);
155 
156  if ( f < 1 )
157  intersection()
158  {
159  polygon([[0,0], [c1x,0], [c3x,c3y]]);
160 
161  translate(f*mpc - mpc)
162  ellipse_s(r, a1=0, a2=a);
163  }
164  else if ( f > 1 )
165  union()
166  {
167  polygon([[0,0], [c1x,0], [c3x,c3y]]);
168 
169  translate(f*mpc - mpc)
170  ellipse_s(r, a1=0, a2=a);
171  }
172  else
173  ellipse_s(r, a1=0, a2=a);
174  }
175 }
176 
177 //! A 3d edge-finish additive shape specified by intersection radius.
178 /***************************************************************************//**
179  \param r <decimal> The radius length.
180  \param l <decimal> The edge length.
181 
182  \param p <integer> The profile identifier.
183  \param f <decimal> The mid-point offset factor.
184 
185  \param m <integer> The end finish mode: (B0: bottom, B1: top).
186  \param ba <decimal> The end bevel angle.
187 
188  \param a1 <decimal> The edge plane start angle.
189  \param a2 <decimal> The edge plane end angle.
190 
191  \param center <boolean> Center length about origin.
192 
193  \details
194 
195  \b Example
196  \amu_eval ( function=edge_add_r ${example_dim} )
197 
198  | m | B1 | B0 | Description |
199  |:---:|:---:|:---:|:------------------------------|
200  | 0 | 0 | 0 | cut bottom (-z) and top (+z) |
201  | 1 | 0 | 1 | bevel bottom and cut top |
202  | 2 | 1 | 0 | cut bottom and bevel top |
203  | 3 | 1 | 1 | bevel bottom and top |
204 
205  See edge_profile_r() for description of available profiles.
206 *******************************************************************************/
207 module edge_add_r
208 (
209  r,
210  l = 1,
211  p = 0,
212  f = 1,
213  m = 3,
214  ba = 45,
215  a1 = 0,
216  a2 = 90,
217  center = false
218 )
219 {
220  sa = a2-a1;
221 
222  wx = (p == 0) ? max(r, r*f)
223  : (p == 1) ? r/tan(sa/2)
224  : max(r, r*f);
225 
226  wy = (p == 0) ? r
227  : (p == 1) ? r/tan(sa/2)
228  : r ;
229 
230  wz = wx*tan(ba);
231 
232  rotate([0, 0, a1])
233  translate(center==true ? origin3d : [0, 0, l/2])
234  difference()
235  {
236  translate([0,0,-l/2])
237  linear_extrude(height=l)
238  edge_profile_r(r, p, f, sa);
239 
240  rotate([0,0,sa/2])
241  for ( c = [0, 1] )
242  {
243  if ( bitwise_is_equal(m, c, 1) )
244  mirror([0, 0, c])
245  polyhedron
246  (
247  points =
248  [
249  [ 0, -wy, -(l/2+aeps)],
250  [ 0, +wy, -(l/2+aeps)],
251  [wx, +wy, -(l/2+aeps)],
252  [wx, -wy, -(l/2+aeps)],
253  [wx, -wy, -(l/2-aeps-wz)],
254  [wx, +wy, -(l/2-aeps-wz)]
255  ],
256  faces = [[1,5,4,0], [0,4,3], [1,2,5], [5,2,3,4], [2,1,0,3]]
257  );
258  }
259  }
260 }
261 
262 //! @}
263 //! @}
264 
265 //----------------------------------------------------------------------------//
266 // openscad-amu auxiliary scripts
267 //----------------------------------------------------------------------------//
268 
269 /*
270 BEGIN_SCOPE dim;
271  BEGIN_OPENSCAD;
272  include <tools/tools_edge.scad>;
273 
274  shape = "edge_profile_r";
275  $fn = 72;
276 
277  if (shape == "edge_profile_r")
278  edge_profile_r( r=5, p=1, f=1+10/100, a=75 );
279  else if (shape == "edge_add_r")
280  rotate([90,-90,90]) edge_add_r( r=5, l=20, f=5/8, center=true );
281  END_OPENSCAD;
282 
283  BEGIN_MFSCRIPT;
284  include --path "${INCLUDE_PATH}" {config_base,config_png}.mfs;
285 
286  views name "views" views "top diag";
287  defines name "shapes" define "shape"
288  strings "
289  edge_profile_r
290  edge_add_r
291  ";
292  variables add_opts_combine "views shapes";
293  variables add_opts "--viewall --autocenter";
294 
295  include --path "${INCLUDE_PATH}" script_std.mfs;
296  END_MFSCRIPT;
297 END_SCOPE;
298 
299 BEGIN_SCOPE manifest;
300  BEGIN_OPENSCAD;
301  include <tools/tools_edge.scad>;
302 
303  $fn = 72;
304 
305  grid_repeat( g=5, i=10, center=true )
306  {
307  linear_extrude(1) edge_profile_r( r=5, p=1, f=1+10/100, a=75 );
308  edge_add_r( r=5, l=20, f=5/8, center=true );
309  }
310  END_OPENSCAD;
311 
312  BEGIN_MFSCRIPT;
313  include --path "${INCLUDE_PATH}" {config_base,config_stl}.mfs;
314  include --path "${INCLUDE_PATH}" script_std.mfs;
315  END_MFSCRIPT;
316 END_SCOPE;
317 */
318 
319 //----------------------------------------------------------------------------//
320 // end of file
321 //----------------------------------------------------------------------------//
module edge_profile_r(r, p=0, f=1, a=90,)
A 2d edge-finish profile specified by intersection radius.
module edge_add_r(r, l=1, p=0, f=1, m=3, ba=45, a1=0, a2=90, center=false)
A 3d edge-finish additive shape specified by intersection radius.
module ellipse_s(size, a1=0, a2=0)
An ellipse sector.
Definition: shapes2d.scad:1186
function unit_l(l)
Compute the normalized unit vector of a Euclidean line (or vector).
origin3d
The origin point coordinate in 3-dimensional Euclidean space.
Definition: constants.scad:127
function bitwise_is_equal(v, b, t=1)
Test if a base-two bit position of an integer value equals a test bit.
aeps
Epsilon, small distance to deal with overlapping shapes.
Definition: constants.scad:45