summaryrefslogtreecommitdiff
path: root/graphics/asymptote/doc/CAD.tex
blob: 270c528b85f5c8e542107a55308d96c883ad2c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
\documentclass{ltxguide}
\usepackage{graphicx}



\begin{document}



\title{Asymptote package CAD.asy\footnote{This document describes version 1.0.}}
\author{Mark Henning, Germany\thanks{URL: http://www.markhenning.de}}
\date{29 September 2006}
\maketitle



\tableofcontents



\section{Introduction}

The package {\tt CAD.asy} provides basic pen definitions and measurement functions for simple 2D CAD drawings according to DIN 15.



\section{Important rules for using this package}

If a function is declared like this:
%
\begin{verbatim}
void foo(int nParam1, string strParam2)
\end{verbatim}
%
You may call it \verb\foo(0, 'abc');\ or \verb\foo(nParam1=0, strParam2='abc');\. The definitions of the functions in this package may change in future version: the order of the parameters may be changed, new parameters may be inserted. Therefore it is \emph{strongly recommended} always calling the functions \verb\foo(nParam1=0, strParam2='abc');\.



\section{Usage}

To use the capabilities of the package, import it:
%
\begin{verbatim}
import CAD;
\end{verbatim}
%
All functions are encapsulated in the structure \verb\sCAD\. As the pen definitions may differ depending on the size of your drawing, you have to initialize the structure before drawing:

\begin{verbatim}
static sCAD Create(int nLineGroup = 1)
\end{verbatim}
%
The parameter \verb\nLineGroup\ depends on the size of your drawing. It specifies the line group to define the pens and thus the width used for the lines. The parameter has to be within the range $[0;3]$. The larger the value, the thicker the lines. Code example:
%
\begin{quote}\begin{verbatim}
sCAD cad = sCAD.Create();
\end{verbatim}\end{quote}

The created variable \verb\cad\ then provides the most important pens. Available pens are:
%
\begin{itemize}
\item The pens of group A:
	\begin{itemize}
	\item\verb\pA\
	\item\verb\pVisibleEdge\
	\item\verb\pVisibleContour\
	\item\verb\pUsableWindingLength\
	\item\verb\pSystemLine\
	\item\verb\pDiagramCurve\
	\item\verb\pSurfaceStructure\
	\end{itemize}
\item The pens of group B:
	\begin{itemize}
	\item\verb\pB\
	\item\verb\pLightEdge\
	\item\verb\pMeasureLine\
	\item\verb\pMeasureHelpLine\
	\item\verb\pMeasureLineBound\
	\item\verb\pReferenceLine\
	\item\verb\pHatch\
	\item\verb\pWindingGround\
	\item\verb\pDiagonalCross\
	\item\verb\pBendLine\
	\item\verb\pProjectionLine\
	\item\verb\pGrid\
	\end{itemize}
\item The pens of group C:
	\begin{itemize}
	\item\verb\pC\
	\item\verb\pFreehand\
	\end{itemize}
\item The pens of group E:
	\begin{itemize}
	\item\verb\pE\
	\item\verb\pSurfaceTreatmentAllowed\
	\end{itemize}
\item The pens of group F:
	\begin{itemize}
	\item\verb\pF\
	\item\verb\pInvisibleEdge\
	\item\verb\pInvisibleContour\
	\end{itemize}
\item The pens of group G:
	\begin{itemize}
	\item\verb\pG\
	\item\verb\pMiddleLine\
	\item\verb\pSymmetryLine\
	\item\verb\pPartialCircle\
	\item\verb\pCircularHole\
	\item\verb\pDivisionPlane\
	\item\verb\pTransferLine\
	\end{itemize}
\item The pens of group J:
	\begin{itemize}
	\item\verb\pJ\
	\item\verb\pCuttingPlane\
	\item\verb\pSurfaceTreatmentRequested\
	\end{itemize}
\item The pens of group K:
	\begin{itemize}
	\item\verb\pK\
	\item\verb\pContourBeforeDeformation\
	\item\verb\pAdjacentPartContour\
	\item\verb\pEndShapeRawMaterial\
	\item\verb\pContourEligibleType\
	\item\verb\pPartInFrontOfCuttingPlane\
	\end{itemize}
\end{itemize}
%
All pens of one group are the same. So there is no difference between the pen \verb\pA\ and the pen \verb\pVisibleEdge\. You may use the short names or the descriptive ones. The list of groups is not complete. I had no idea how to implement the pens of group D. For me, group H seems to be obsolete, and there is no group I contained in DIN 15. In the case I did something wrong translating the German names into English, the source file also contains the original German names of each pen. Whenever a drawing function does not allow you to select the pen, the right pen is selected automatically.



\begin{verbatim}
void MeasureLine(picture pic = currentpicture,
                 Label L,
                 pair pFrom,
                 pair pTo,
                 real dblLeft = 0,
                 real dblRight = 0,
                 real dblRelPosition = 0.5,
                 bool bSmallBound = false)
\end{verbatim}
%
This is the basic function to draw labeled straight measurement lines. \verb\pic\ denotes the picture the line has to be drawn into, \verb\L\ is the label of the line. The pairs \verb\pFrom\ and \verb\pTo\ are the start and the end point of the distance to measure, respectively. Note, that these two points do \emph{not} refer to the start and end point of the line, as it may be longer than the measured distance.

The line is extended  on its left side (= the part of the line 'before' the start point) by the distance \verb\dblLeft\. On its right side (= the part of the line 'behind' the end point) it is extended by the distance \verb\dblRight\. \verb\dblLeft\ and \verb\dblRight\ must be $\leq 0$. If only one of both values is zero, it is set to the value of the other one, because according to DIN 15 it is not allowed to draw a measurement line asymmetrically. The position of the arrows indicating begin and end of the distance depends on \verb\dblLeft\ and \verb\dblRight\. If both values are 0, the measurement arrows are drawn within the measurement distance. Otherwise they are drawn outside.

The parameter \verb\dblRelPosition\ refers to the relative position of the label between the start and end point. This means: The value 0 positions the label at the start point, 0.5 refers to the center between the start and the end point. Finally, the value 1 will position the label at the end point. If \verb\dblLeft\ or \verb\dblRight\ are nonzero, you may position the label at the left side of the start point ($< 0$) or at the right side of the start point ($> 1$).

Usually, there is enough space to draw the measurement arrows. If you wish to use small circles instead of the arrows, set \verb\bSmallBound\ to \verb\true\.



\begin{verbatim}
real GetMeasurementBoundSize(bool bSmallBound = false)
\end{verbatim}
%
Returns the size of the arrow or the small bound circle used for measurement lines.



\begin{verbatim}
guide GetMeasurementBound(bool bSmallBound = false)
\end{verbatim}
%
Returns the correctly scaled guide of the arrow or the small bound circle used for measurement lines.



\begin{verbatim}
void MeasureParallel(picture pic = currentpicture,
                     Label L,
                     pair pFrom,
                     pair pTo,
                     real dblDistance,
                     // Variables from MeasureLine
                     real dblLeft = 0,
                     real dblRight = 0,
                     real dblRelPosition = 0.5,
                     bool bSmallBound = false)
\end{verbatim}
%
Usually, measurement lines are placed outside the drawing with reference lines to the measured distance. \verb\pFrom\ and \verb\pTo\ denote the points of the drawing marking the begin and the end of the distance to measure, and not the begin and the end of the measurement line as in the case of the function \verb\MeasureLine\. The measurement line is placed \verb\dblDistance\ away from the distance to measure. If you would be at \verb\pFrom\ and look into the direction \verb\pTo\, it is placed on the left for positive values of \verb\dblDistance\. For negative values, it is positioned on the right. For the meaning of the other parameters see the function \verb\MeasureLine\.



\begin{verbatim}
guide MakeFreehand(pair pFrom, pair pTo,
                   real dblRelDivisionLength = 12.5,
                   real dblRelDistortion = 2.5,
                   bool bIncludeTo = true)
\end{verbatim}
%
To draw a line between two points, which is not straight, but more like a freehand line, use this function. The pairs \verb\pFrom\ and \verb\pTo\ denote start and end point, respectively. \verb\dblRelDivisionLength\ is the length of the parts, the line is subdivided into. \verb\dblRelDistortion\ is the amount of distortion. Both sizes are given relative to the width of a freehand line. If \verb\bIncludeTo\ is \verb\true\, the point \verb\pTo\ is added to the path. Otherwise it is not. This may be useful for converting a guide containing more than two points to a freehand line.



\section{Example}

\begin{figure}
\includegraphics{CAD1}
\caption{Example showing the measurement capabilities and a small freehand line.\label{fig:example1}}
\end{figure}

To produce figure \ref{fig:example1}, use this code:
\begin{quote}
\begin{verbatim}
import CAD;

sCAD    cad = sCAD.Create();

// Freehand line
draw(g = cad.MakeFreehand(pFrom = (3, -1)*cm, (6, -1)*cm),
     p = cad.pFreehand);

// Standard measurement lines
draw(g = box((0, 0)*cm, (1, 1)*cm), p = cad.pVisibleEdge);
cad.MeasureParallel(L = "$\sqrt{2}$",
                    pFrom = (0, 1)*cm,
                    pTo = (1, 0)*cm,
                    dblDistance = -15mm);

// Label inside, shifted to the right; arrows outside
draw(g = box((2, 0)*cm, (3, 1)*cm), p = cad.pVisibleEdge);
cad.MeasureParallel(L = "1",
                    pFrom = (2, 1)*cm,
                    pTo = (3, 1)*cm,
                    dblDistance = 5mm,
                    dblLeft = 5mm,
                    dblRelPosition = 0.75);

// Label and arrows outside
draw(g = box((5, 0)*cm, (5.5, 1)*cm), p = cad.pVisibleEdge);
cad.MeasureParallel(L = "0.5",
                    pFrom = (5, 1)*cm,
                    pTo = (5.5, 1)*cm,
                    dblDistance = 5mm,
                    dblLeft = 10mm,
                    dblRelPosition = -1);

// Small bounds, asymmetric measurement line
draw(g = box((7, 0)*cm, (7.5, 1)*cm), p = cad.pVisibleEdge);
cad.MeasureParallel(L = "0.5",
                    pFrom = (7, 1)*cm,
                    pTo = (7.5, 1)*cm,
                    dblDistance = 5mm,
                    dblLeft = 2*cad.GetMeasurementBoundSize(
                                    bSmallBound = true),
                    dblRight = 10mm,
                    dblRelPosition = 2,
                    bSmallBound = true);
\end{verbatim}
\end{quote}

\end{document}