summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/lapdf/rcircle.tex
blob: a4e31599739b0b1a83639d52d714665df1724c8f (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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
\input preamble.tex

\Defdim(\a,0)
\Defdim(\d,0)
\Defdim(\x,0)
\Defdim(\y,0)

\def\Ncirc(#1){\Rad(#1,\a)
 \Cos(\Np\a,\x) \Add(\x,\x)
 \Sin(\Np\a,\y) \Add(\y,\y)
 \Circle(64)(\Np\x,\Np\y,2) \Stroke}

\def\ctitle#1{{\huge\bf{#1}}}

\title{\Huge \bf{Drawing Circles \\
       with \\
       Rational Quadratic Bezier Curves}}
\author{Detlef Reimers, detlefreimers@gmx.de}
\date{\today}

% ---------------------------------------------------------------------------
\begin{document}
\maketitle

\begin{center}
\begin{lapdf}(8, 10)(-4,-5)
 \Whiledim{\d<360}{\Nextcol(0,23) \Ncirc(\Np\d) \Dadd(\d,15)}
\end{lapdf}

\ctitle{Description}
\end{center}
This document explains, how to calculate the bezier points for
complete circles. These can be drawn with the \texttt{Rcurve}
commmand from the \texttt{lapdf.sty}. If the weight of the point
$P_1$ is $w=\cos(\alpha)$, where $\alpha$ ist the angle between
$P_{0}P_{1}$ and $P_{1}P_{2}$, then the conic will be a circular
arc, if also both length $P_{0}P_{1}$ and $P_{1}P_{2}$ are equal.

We have to smothly join several of these arcs together, to get
a full circle. Only in the case of two segments, we have have to
use one negative weight. In all other cases we only have positive
weights. In all of the following calculations and drawings we assume,
that the center of the circle lies at the origin.

\pagebreak
\parskip0.3cm

\begin{center}
\ctitle{General calculation scheme}

\begin{lapdf}(14,13.5)(-7,-6.5)
 \Dash(1)
 \Setwidth(0.01)
 \Polygon(+0.00,-5.00)
 (+3.63,-5.00)(+4.76,-1.55)
 (+5.88,+1.91)(+2.94,+4.05)
 (+0.00,+6.18)(-2.94,+4.05)
 (-5.88,+1.91)(-4.76,-1.55)
 (-3.63,-5.00)(+0.00,-5.00) \Stroke
 \Line(+0.00,+0.00)(+0.00,-5.00) \Stroke
 \Line(+0.00,+0.00)(+3.63,-5.00) \Stroke
 \Line(+0.00,+0.00)(+4.76,-1.55) \Stroke
 \Line(+0.00,+0.00)(+5.88,+1.91) \Stroke
 \Line(+0.00,+0.00)(+2.94,+4.05) \Stroke
 \Line(+0.00,+0.00)(+0.00,+6.18) \Stroke
 \Line(+0.00,+0.00)(-2.94,+4.05) \Stroke
 \Line(+0.00,+0.00)(-5.88,+1.91) \Stroke
 \Line(+0.00,+0.00)(-4.76,-1.55) \Stroke
 \Line(+0.00,+0.00)(-3.63,-5.00) \Stroke
 \Dash(0)
 \Setwidth(0.02)
 \Blue
 \Circle(96)(0,0,6.18) \Stroke
 \Red
 \Circle(96)(0,0,5) \Stroke
 \Black
 \Rcurve(64)(+0.00,-1.30,1)(+0.42,-1.30,0.5)(0.76,-1.05,1) \Stroke
 \Point(1)(+3.63,-5.00)
 \Point(1)(+4.76,-1.55)
 \Point(1)(+5.88,+1.91)
 \Point(1)(+2.94,+4.05)
 \Point(1)(+0.00,+6.18)
 \Point(1)(-2.94,+4.05)
 \Point(1)(-5.88,+1.91)
 \Point(1)(-4.76,-1.55)
 \Point(1)(-3.63,-5.00)
 \Point(1)(+0.00,-5.00)
 \Text(+3.63,-5.10,tl){$P_1$}
 \Text(+4.86,-1.55,tl){$P_2$}
 \Text(+5.98,+2.01,cl){$P_3$}
 \Text(+3.04,+4.15,bl){$P_4$}
 \Text(+0.00,+6.38,bc){$P_5$}
 \Text(-3.04,+4.15,br){$P_6$}
 \Text(-5.98,+2.01,cr){$P_7$}
 \Text(-4.86,-1.55,tr){$P_8$}
 \Text(-3.63,-5.10,tr){$P_9$}
 \Text(+0.00,-5.10,tc){$P_0=P_{10}$}
 \Text(0.10,-2.90,cl){$r$}
 \Text(0.10,+3.10,cl){$R$}
 \Text(0.25,-0.80,cc){$\alpha$}
\end{lapdf}
\end{center}
We always put $P_0$ at the bottom of the circle and all other points
follow counterclockwise.
This is the general procedure for circle construction with rational
quadratic bezier curves (see picture):
\begin{enumerate}
\item Set the radius $r$.
\item Set the number of bezier segments $n$.
\item Calculate $\alpha = \displaystyle {360^\circ \over 2n}$.
\item Calculate outer radius $R=\displaystyle {r \over \cos(\alpha)}$.
\item Calculate all even bezier points
 $P_{2i} = \displaystyle {+r \cdot \sin(2i\cdot\alpha)
           \choose -r \cdot \cos(2i\cdot\alpha)}$ for $i=0 \dots n$.
\item Calculate odd bezier points
 $P_{2i+1} = \displaystyle {+R \cdot \sin((2i+1)\cdot\alpha)
             \choose -R \cdot \cos((2i+1)\cdot\alpha)}$ for $i=0 \dots n-1$.
\end{enumerate}
You can control your calculations, if you check your endpoint $P_{2n}$.
This point is equal with $P_0$. All curves are drawn with the
{\tt Rmoveto()} and {\tt Rcurveto()} combination.

\pagebreak

\parskip1cm
\begin{center}
\ctitle{2 Segments}

\begin{lapdf}(6,7.5)(-3,-3)
 \Lingrid(5)(0,1)(-3,3)(-3,5)
 \Dash(1)
 \Setwidth(0.01)
 \Polygon(+2.165,+1.25)
 (+0.00,+5.0)(-2.165,+1.25) \Stroke
 \Dash(0)
 \Red
 \Setwidth(0.02)
 \Rmoveto(+2.165,+1.25,1)
 \Rcurveto(64)(+0.00,+5.0,+0.5)(-2.165,+1.25,1)
 \Rcurveto(64)(+0.00,+5.0,-0.5)(+2.165,+1.25,1) \Stroke
 \Black
 \Point(1)(+2.165,+1.25)
 \Point(1)(+0.000,+5.00)
 \Point(1)(-2.165,+1.25)
\end{lapdf}

Circle with $2n+1=5$ points ($w_{2n}=1$ and $w_{2n+1} = \pm \cos(60^\circ) = \pm 0.5$).
\end{center}
\begin{center}
\ctitle{3 Segments}

\begin{lapdf}(6,7.5)(-3,-3)
 \Lingrid(5)(0,1)(-5,5)(-3,5)
 \Dash(1)
 \Setwidth(0.01)
 \Polygon(+0.00,-2.50)
 (+4.333,-2.50)(+2.165,+1.25)
 (+0.000,+5.00)(-2.165,+1.25)
 (-4.333,-2.50)(+0.000,-2.50) \Stroke
 \Dash(0)
 \Setwidth(0.02)
 \Red
 \Rmoveto(+0.000,-2.50,1)
 \Rcurveto(64)(+4.33,-2.50,0.5)(+2.165,+1.25,1)
 \Rcurveto(64)(+0.00,+5.00,0.5)(-2.165,+1.25,1)
 \Rcurveto(64)(-4.33,-2.50,0.5)(+0.000,-2.50,1) \Stroke
 \Black
 \Point(1)(+0.000,-2.50)
 \Point(1)(+4.333,-2.50)
 \Point(1)(+2.165,+1.25)
 \Point(1)(+0.000,+5.00)
 \Point(1)(-2.165,+1.25)
 \Point(1)(-4.333,-2.50)
\end{lapdf}

Circle with $2n+1=7$ points ($w_{2n}=1$ and $w_{2n+1} = \cos(60^\circ) = 0.5$).
\end{center}

\pagebreak

\begin{center}
\ctitle{4 Segments}

\begin{lapdf}(6,6)(-3,-3)
 \Lingrid(5)(0,1)(-3,3)(-3,3)
 \Dash(1)
 \Setwidth(0.01)
 \Polygon(+2.50,+0.00)
 (+2.50,+2.50)(+0.00,+2.50)
 (-2.50,+2.50)(-2.50,+0.00)
 (-2.50,-2.50)(+0.00,-2.50)
 (+2.50,-2.50)(+2.50,+0.00) \Stroke
 \Dash(0)
 \Setwidth(0.02)
 \Red
 \Rmoveto(+2.50,+0.00,1)
 \Rcurveto(64)(+2.50,+2.50,0.707)(+0.00,+2.50,1)
 \Rcurveto(64)(-2.50,+2.50,0.707)(-2.50,+0.00,1)
 \Rcurveto(64)(-2.50,-2.50,0.707)(+0.00,-2.50,1)
 \Rcurveto(64)(+2.50,-2.50,0.707)(+2.50,+0.00,1) \Stroke
 \Black
 \Point(1)(+2.50,+0.00)
 \Point(1)(+2.50,+2.50)
 \Point(1)(+0.00,+2.50)
 \Point(1)(-2.50,+2.50)
 \Point(1)(-2.50,+0.00)
 \Point(1)(-2.50,-2.50)
 \Point(1)(+0.00,-2.50)
 \Point(1)(+2.50,-2.50)
\end{lapdf}

Circle with $2n+1=9$ points ($w_{2n}=1$ and $w_{2n+1} = \cos(45^\circ) = 0.707$).
\end{center}
\begin{center}
\ctitle{5 Segments}

\begin{lapdf}(6,6)(-3,-3)
 \Lingrid(5)(0,1)(-3,3)(-3,3)
 \Dash(1)
 \Setwidth(0.01)
 \Polygon(+0.00,-2.50)
 (+1.815,-2.500)(+2.38,-0.775)
 (+2.940,+0.905)(+1.47,+2.025)
 (+0.000,+3.090)(-1.47,+2.025)
 (-2.940,+0.905)(-2.38,-0.775)
 (-1.815,-2.500)(+0.00,-2.500) \Stroke
 \Dash(0)
 \Setwidth(0.02)
 \Red
 \Rmoveto(+0.00,-2.500,1)
 \Rcurveto(64)(+1.815,-2.500,0.809)(+2.380,-0.775,1)
 \Rcurveto(64)(+2.940,+0.905,0.809)(+1.470,+2.025,1)
 \Rcurveto(64)(+0.000,+3.090,0.809)(-1.470,+2.025,1)
 \Rcurveto(64)(-2.940,+0.905,0.809)(-2.380,-0.775,1)
 \Rcurveto(64)(-1.815,-2.500,0.809)(+0.000,-2.500,1) \Stroke
 \Black
 \Point(1)(+1.815,-2.500)
 \Point(1)(+2.380,-0.775)
 \Point(1)(+2.940,+0.905)
 \Point(1)(+1.470,+2.025)
 \Point(1)(+0.000,+3.090)
 \Point(1)(-1.470,+2.025)
 \Point(1)(-2.940,+0.905)
 \Point(1)(-2.380,-0.775)
 \Point(1)(-1.815,-2.500)
 \Point(1)(+0.000,-2.500)
\end{lapdf}

Circle with $2n+1=11$ points ($w_{2n}=1$ and $w_{2n+1} = \cos(36^\circ) = 0.809$).
\end{center}

\pagebreak

\begin{center}
\ctitle{6 Segments}

\begin{lapdf}(6,6)(-3,-3)
 \Lingrid(5)(0,1)(-3,3)(-3,3)
 \Dash(1)
 \Setwidth(0.01)
 \Polygon(+2.50,+0.00)
 (+2.50,+1.445)(+1.25,+2.165)
 (+0.00,+2.885)(-1.25,+2.165)
 (-2.50,+1.445)(-2.50,+0.000)
 (-2.50,-1.445)(-1.25,-2.165)
 (+0.00,-2.885)(+1.25,-2.165)
 (+2.50,-1.445)(+2.50,+0.000) \Stroke
 \Dash(0)
 \Setwidth(0.02)
 \Red
 \Rmoveto(+2.50,+0.000,1)
 \Rcurveto(64)(+2.50,+1.445,0.866)(+1.25,+2.165,1)
 \Rcurveto(64)(+0.00,+2.885,0.866)(-1.25,+2.165,1)
 \Rcurveto(64)(-2.50,+1.445,0.866)(-2.50,+0.000,1)
 \Rcurveto(64)(-2.50,-1.445,0.866)(-1.25,-2.165,1)
 \Rcurveto(64)(+0.00,-2.885,0.866)(+1.25,-2.165,1)
 \Rcurveto(64)(+2.50,-1.445,0.866)(+2.50,+0.000,1) \Stroke
 \Black
 \Point(1)(+2.50,+0.000)
 \Point(1)(+2.50,+1.445)
 \Point(1)(+1.25,+2.165)
 \Point(1)(+0.00,+2.885)
 \Point(1)(-1.25,+2.165)
 \Point(1)(-2.50,+1.445)
 \Point(1)(-2.50,+0.000)
 \Point(1)(-2.50,-1.445)
 \Point(1)(-1.25,-2.165)
 \Point(1)(+0.00,-2.885)
 \Point(1)(+1.25,-2.165)
 \Point(1)(+2.50,-1.445)
\end{lapdf}

Circle with $2n+1=13$ points ($w_{2n}=1$ and $w_{2n+1} = \cos(30^\circ) = 0.866$).
\end{center}

\begin{center}
\ctitle{7 Segments}

\begin{lapdf}(6,6)(-3,-3)
 \Lingrid(5)(0,1)(-3,3)(-3,3)
 \Dash(1)
 \Setwidth(0.01)
 \Polygon(+0.00,-2.50)
 (+1.205,-2.50)(+1.955,-1.560)
 (+2.705,-0.62)(+2.440,+0.555)
 (+2.170,+1.73)(+1.085,+2.255)
 (+0.000,+2.78)(-1.085,+2.255)
 (-2.170,+1.73)(-2.440,+0.555)
 (-2.705,-0.62)(-1.955,-1.560)
 (-1.205,-2.50)(+0.000,-2.500) \Stroke
 \Dash(0)
 \Setwidth(0.02)
 \Red
 \Rmoveto(+0.000,-2.500,1)
 \Rcurveto(64)(+1.205,-2.50,0.901)(+1.905,-1.560,1)
 \Rcurveto(64)(+2.705,-0.62,0.901)(+2.440,+0.555,1)
 \Rcurveto(64)(+2.170,+1.73,0.901)(+1.085,+2.255,1)
 \Rcurveto(64)(+0.000,+2.78,0.901)(-1.085,+2.255,1)
 \Rcurveto(64)(-2.170,+1.73,0.901)(-2.440,+0.555,1)
 \Rcurveto(64)(-2.705,-0.62,0.901)(-1.905,-1.560,1)
 \Rcurveto(64)(-1.205,-2.50,0.901)(+0.000,-2.500,1) \Stroke
 \Black
 \Point(1)(+0.000,-2.500)
 \Point(1)(+1.205,-2.500)
 \Point(1)(+1.905,-1.560)
 \Point(1)(+2.705,-0.620)
 \Point(1)(+2.440,+0.555)
 \Point(1)(+2.170,+1.730)
 \Point(1)(+1.085,+2.255)
 \Point(1)(+0.000,+2.780)
 \Point(1)(-1.085,+2.255)
 \Point(1)(-2.170,+1.730)
 \Point(1)(-2.440,+0.555)
 \Point(1)(-2.705,-0.620)
 \Point(1)(-1.905,-1.560)
 \Point(1)(-1.205,-2.500)
\end{lapdf}

Circle with $2n+1=15$ points ($w_{2n}=1$ and $w_{2n+1} = \cos(25.71^\circ) = 0.901$).
\end{center}
\end{document}