omdl  v0.9.5
OpenSCAD Mechanical Design Library
dimension.scad
Go to the documentation of this file.
1 //! Drafting dimension operations.
2 /***************************************************************************//**
3  \file
4  \author Roy Allen Sutton
5  \date 2019-2023
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  \amu_define group_name (Dimension)
31  \amu_define group_brief (Drafting dimension operations.)
32 
33  \amu_include (include/amu/pgid_path_pstem_g.amu)
34 *******************************************************************************/
35 
36 //----------------------------------------------------------------------------//
37 // group.
38 //----------------------------------------------------------------------------//
39 
40 /***************************************************************************//**
41  \amu_include (include/amu/group_in_parent_start.amu)
42 
43  \amu_include (include/amu/scope_diagram_2d_object.amu)
44 *******************************************************************************/
45 
46 //----------------------------------------------------------------------------//
47 
48 //----------------------------------------------------------------------------//
49 // dimension operations
50 //----------------------------------------------------------------------------//
51 
52 //! \name Dimensioning
53 //! @{
54 
55 //! Construct a dimension leader line at a point.
56 /***************************************************************************//**
57  \param p <point-2d> The leader line point.
58 
59  \param v1 <line-2d | decimal> The leader line 1 angle.
60  A 2d line, vector, or decimal angle.
61  \param l1 <decimal> The leader line 1 length.
62  \param v2 <line-2d | decimal> The leader line 2 angle.
63  A 2d line, vector, or decimal angle.
64  \param l2 <decimal> The leader line 2 length.
65 
66  \param h <string> An optional text heading.
67  \param t <string | string-list> A single or multi-line text string.
68  \param ts <decimal-list-3> A list of decimals that define the
69  <width, line-height, heading-height> of the text.
70  \param tp <integer-list-2> The text alignment point.
71  A list [tpx, tpy] of decimals. Requires \p tr.
72  \param tr <decimal> The text rotation angle.
73  \param ta <string> The text horizontal alignment. One of:
74  < \b "left" | \b "center" | \b "right" >.
75 
76  \param bw <decimal> The boarder line weight.
77  \param bs <integer | integer-list> The boarder line [style].
78 
79  \param w <decimal> The line weight.
80  \param s <integer | integer-list> The line [style].
81  \param a <integer | integer-list-5> The arrowhead [style][arrow].
82 
83  \param o <decimal> The leader point offset.
84 
85  \param cmh <decimal> The horizontal width minimum unit cell size.
86  \param cmv <decimal> The vertical height minimum unit cell size.
87 
88  \param window <boolean> Return text window rectangle.
89  \param layers <string-list> The List of drafting layer names.
90 
91  \details
92 
93  \amu_eval ( html_image_w=256 latex_image_w="1.50in" object=draft_dim_leader ${object_diagram_2d} )
94 
95  [style]: \ref draft_line()
96  [arrow]: \ref draft_arrow()
97 *******************************************************************************/
98 module draft_dim_leader
99 (
100  p = origin2d,
101 
102  v1 = 30,
103  l1 = draft_get_config("dim-leader-length"),
104  v2,
105  l2,
106 
107  h,
108  t,
109  ts,
110  tp,
111  tr,
112  ta = "center",
113 
114  bw = draft_get_config("dim-leader-box-weight"),
115  bs = draft_get_config("dim-leader-box-style"),
116 
117  w = draft_get_config("dim-leader-weight"),
118  s = draft_get_config("dim-leader-style"),
119  a = draft_get_config("dim-leader-arrow"),
120 
121  o = draft_get_config("dim-offset"),
122 
123  cmh = draft_get_config("dim-cmh"),
124  cmv = draft_get_config("dim-cmv"),
125 
126  window = false,
127  layers = draft_get_config("layers-dim")
128 )
129 {
130  if (draft_layers_any_active(layers))
132  {
133  // offset
134  plo = is_undef(o) ? p
135  : is_number(v1) ? line_tp(line2d_new(m=o, a=v1, p1=p))
136  : line_tp(line2d_new(m=o, v=v1, p1=p));
137 
138  // leader 1
139  ll1 = is_number(v1) ? line2d_new(m=l1, a=v1, p1=plo)
140  : line2d_new(m=l1, v=v1, p1=plo);
141 
142  draft_line(l=ll1, w=w, s=s, a1=a);
143 
144 
145  // leader 2
146  dv2 = defined_or(v2, ll1);
147  dl2 = defined_or(l2, l1);
148 
149  ll2 = is_number(v2) ? line2d_new(m=dl2, a=dv2, p1=line_tp(ll1))
150  : line2d_new(m=dl2, v=dv2, p1=line_tp(ll1));
151 
152  draft_line(l=ll2, w=w, s=s);
153 
154  // text rotation
155  tra = is_undef(tr) ? angle_ll(x_axis2d_uv, ll2, false)
156  : is_number(tr) ? tr
157  : angle_ll(x_axis2d_uv, tr, false);
158 
159  // text alignment point
160  dtp = is_undef(tr) ? [-1, 0]
161  : is_defined(tp) ? tp
162  : let( al2 = (angle_ll(x_axis2d_uv, ll2, false)+360-tra)%360 )
163  (al2> 45 && al2< 135) ? [ 0, 1]
164  : (al2>=135 && al2<=225) ? [ 1, 0]
165  : (al2> 225 && al2< 315) ? [ 0,-1]
166  : [-1, 0];
167 
168  translate( line_tp(ll2) )
169  rotate( [0, 0, tra] )
170  draft_note
171  (
172  head=h,
173  note=t,
174  size=ts,
175  line=[bw, bs],
176  halign=ta,
177  cmh=cmh,
178  cmv=cmv,
179  zp=dtp,
180  window=window,
181  layers=layers,
182  $draft_make_3d=false
183  );
184  }
185 }
186 
187 //! Construct a dimension line between two points.
188 /***************************************************************************//**
189  \param p1 <point-2d> The dimension point 1.
190  \param p2 <point-2d> The dimension point 2.
191 
192  \param v1 <line-2d | decimal> The point 1 extension line vector.
193  A 2d line, vector, or decimal angle.
194  \param v2 <line-2d | decimal> The point 2 extension line vector.
195  A 2d line, vector, or decimal angle.
196 
197  \param t <string | string-list> A single or multi-line text string
198  that overrides the measured distance.
199  \param u <string> The units for the measured distance.
200  One of the predefined in \ref units_length.
201 
202  \param d <decimal | decimal-list-2> The minimum distance between the
203  reference point and the start of the extension line.
204  A list [d1, d2] of decimals or a single decimal for (d1=d2).
205  \param e <decimal | decimal-list-2> The length of the extension line.
206  A list [e1, e2] of decimals or a single decimal for (e1=e2).
207  \param es <integer | integer-list> The extension line [style].
208 
209  \param w <decimal> The line weight.
210  \param s <integer | integer-list> The line [style].
211  \param a <integer | integer-list-5> The arrowheads [style][arrow].
212 
213  \param a1 <integer | integer-list-5> The arrowhead 1 [style][arrow]
214  override.
215  \param a2 <integer | integer-list-5> The arrowhead 2 [style][arrow]
216  override.
217 
218  \param o <decimal> The dimension line offset.
219 
220  \param ts <decimal-list-3> A list of decimals that define the
221  <width, line-height, heading-height> of the text.
222  \param tp <integer-list-2> The text alignment point.
223  A list [tpx, tpy] of decimals.
224  \param rm <integer> The measurement rounding mode.
225  One of: 0=none, 1=[round_d], and 2=[round_s].
226 
227  \param cmh <decimal> The horizontal width minimum unit cell size.
228  \param cmv <decimal> The vertical height minimum unit cell size.
229 
230  \param layers <string-list> The List of drafting layer names.
231 
232  \details
233 
234  Only one of \p v1 or \p v2 should normally be used at a time. When
235  neither is specified, the extension line vector angle will be at a
236  right angle to the line formed by the dimension points \p p1 and \p
237  p2.
238 
239  \amu_eval ( html_image_w=512 latex_image_w="3.00in" object=draft_dim_line ${object_diagram_2d} )
240 
241  [style]: \ref draft_line()
242  [arrow]: \ref draft_arrow()
243  [round_d]: \ref round_d()
244  [round_s]: \ref round_s()
245 *******************************************************************************/
246 module draft_dim_line
247 (
248  p1 = origin2d,
249  p2 = origin2d,
250 
251  v1,
252  v2,
253 
254  t,
255  u,
256 
257  d = draft_get_config("dim-line-distance"),
258  e = draft_get_config("dim-line-extension-length"),
259  es = draft_get_config("dim-line-extension-style"),
260 
261  w = draft_get_config("dim-line-weight"),
262  s = draft_get_config("dim-line-style"),
263  a = draft_get_config("dim-line-arrow"),
264 
265  a1,
266  a2,
267 
268  o = draft_get_config("dim-offset"),
269 
270  ts = draft_get_config("dim-text-size"),
271  tp = draft_get_config("dim-text-place"),
272  rm = draft_get_config("dim-round-mode"),
273 
274  cmh = draft_get_config("dim-cmh"),
275  cmv = draft_get_config("dim-cmv"),
276 
277  layers = draft_get_config("layers-dim")
278 )
279 {
280  if (draft_layers_any_active(layers))
282  {
283  // identify measurement reference points
284  // only one of 'v1', 'v2' should normally be used at a time
285  // create vector if numerical angle has been specified.
286  mr1 = is_undef(v1) ? p1
287  : let( va1 = is_number(v1) ? line2d_new(a=v1, p1=p1) : v1 )
288  point_closest_pl(p2, va1);
289  mr2 = is_undef(v2) ? p2
290  : let( va2 = is_number(v2) ? line2d_new(a=v2, p1=p2) : v2 )
291  point_closest_pl(p1, va2);
292 
293  // minimum distance from reference points to dimension line
294  dm1 = defined_e_or(d, 0, d);
295  dm2 = defined_e_or(d, 1, dm1);
296 
297  // extension line lengths (back towards reference points)
298  de1 = defined_e_or(e, 0, e);
299  de2 = defined_e_or(e, 1, de1);
300 
301  // extension lines angle
302  // construct perpendicular to line form by reference points
303  ape = angle_ll(x_axis2d_uv, [mr1, mr2]) + 90;
304 
305  // minimum distances to dimension line
306  dmt = max(dm1, dm2);
307 
308  // extension line end points
309  pe1 = line_tp(line2d_new(m=dmt, a=ape, p1=mr1));
310  pe2 = line_tp(line2d_new(m=dmt, a=ape, p1=mr2));
311 
312  // dimension line offset at extension line end-points
313  pd1 = line_tp(line2d_new(m=-o, a=ape, p1=pe1));
314  pd2 = line_tp(line2d_new(m=-o, a=ape, p1=pe2));
315 
316  //
317  // draft
318  //
319 
320  // extension lines
321  draft_line(l=line2d_new(m=-de1, a=ape, p1=pe1), w=w/2, s=es);
322  draft_line(l=line2d_new(m=-de2, a=ape, p1=pe2), w=w/2, s=es);
323 
324  // dimension text
325  dt = is_defined(t) ? t
326  : let
327  (
328  // measure distance between reference points
329  md = distance_pp(mr1, mr2),
330 
331  // use specified units 'u'
332  du = is_undef(u) ? md
333  : length(md, from=length_unit_base, to=u),
334 
335  // rounding: [mode:0, digits]
336  rs = defined_e_or(rm, 0, 0),
337 
338  rd = rs == 1 ? round_d(du, defined_e_or(rm, 1, 2))
339  : rs == 2 ? round_s(du, defined_e_or(rm, 1, 3))
340  : du
341  )
342  // add units id when 'u' is specified
343  is_undef(u) ? str(rd) : str(rd, " ", u);
344 
345  // individual or common arrowheads
346  da1 = defined_or(a1, a);
347  da2 = defined_or(a2, a);
348 
349  // when text placed over line
350  if ( second(tp) == 0 && !is_empty(dt) )
351  difference()
352  {
353  // remove window from dimension line for text
354  draft_line(l=[pd1, pd2], w=w, s=s, a1=da1, a2=da2);
355 
356  translate( (pd1+pd2)/2 )
357  rotate( [0, 0, ape-90] )
358  draft_note
359  (
360  note=dt,
361  size=ts,
362  line=[0,0],
363  halign="center",
364  cmh=cmh,
365  cmv=cmv,
366  zp=tp,
367  window=true,
368  layers=layers,
369  $draft_make_3d=false
370  );
371  }
372  else
373  {
374  draft_line(l=[pd1, pd2], w=w, s=s, a1=da1, a2=da2);
375  }
376 
377  if ( !is_empty(dt) )
378  translate( (pd1+pd2)/2 )
379  rotate( [0, 0, ape-90] )
380  draft_note
381  (
382  note=dt,
383  size=ts,
384  line=[0,0],
385  halign="center",
386  cmh=cmh,
387  cmv=cmv,
388  zp=tp,
389  window=false,
390  layers=layers,
391  $draft_make_3d=false
392  );
393  }
394 }
395 
396 //! Construct a radial dimension line.
397 /***************************************************************************//**
398  \param c <point-2d> The radius center point.
399 
400  \param p <point-2d> A point on the radius.
401  \param r <decimal> The radius length.
402  \param v <line-2d | decimal> The dimension line angle for radius \p r.
403  A 2d line, vector, or decimal angle.
404 
405  \param t <string | string-list> A single or multi-line text string
406  that overrides the measured length.
407  \param u <string> The units for the measured length.
408  One of the predefined in \ref units_length.
409 
410  \param d <boolean> Construct a diameter dimension line.
411 
412  \param w <decimal> The line weight.
413  \param s <integer | integer-list> The line [style].
414  \param a <integer | integer-list-5> The arrowheads [style][arrow].
415 
416  \param a1 <integer | integer-list-5> The arrowhead 1 [style][arrow]
417  override.
418  \param a2 <integer | integer-list-5> The arrowhead 2 [style][arrow]
419  override.
420 
421  \param o <decimal | decimal-list-2> The dimension line offset. A list
422  [o1, o2] of decimals or a single decimal for (o1=o2).
423 
424  \param ts <decimal-list-3> A list of decimals that define the
425  <width, line-height, heading-height> of the text.
426  \param tp <integer-list-2> The text alignment point.
427  A list [tpx, tpy] of decimals.
428  \param rm <integer> The measurement rounding mode.
429  One of: 0=none, 1=[round_d], and 2=[round_s].
430 
431  \param cmh <decimal> The horizontal width minimum unit cell size.
432  \param cmv <decimal> The vertical height minimum unit cell size.
433 
434  \param layers <string-list> The List of drafting layer names.
435 
436  \details
437 
438  \amu_eval ( html_image_w=256 latex_image_w="1.50in" object=draft_dim_radius ${object_diagram_2d} )
439 
440  [style]: \ref draft_line()
441  [arrow]: \ref draft_arrow()
442  [round_d]: \ref round_d()
443  [round_s]: \ref round_s()
444 *******************************************************************************/
445 module draft_dim_radius
446 (
447  c = origin2d,
448 
449  p,
450  r = 1,
451  v,
452 
453  t,
454  u,
455 
456  d = false,
457 
458  w = draft_get_config("dim-radius-weight"),
459  s = draft_get_config("dim-radius-style"),
460  a = draft_get_config("dim-radius-arrow"),
461 
462  a1,
463  a2,
464 
465  o = draft_get_config("dim-offset"),
466 
467  ts = draft_get_config("dim-text-size"),
468  tp = draft_get_config("dim-text-place"),
469  rm = draft_get_config("dim-round-mode"),
470 
471  cmh = draft_get_config("dim-cmh"),
472  cmv = draft_get_config("dim-cmv"),
473 
474  layers = draft_get_config("layers-dim")
475 )
476 {
477  if (draft_layers_any_active(layers))
479  {
480  // identify radius reference points
481  // create vector if numerical angle has been specified.
482  rr1 = c;
483  rr2 = is_defined(p) ? p
484  : is_undef(v) ? line_tp(line2d_new(m=r, p1=c))
485  : is_number(v) ? line_tp(line2d_new(m=r, a=v, p1=c))
486  : line_tp(line2d_new(m=r, v=v, p1=c));
487 
488  // identify measurement reference points
489  mr1 = d ? line_tp(line2d_new(m=distance_pp(rr1, rr2), v=[rr2, rr1], p1=rr1))
490  : rr1;
491  mr2 = rr2;
492 
493  // minimum distance from reference points to dimension line
494  do1 = defined_e_or(o, 0, o);
495  do2 = defined_e_or(o, 1, d ? do1 : 0);
496 
497  // dimension lines angle
498  ape = angle_ll(x_axis2d_uv, [mr1, mr2]);
499 
500  // dimension line offset at end-points
501  pd1 = (do1 == 0) ? mr1
502  : line_tp( line2d_new(m=distance_pp(mr1, mr2)-do1, v=[mr2, mr1], p1=mr2) );
503  pd2 = (do2 == 0) ? mr2
504  : line_tp( line2d_new(m=distance_pp(mr1, mr2)-do2, v=[mr1, mr2], p1=mr1) );
505 
506  //
507  // draft
508  //
509 
510  // dimension text
511  dt = is_defined(t) ? t
512  : let
513  (
514  // measure distance between reference points
515  md = distance_pp(mr1, mr2),
516 
517  // use specified units 'u'
518  du = is_undef(u) ? md
519  : length(md, from=length_unit_base, to=u),
520 
521  // rounding: [mode:0, digits]
522  rs = defined_e_or(rm, 0, 0),
523 
524  rd = rs == 1 ? round_d(du, defined_e_or(rm, 1, 2))
525  : rs == 2 ? round_s(du, defined_e_or(rm, 1, 3))
526  : du,
527 
528  rt = d ? "D" : "R"
529  )
530  // add units id when 'u' is specified
531  is_undef(u) ? str(rt, " ", rd) : str(rt, " ", rd, " ", u);
532 
533  // individual or common arrowheads
534  da1 = defined_or(a1, d ? a : 0);
535  da2 = defined_or(a2, a);
536 
537  // when text placed over line
538  if ( second(tp) == 0 && !is_empty(dt) )
539  difference()
540  {
541  // remove window from dimension line for text
542  draft_line(l=[pd1, pd2], w=w, s=s, a1=da1, a2=da2);
543 
544  translate( (pd1+pd2)/2 )
545  rotate( [0, 0, ape] )
546  draft_note
547  (
548  note=dt,
549  size=ts,
550  line=[0,0],
551  halign="center",
552  cmh=cmh,
553  cmv=cmv,
554  zp=tp,
555  window=true,
556  layers=layers,
557  $draft_make_3d=false
558  );
559  }
560  else
561  {
562  draft_line(l=[pd1, pd2], w=w, s=s, a1=da1, a2=da2);
563  }
564 
565  if ( !is_empty(dt) )
566  translate( (pd1+pd2)/2 )
567  rotate( [0, 0, ape] )
568  draft_note
569  (
570  note=dt,
571  size=ts,
572  line=[0,0],
573  halign="center",
574  cmh=cmh,
575  cmv=cmv,
576  zp=tp,
577  window=false,
578  layers=layers,
579  $draft_make_3d=false
580  );
581  }
582 }
583 
584 //! Construct a angular dimension arc.
585 /***************************************************************************//**
586  \param c <point-2d> The arc center point.
587  \param r <decimal> The arc radius length.
588 
589  \param v1 <line-2d | decimal> The arc initial angle.
590  A 2d line, vector, or decimal angle.
591  \param v2 <line-2d | decimal> The arc terminal angle.
592  A 2d line, vector, or decimal angle.
593 
594  \param fn <integer> The number of [facets].
595  \param cw <boolean> Sweep clockwise along arc from the head of
596  vector \p v1 to the head of vector \p v2 when \p cw =
597  \b true, and counter clockwise when \p cw = \b false.
598 
599  \param t <string | string-list> A single or multi-line text string
600  that overrides the measured angle.
601  \param u <string> The units for the measured angle.
602  One of the predefined in \ref units_angle.
603 
604  \param e <decimal | decimal-list-2> The extension line to radius ratio.
605  A list [e1, e2] of decimals or a single decimal for (e1=e2).
606  \param es <integer | integer-list> The extension line [style].
607 
608  \param w <decimal> The arc weight.
609  \param s <integer | integer-list> The arc [style].
610  \param a <integer | integer-list-5> The arrowheads [style][arrow].
611 
612  \param a1 <integer | integer-list-5> The arrowhead 1 [style][arrow]
613  override.
614  \param a2 <integer | integer-list-5> The arrowhead 2 [style][arrow]
615  override.
616 
617  \param o <decimal> The dimension arc offset.
618 
619  \param ts <decimal-list-3> A list of decimals that define the
620  <width, line-height, heading-height> of the text.
621  \param tp <integer-list-4> The text alignment point.
622  A list [tpx, tpy, tpa, tra] of decimals, where \p tpa is
623  the text pivot angle and \p tra is the text rotation angle.
624  \param rm <integer> The measurement rounding mode.
625  One of: 0=none, 1=[round_d], and 2=[round_s].
626 
627  \param cmh <decimal> The horizontal width minimum unit cell size.
628  \param cmv <decimal> The vertical height minimum unit cell size.
629 
630  \param layers <string-list> The List of drafting layer names.
631 
632  \details
633 
634  \amu_eval ( html_image_w=256 latex_image_w="1.50in" object=draft_dim_angle ${object_diagram_2d} )
635 
636  [facets]: \ref get_fn()
637  [style]: \ref draft_line()
638  [arrow]: \ref draft_arrow()
639  [round_d]: \ref round_d()
640  [round_s]: \ref round_s()
641 *******************************************************************************/
642 module draft_dim_angle
643 (
644  c = origin2d,
645  r = 1,
646 
647  v1,
648  v2,
649 
650  fn,
651  cw = false,
652 
653  t,
654  u,
655 
656  e = draft_get_config("dim-angle-extension-ratio"),
657  es = draft_get_config("dim-angle-extension-style"),
658 
659  w = draft_get_config("dim-angle-weight"),
660  s = draft_get_config("dim-angle-style"),
661  a = draft_get_config("dim-angle-arrow"),
662 
663  a1,
664  a2,
665 
666  o = draft_get_config("dim-offset"),
667 
668  ts = draft_get_config("dim-text-size"),
669  tp = draft_get_config("dim-text-place"),
670  rm = draft_get_config("dim-round-mode"),
671 
672  cmh = draft_get_config("dim-cmh"),
673  cmv = draft_get_config("dim-cmv"),
674 
675  layers = draft_get_config("layers-dim")
676 )
677 {
678  if (draft_layers_any_active(layers))
680  {
681  // identify measurement reference points at center 'c'
682  // handle (1) point, (2) angle, or (3) vector.
683  mr1 = is_point(v1) ? v1
684  : is_number(v1) ? line_tp(line2d_new(a=v1, p1=c))
685  : line_tp(line2d_new(v=v1, p1=c));
686  mr2 = is_point(v2) ? v2
687  : is_number(v2) ? line_tp(line2d_new(a=v2, p1=c))
688  : line_tp(line2d_new(v=v2, p1=c));
689 
690  // extension line to radius ratio
691  er1 = defined_e_or(e, 0, e);
692  er2 = defined_e_or(e, 1, er1);
693 
694  // extension line end points
695  pe1 = line_tp(line2d_new(m=r, v=[c, mr1], p1=c));
696  pe2 = line_tp(line2d_new(m=r, v=[c, mr2], p1=c));
697 
698  // dimension text angle and position
699  dta = angle_ll(x_axis2d_uv, cw ? [mr1, mr2] : [mr2, mr1], false)
700  + defined_or(third(tp), 0);
701  dtp = line_tp(line2d_new(m=r-o, a=dta+90, p1=c));
702 
703  //
704  // draft
705  //
706 
707  // extension lines (back towards center point)
708  draft_line(l=line2d_new(m=r*er1, v=[mr1, c], p1=pe1), w=w/2, s=es);
709  draft_line(l=line2d_new(m=r*er2, v=[mr2, c], p1=pe2), w=w/2, s=es);
710 
711  // dimension text
712  dt = is_defined(t) ? t
713  : let
714  (
715  // measure angle between reference points
716  ma = cw ?
717  angle_ll([c, mr2], [c, mr1], false)
718  : angle_ll([c, mr1], [c, mr2], false),
719 
720  // use specified units 'u'
721  au = is_undef(u) ? ma
722  : angle(ma, from=angle_unit_base, to=u),
723 
724  // rounding: [mode:0, digits]
725  rs = defined_e_or(rm, 0, 0),
726 
727  rd = rs == 1 ? round_d(au, defined_e_or(rm, 1, 2))
728  : rs == 2 ? round_s(au, defined_e_or(rm, 1, 3))
729  : au
730  )
731  // add units id when 'u' is specified
732  is_undef(u) ? str(rd) : str(rd, " ", u);
733 
734  // individual or common arrowheads
735  da1 = defined_or(a1, a);
736  da2 = defined_or(a2, a);
737 
738  // when text placed over line
739  if ( second(tp) == 0 && !is_empty(dt) )
740  difference()
741  {
742  // remove window from dimension line for text
743  draft_arc(r=r-o, c=c, v1=[c, pe1], v2=[c, pe2], fn=fn, cw=cw, w=w, s=s, a1=da1, a2=da2);
744 
745  translate( dtp )
746  rotate( [0, 0, dta + defined_or(tp[3], 0)] )
747  draft_note
748  (
749  note=dt,
750  size=ts,
751  line=[0,0],
752  halign="center",
753  cmh=cmh,
754  cmv=cmv,
755  zp=tp,
756  window=true,
757  layers=layers,
758  $draft_make_3d=false
759  );
760  }
761  else
762  {
763  draft_arc(r=r-o, c=c, v1=[c, pe1], v2=[c, pe2], fn=fn, cw=cw, w=w, s=s, a1=da1, a2=da2);
764  }
765 
766  if ( !is_empty(dt) )
767  translate( dtp )
768  rotate( [0, 0, dta + defined_or(tp[3], 0)] )
769  draft_note
770  (
771  note=dt,
772  size=ts,
773  line=[0,0],
774  halign="center",
775  cmh=cmh,
776  cmv=cmv,
777  zp=tp,
778  window=false,
779  layers=layers,
780  $draft_make_3d=false
781  );
782  }
783 }
784 
785 //! Construct a center mark dimension cross.
786 /***************************************************************************//**
787  \param c <point-2d> The center point.
788 
789  \param r <decimal> A circular arc radius.
790 
791  \param v <line-2d | decimal> The cross rotation angle.
792  A 2d line, vector, or decimal angle.
793  \param l <decimal> The cross line length.
794 
795  \param e <decimal | decimal-list-4> The length of the extension lines.
796  A list [e1, e2, e3, e4] of decimals or a single decimal for
797  (e1=e2=e3=e4).
798  \param es <integer | integer-list> The extension line [style].
799 
800  \param w <decimal> The line weight.
801  \param s <integer | integer-list> The line [style].
802 
803  \param layers <string-list> The List of drafting layer names.
804 
805  \details
806 
807  \amu_eval ( html_image_w=512 latex_image_w="3.00in" object=draft_dim_center ${object_diagram_2d} )
808 
809  [style]: \ref draft_line()
810 *******************************************************************************/
811 module draft_dim_center
812 (
813  c = origin2d,
814 
815  r,
816 
817  v = 0,
818  l = draft_get_config("dim-center-length"),
819 
820  e,
821  es = draft_get_config("dim-angle-extension-style"),
822 
823  w = draft_get_config("dim-center-weight"),
824  s = draft_get_config("dim-center-style"),
825 
826  layers = draft_get_config("layers-dim")
827 )
828 {
829  if (draft_layers_any_active(layers))
831  {
832  // alignment angle
833  aa = is_number(v) ? v : angle_ll(x_axis2d_uv, v);
834 
835  //
836  // draft
837  //
838 
839  // center
840  for ( q = [0,1] )
841  {
842  la = aa + 90*q;
843  p1 = c - l * [cos(la), sin(la)];
844 
845  draft_line(l=line2d_new(m=l*2, a=la, p1=p1), w=w, s=s);
846  }
847 
848  // radius
849  if ( is_defined(r) )
850  for ( q = [0:3] )
851  {
852  la = aa + 90*q;
853  p1 = c + (r-l) * [cos(la), sin(la)]; // radius
854  p2 = c + (r-l/2)/2 * [cos(la), sin(la)]; // mid
855 
856  draft_line(l=line2d_new(m=l*2, a=la, p1=p1), w=w, s=s);
857  draft_line(l=line2d_new(m=l/2, a=la, p1=p2), w=w, s=s);
858  }
859 
860  // individual extensions
861  rs = is_defined(r) ? (r + 2*l) : (2*l); // radial start distance
862  dl = defined_e_or(e, 0, e); // default length
863 
864  if ( is_defined(e) )
865  for ( q = [0:3] )
866  {
867  la = aa + 90*q;
868  p1 = c + rs * [cos(la), sin(la)]; // start point
869  el = defined_e_or(e, q, dl) - rs; // individual lengths
870 
871  if (el > 0)
872  draft_line(l=line2d_new(m=el, a=la, p1=p1), w=w, s=es);
873  }
874 
875  }
876 }
877 
878 //! @}
879 
880 //! @}
881 //! @}
882 
883 //----------------------------------------------------------------------------//
884 // openscad-amu auxiliary scripts
885 //----------------------------------------------------------------------------//
886 
887 /*
888 BEGIN_SCOPE diagram;
889  BEGIN_OPENSCAD;
890  include <omdl-base.scad>;
891  include <tools/align.scad>;
892  include <tools/operation_cs.scad>;
893  include <tools/polytope.scad>;
894  include <tools/drafting/draft-base.scad>;
895 
896  object = "draft_dim_leader";
897 
898  if (object == "draft_dim_leader") {
899  draft_dim_leader (l1=25, v2=0, t="1");
900  }
901 
902  if (object == "draft_dim_line") {
903  draft_dim_line (p1=[0,0], p2=[100,0], u="cm");
904  }
905 
906  if (object == "draft_dim_radius") {
907  draft_arc (r=50, v1=90, s=2);
908  draft_dim_radius (r=50, v=45, u="cm", a1=[4,0,2]);
909  }
910 
911  if (object == "draft_dim_angle") {
912  draft_dim_angle (r=50, v1=0, v2=angle(pi/4+pi/16,"r"), u="dms");
913  }
914 
915  if (object == "draft_dim_center") {
916  draft_arc (r=25, w=1/4);
917  draft_dim_center (r=25, l=5, e=[100,0,100,0]);
918  }
919  END_OPENSCAD;
920 
921  BEGIN_MFSCRIPT;
922  include --path "${INCLUDE_PATH}" {var_init,var_gen_svg}.mfs;
923 
924  defines name "objects" define "object"
925  strings "
926  draft_dim_leader
927  draft_dim_line
928  draft_dim_radius
929  draft_dim_angle
930  draft_dim_center
931  ";
932  variables add_opts_combine "objects";
933  variables add_opts "--viewall --autocenter";
934 
935  include --path "${INCLUDE_PATH}" scr_make_mf.mfs;
936  END_MFSCRIPT;
937 END_SCOPE;
938 */
939 
940 //----------------------------------------------------------------------------//
941 // end of file
942 //----------------------------------------------------------------------------//
origin2d
<point-2d> The origin point coordinate in 2d Euclidean space.
Definition: constants.scad:407
x_axis2d_uv
<vector-2d> The unit vector of the positive x-axis in 2d Euclidean space.
Definition: constants.scad:410
function line_tp(l)
Return the terminal point of a line or vector.
function angle_ll(l1, l2, s=true)
Compute the angle between two lines or vectors in a 3d or 2d-space.
function is_point(v)
Test if a value defines a point.
function line2d_new(m=1, a=0, p1=origin2d, p2, v)
Construct a 2 dimensional directed line.
function point_closest_pl(p, l)
Compute the coordinates of the closest point on a line to a given point.
function distance_pp(p1, p2)
Compute the distance between two points.
function defined_e_or(v, i, d)
Return an element of an iterable when it exists or a default value otherwise.
function third(v)
Return the third element of an iterable value.
function second(v)
Return the second element of an iterable value.
function is_empty(v)
Test if an iterable value is empty.
function round_d(v, d=6)
Round a list of numbers to a fixed number of decimal point digits.
function round_s(v, d=6)
Round a list of numbers to a fixed number of significant figures.
function defined_or(v, d)
Return given value, if defined, or a secondary value, if primary is not defined.
function is_defined(v)
Test if a value is defined.
function is_number(v)
Test if a value is a number.
$draft_make_3d
<boolean> Extrude 2D drafted constructions to 3D.
Definition: config.scad:89
function draft_get_config(k)
Get drafting configuration default helper function.
module draft_dim_line(p1=origin2d, p2=origin2d, v1, v2, t, u, d=draft_get_config("dim-line-distance"), e=draft_get_config("dim-line-extension-length"), es=draft_get_config("dim-line-extension-style"), w=draft_get_config("dim-line-weight"), s=draft_get_config("dim-line-style"), a=draft_get_config("dim-line-arrow"), a1, a2, o=draft_get_config("dim-offset"), ts=draft_get_config("dim-text-size"), tp=draft_get_config("dim-text-place"), rm=draft_get_config("dim-round-mode"), cmh=draft_get_config("dim-cmh"), cmv=draft_get_config("dim-cmv"), layers=draft_get_config("layers-dim"))
Construct a dimension line between two points.
Definition: dimension.scad:372
module draft_dim_center(c=origin2d, r, v=0, l=draft_get_config("dim-center-length"), e, es=draft_get_config("dim-angle-extension-style"), w=draft_get_config("dim-center-weight"), s=draft_get_config("dim-center-style"), layers=draft_get_config("layers-dim"))
Construct a center mark dimension cross.
Definition: dimension.scad:949
module draft_dim_leader(p=origin2d, v1=30, l1=draft_get_config("dim-leader-length"), v2, l2, h, t, ts, tp, tr, ta="center", bw=draft_get_config("dim-leader-box-weight"), bs=draft_get_config("dim-leader-box-style"), w=draft_get_config("dim-leader-weight"), s=draft_get_config("dim-leader-style"), a=draft_get_config("dim-leader-arrow"), o=draft_get_config("dim-offset"), cmh=draft_get_config("dim-cmh"), cmv=draft_get_config("dim-cmv"), window=false, layers=draft_get_config("layers-dim"))
Construct a dimension leader line at a point.
Definition: dimension.scad:220
module draft_dim_angle(c=origin2d, r=1, v1, v2, fn, cw=false, t, u, e=draft_get_config("dim-angle-extension-ratio"), es=draft_get_config("dim-angle-extension-style"), w=draft_get_config("dim-angle-weight"), s=draft_get_config("dim-angle-style"), a=draft_get_config("dim-angle-arrow"), a1, a2, o=draft_get_config("dim-offset"), ts=draft_get_config("dim-text-size"), tp=draft_get_config("dim-text-place"), rm=draft_get_config("dim-round-mode"), cmh=draft_get_config("dim-cmh"), cmv=draft_get_config("dim-cmv"), layers=draft_get_config("layers-dim"))
Construct a angular dimension arc.
Definition: dimension.scad:776
module draft_dim_radius(c=origin2d, p, r=1, v, t, u, d=false, w=draft_get_config("dim-radius-weight"), s=draft_get_config("dim-radius-style"), a=draft_get_config("dim-radius-arrow"), a1, a2, o=draft_get_config("dim-offset"), ts=draft_get_config("dim-text-size"), tp=draft_get_config("dim-text-place"), rm=draft_get_config("dim-round-mode"), cmh=draft_get_config("dim-cmh"), cmv=draft_get_config("dim-cmv"), layers=draft_get_config("layers-dim"))
Construct a radial dimension line.
Definition: dimension.scad:575
module draft_note(head, note, size, line, halign="left", cmh=draft_get_config("note-cmh"), cmv=draft_get_config("note-cmv"), zp=0, window=false, layers=draft_get_config("layers-note"))
Construct a text note with optional heading and boarder.
module draft_line(l=x_axis2d_ul, w=1, s=1, a1=0, a2=0)
Draft a line with configurable style and optional arrowheads.
module draft_make_3d_if_configured()
Extrude 2D drafted constructions to 3D if configured.
function draft_layers_any_active(layers=draft_get_config("layers-default"))
Check if any identified layers are active.
module draft_arc(r=1, c=origin2d, v1=x_axis2d_uv, v2=x_axis2d_uv, fn, cw=true, w=1, s=1, a1=0, a2=0)
Draft an arc with configurable style and optional arrowheads.
function angle(a, from=angle_unit_default, to=angle_unit_base)
Convert an angle from some units to another.
angle_unit_base
<string> The base units for value storage.
Definition: angle.scad:491
function length(v, from=length_unit_default, to=length_unit_base, d=1)
Convert a value from from one units to another with dimensions.
length_unit_base
<string> The base units for value storage.
Definition: length.scad:736