omdl  v0.5
OpenSCAD Mechanical Design Library
tool_edge.scad
Go to the documentation of this file.
1 //! Shape edge finishing tools.
2 /***************************************************************************//**
3  \file tool_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 <shapes2d.scad>;
34 
35 //----------------------------------------------------------------------------//
36 /***************************************************************************//**
37  \addtogroup tools
38  @{
39 
40  \amu_define caption (Edge Finishing)
41 
42  \amu_make png_files (append=dim extension=png)
43  \amu_make eps_files (append=dim extension=png2eps)
44  \amu_shell file_cnt ("echo ${png_files} | wc -w")
45  \amu_shell cell_num ("seq -f '(%g)' -s '^' ${file_cnt}")
46 
47  \htmlonly
48  \amu_image_table
49  (
50  type=html columns=4 image_width="200" cell_files="${png_files}"
51  table_caption="${caption}" cell_captions="${cell_num}"
52  )
53  \endhtmlonly
54  \latexonly
55  \amu_image_table
56  (
57  type=latex columns=4 image_width="1.25in" cell_files="${eps_files}"
58  table_caption="${caption}" cell_captions="${cell_num}"
59  )
60  \endlatexonly
61 
62  \defgroup tools_edge Edge Finishing
63  \brief Shape edge finishing tools.
64  @{
65 *******************************************************************************/
66 //----------------------------------------------------------------------------//
67 
68 //----------------------------------------------------------------------------//
69 // amu macros
70 //----------------------------------------------------------------------------//
71 /***************************************************************************//**
72  \amu_define scope (tool_edge_dim)
73  \amu_define size (qvga)
74  \amu_define view (diag)
75 
76  \amu_define example_dim
77  (
78  \image html ${scope}_${size}_${view}_${function}.png "${function}"
79  \image latex ${scope}_${size}_${view}_${function}.eps "${function}" width=2.5in
80  \dontinclude ${scope}.scad \skipline ${function}(
81  )
82 *******************************************************************************/
83 //----------------------------------------------------------------------------//
84 
85 //! A 2D edge-finish profile specified by intersection radius.
86 /***************************************************************************//**
87  \param r <decimal> The radius length.
88  \param p <integer> The profile identifier.
89  \param f <decimal> The mid-point offset factor.
90  \param a <decimal> The sweep angle.
91 
92  \details
93 
94  \b Example
95  \amu_eval ( function=edge_profile_r view=top ${example_dim} )
96 
97  \b Profiles:
98 
99  | p | Description |
100  |:---:|:--------------------------------------|
101  | 0 | Two segment bevel with mid inflection |
102  | 1 | A cove with cut-out offset |
103  | 2 | A quarter round with offset |
104 
105  \note A offset factor greater than 1 moves the mid-point away
106  from the profile edge-vertex. A factor less than 1 move it
107  inwards towards the edge-vertex.
108 *******************************************************************************/
109 module edge_profile_r
110 (
111  r,
112  p = 0,
113  f = 1,
114  a = 90,
115 )
116 {
117  // bevel with mid inflection
118  if ( p == 0 )
119  {
120  c1x = r;
121  c3x = c1x*cos(a);
122  c3y = c1x*sin(a);
123 
124  mpc = f*[(c1x+c3x)/2, c3y/2];
125 
126  polygon([[0,0], [c1x,0], mpc, [c3x,c3y]]);
127  }
128  // cove with cut-out offset
129  else if ( p == 1 )
130  {
131  difference()
132  {
133  c1x = r/tan(a/2);
134  c3x = c1x*cos(a);
135  c3y = c1x*sin(a);
136 
137  polygon([[0,0], [c1x,0], [c3x,c3y]]);
138 
139  translate(f*[c1x,r])
140  circle(r=r);
141  }
142  }
143  // quarter round with offset
144  else if ( p == 2 )
145  {
146  c1x = r;
147  c3x = c1x*cos(a);
148  c3y = c1x*sin(a);
149 
150  mpc = unit_v([(c1x+c3x)/2, c3y/2]);
151 
152  if ( f < 1 )
153  intersection()
154  {
155  polygon([[0,0], [c1x,0], [c3x,c3y]]);
156 
157  translate(f*mpc - mpc)
158  ellipse_s(r, a1=0, a2=a);
159  }
160  else if ( f > 1 )
161  union()
162  {
163  polygon([[0,0], [c1x,0], [c3x,c3y]]);
164 
165  translate(f*mpc - mpc)
166  ellipse_s(r, a1=0, a2=a);
167  }
168  else
169  ellipse_s(r, a1=0, a2=a);
170  }
171 }
172 
173 //! A 3D edge-finish additive shape specified by intersection radius.
174 /***************************************************************************//**
175  \param r <decimal> The radius length.
176  \param l <decimal> The edge length.
177 
178  \param p <integer> The profile identifier.
179  \param f <decimal> The mid-point offset factor.
180 
181  \param m <integer> The end finish mode: (B0: bottom, B1: top).
182  \param ba <decimal> The end bevel angle.
183 
184  \param a1 <decimal> The edge intersection start angle.
185  \param a2 <decimal> The edge intersection end angle.
186 
187  \param center <boolean> Center length about origin.
188 
189  \details
190 
191  \b Example
192  \amu_eval ( function=edge_add_r ${example_dim} )
193 
194  | m | B1 | B0 | Description |
195  |:---:|:---:|:---:|:------------------------------|
196  | 0 | 0 | 0 | cut bottom (-z) and top (+z) |
197  | 1 | 0 | 1 | bevel bottom and cut top |
198  | 2 | 1 | 0 | cut bottom and bevel top |
199  | 3 | 1 | 1 | bevel bottom and top |
200 
201  See edge_profile_r() for description of available profiles.
202 *******************************************************************************/
203 module edge_add_r
204 (
205  r,
206  l = 1,
207  p = 0,
208  f = 1,
209  m = 3,
210  ba = 45,
211  a1 = 0,
212  a2 = 90,
213  center = false
214 )
215 {
216  sa = a2-a1;
217 
218  wx = (p == 0) ? max(r, r*f)
219  : (p == 1) ? r/tan(sa/2)
220  : max(r, r*f);
221 
222  wy = (p == 0) ? r
223  : (p == 1) ? r/tan(sa/2)
224  : r ;
225 
226  wz = wx*tan(ba);
227 
228  rotate([0, 0, a1])
229  translate(center==true ? origin3d : [0, 0, l/2])
230  difference()
231  {
232  translate([0,0,-l/2])
233  linear_extrude(height=l)
234  edge_profile_r(r, p, f, sa);
235 
236  rotate([0,0,sa/2])
237  for ( c = [0, 1] )
238  {
239  if ( bitwise_is_equal(m, c, 1) )
240  mirror([0, 0, c])
241  polyhedron
242  (
243  points =
244  [
245  [ 0, -wy, -(l/2+eps)],
246  [ 0, +wy, -(l/2+eps)],
247  [wx, +wy, -(l/2+eps)],
248  [wx, -wy, -(l/2+eps)],
249  [wx, -wy, -(l/2-eps-wz)],
250  [wx, +wy, -(l/2-eps-wz)]
251  ],
252  faces = [[1,5,4,0], [0,4,3], [1,2,5], [5,2,3,4], [2,1,0,3]]
253  );
254  }
255  }
256 }
257 
258 //! @}
259 //! @}
260 
261 //----------------------------------------------------------------------------//
262 // openscad-amu auxiliary scripts
263 //----------------------------------------------------------------------------//
264 
265 /*
266 BEGIN_SCOPE dim;
267  BEGIN_OPENSCAD;
268  include <tool_edge.scad>;
269 
270  shape = "edge_profile_r";
271  $fn = 72;
272 
273  if (shape == "edge_profile_r")
274  edge_profile_r( r=5, p=1, f=1+10/100, a=75 );
275  else if (shape == "edge_add_r")
276  rotate([90,-90,90]) edge_add_r( r=5, l=20, f=5/8, center=true );
277  END_OPENSCAD;
278 
279  BEGIN_MFSCRIPT;
280  include --path "${INCLUDE_PATH}" {config_base,config_png}.mfs;
281 
282  views name "views" views "top diag";
283  defines name "shapes" define "shape"
284  strings "
285  edge_profile_r
286  edge_add_r
287  ";
288  variables add_opts_combine "views shapes";
289  variables add_opts "--viewall --autocenter";
290 
291  include --path "${INCLUDE_PATH}" script_std.mfs;
292  END_MFSCRIPT;
293 END_SCOPE;
294 
295 BEGIN_SCOPE manifest;
296  BEGIN_OPENSCAD;
297  include <tool_edge.scad>;
298 
299  $fn = 72;
300 
301  st_cartesian_copy( grid=5, incr=10, center=true )
302  {
303  linear_extrude(1) edge_profile_r( r=5, p=1, f=1+10/100, a=75 );
304  edge_add_r( r=5, l=20, f=5/8, center=true );
305  }
306  END_OPENSCAD;
307 
308  BEGIN_MFSCRIPT;
309  include --path "${INCLUDE_PATH}" {config_base,config_stl}.mfs;
310  include --path "${INCLUDE_PATH}" script_std.mfs;
311  END_MFSCRIPT;
312 END_SCOPE;
313 */
314 
315 //----------------------------------------------------------------------------//
316 // end of file
317 //----------------------------------------------------------------------------//
module edge_profile_r(r, p=0, f=1, a=90,)
A 2D edge-finish profile specified by intersection radius.
Definition: tool_edge.scad:110
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.
Definition: tool_edge.scad:204
function unit_v(vt, vi)
Compute the normalized unit vector for a 1, 2, or 3 term vector.
module ellipse_s(size, a1=0, a2=0)
An ellipse sector.
Definition: shapes2d.scad:1171
eps
Epsilon, small distance to deal with overlaping shapes
Definition: constants.scad:47
origin3d
The origin coordinates in 3-dimensional Euclidean space.
Definition: constants.scad:114
function bitwise_is_equal(v, b, t=1)
Test if a base-two bit position of an integer value equals a test bit.