1 /** This file is part of Shapes.
3 ** Shapes is free software: you can redistribute it and/or modify
4 ** it under the terms of the GNU General Public License as published by
5 ** the Free Software Foundation, either version 3 of the License, or
8 ** Shapes is distributed in the hope that it will be useful,
9 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ** GNU General Public License for more details.
13 ** You should have received a copy of the GNU General Public License
14 ** along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 ** Copyright 2009, 2010 Henrik Tidefelt
21 ##preamble \usepackage{amsmath}
23 lengthMarks: \ n p r:void a:75° →
25 the_r: [if [typeof r]=§Void @width*10 r]
31 [[range '0 n-'1].foldl
35 sl: [p 0.5*l_p + ( e*1 - 0.5*(n-'1) ) * d]
36 [shift sl.p]*rot [] [stroke the_r*sl.T--~the_r*sl.T]
43 •page << [shift (~4cm,~1cm)][][center [TeX `
46 2\, \alpha &= \text{\texttt{frontAngle}}
48 2\, \beta &= \text{\texttt{rearAngle}}
52 \text{\texttt{width}}, & \text{if \texttt{width} is a §Length}
54 \max \left\{\, 3\,\mathrm{bp},\, \text{\texttt{width}}\, \text{\texttt{@width}} \,\right\}, & \text{if \texttt{width} is a §Float}
64 pth: { c: [circle 5cm] [c 2.3]--[c 3.3] }
66 /** First we set up variables that mirror the formal parameters of ShapesArrow.
73 /** Show the arrowhead.
75 •page << @stroking:[gray 0.7] | [stroke pth head:[ShapesArrow width:width frontAngle:frontAngle rearAngle:rearAngle ...]]
77 /** Then we paste the implementation of ShapesArrow...
81 w: 0.5*[if [typeof width]=§Float @width*width width]
82 el: [min w/[sin 0.5*frontAngle] lMax]
83 l: [min w * ( [cot 0.5*frontAngle] - [cot 0.5*rearAngle] ) lMax]
84 e: [p 0]--[p el] >> [shift ~z]
90 r: w / [sin 0.5*rearAngle]
91 d1: sl.p + [[rotate 0.5*rearAngle] (r*sl.T)] - z
92 d2: sl.p + [[rotate ~0.5*rearAngle] (r*sl.T)] - z
94 /** The following paths are not bound to variables in the implementation, but we need them here.
96 e1: [[shift z]*[rotate [angle d1]-dra]*[scale (|d1|)/drl] e]
97 e2: [[shift z]*[rotate [angle d2]-dra]*[scale (|d2|)/drl] e]
99 /** ... so that we can annotate the result!
102 •page << @width:3bp & @stroking:[gray 0.8] | [stroke pth]
104 @width:1.5bp & @stroking:RGB_BLUE
107 •page << [stroke [shift z][]e]
112 @width:5bp & @stroking:RGB_RED
115 •page << [spot pr] << [spot z] << [spot e1.end.p] << [spot e2.end.p]
118 hStyle: @width:0.5bp & @stroking:[gray 0.2]
119 angleHead: [ShapesArrow width:2bp ...]
127 •page << [stroke [shift z][]( e1.begin.T*r0--e1.begin.T*~r1 )]
128 •page << [stroke [shift z][]( e2.begin.T*r0--e2.begin.T*~r1 )]
131 arc: [shift z] [] [ccw_arc (0m,0m) [rotate ~(5mm/rAngle)][]e2.begin.T*~r1 e2.begin.T*~r1 rAngle]
132 •page << [stroke [shift z] [] [ccw_arc (0m,0m) e2.begin.T*~r1 e1.begin.T*~r1 rAngle]]
133 << [stroke [shift z] [] [cw_arc (0m,0m) [rotate (5mm/rAngle)][]e1.begin.T*~r1 e1.begin.T*~r1 rAngle]
135 << [stroke arc head:angleHead]
136 << [putlabelRight [TeX `$\approx 2\, \alpha$´] arc.begin.p ~1]
139 arc1: [shift z] [] [cw_arc (0m,0m) e1.begin.T*~r1 p.begin.T*~r1 0.5*(r1+r2)]
140 arc2: [shift z] [] [ccw_arc (0m,0m) e2.begin.T*~r1 p.begin.T*~r1 0.5*(r1+r2)]
141 •page << [stroke z--(+~r2*p.begin.T)]
142 << [stroke [[shift z]*[rotate 0.5*frontAngle] ~(r1+1bp)*p.begin.T--(+(~(r2-r1)*p.begin.T))]]
143 << [stroke [[shift z]*[rotate ~0.5*frontAngle] ~(r1+1bp)*p.begin.T--(+(~(r2-r1)*p.begin.T))]]
144 << [stroke arc1 head:angleHead tail:angleHead]
145 << [stroke arc2 head:angleHead tail:angleHead]
146 << [putlabelRight [TeX `$\alpha$´] [mspoint arc1 0.5] ~1]
147 << [putlabelRight [TeX `$\alpha$´] [mspoint arc2 0.5] ~1]
152 << [putlabelRight [TeX `$r$´] [mspoint p 0.5] 0]
157 << [putlabelRight [TeX `$r$´] [mspoint p 0.5] 0]
160 pw: pr + [cos 0.5*rearAngle]*r*sl.T
163 •page << [stroke p1 head:angleHead tail:angleHead]
164 << [putlabelLeft [TeX `$w$´] [mspoint p1 0.5] 1]
165 << [stroke p2 head:angleHead tail:angleHead]
166 << [putlabelLeft [TeX `$w$´] [mspoint p2 0.5] ~1]
169 hLine: pr--(+(1.2*r*sl.T))
170 arc1: [ccw_arc pr hLine.end.p e1.end.p 0.9*r]
171 arc2: [cw_arc pr hLine.end.p e2.end.p 0.9*r]
172 •page << [stroke hLine]
173 << [stroke arc1 head:angleHead tail:angleHead]
174 << [putlabelLeft [TeX `$\beta$´] [mspoint arc1 0.5] 1]
175 << [stroke arc2 head:angleHead tail:angleHead]
176 << [putlabelLeft [TeX `$\beta$´] [mspoint arc2 0.5] ~1]
182 arc: [sidepath2 [upsample_bends 20° arc0] offset]
183 •page << [stroke arc head:angleHead tail:angleHead]
184 << [stroke arc0.begin.p--(+arc0.begin.N*1.5*offset)]
185 << [stroke arc0.end.p--(+arc0.end.rN*~2*offset)]
186 << [putlabelBelow [TeX `$l$´] [mspoint arc 0.8] 0]
191 arc: [sidepath2 [upsample_bends 20° arc0] offset]
192 •page << [stroke arc head:angleHead tail:angleHead]
193 << [stroke arc0.begin.p--(+arc0.begin.N*1.5*offset)]
194 << [stroke arc0.end.p--(+arc0.end.rN*~2*offset)]
195 << [putlabelAbove [TeX `$h$´] [mspoint arc 0.7] 0]
206 pth: (~5cm,~10cm)--(3cm,(+0cm))
208 /** First we set up variables that mirror the formal parameters of ShapesArrow.
215 /** Show the arrowhead.
217 •page << @stroking:[gray 0.7] | [stroke pth head:[ShapesArrow width:width frontAngle:frontAngle rearAngle:rearAngle ...]]
219 /** Then we paste the implementation of ShapesArrow...
223 w: 0.5*[if [typeof width]=§Float @width*width width]
224 el: [min w/[sin 0.5*frontAngle] lMax]
225 l: [min w * ( [cot 0.5*frontAngle] - [cot 0.5*rearAngle] ) lMax]
226 e: [p 0]--[p el] >> [shift ~z]
232 r: w / [sin 0.5*rearAngle]
233 d1: sl.p + [[rotate 0.5*rearAngle] (r*sl.T)] - z
234 d2: sl.p + [[rotate ~0.5*rearAngle] (r*sl.T)] - z
236 /** The following paths are not bound to variables in the implementation, but we need them here.
238 e1: [[shift z]*[rotate [angle d1]-dra]*[scale (|d1|)/drl] e]
239 e2: [[shift z]*[rotate [angle d2]-dra]*[scale (|d2|)/drl] e]
241 /** ... so that we can annotate the result!
244 •page << @width:3bp & @stroking:[gray 0.8] | [stroke pth]
246 @width:1.5bp & @stroking:RGB_BLUE
249 •page << [stroke [shift z][]e]
254 @width:5bp & @stroking:RGB_RED
257 •page << [spot pr] << [spot z] << [spot e1.end.p] << [spot e2.end.p]
260 hStyle: @width:0.5bp & @stroking:[gray 0.2]
261 angleHead: [ShapesArrow width:2bp ...]
268 arc1: [ccw_arc z pr e1.end.p rLbl]
269 arc2: [cw_arc z pr e2.end.p rLbl]
270 •page << [stroke arc1 head:angleHead tail:angleHead]
271 << [putlabelLeft [TeX `$\alpha$´] [mspoint arc1 0.5] 0]
272 << [stroke arc2 head:angleHead tail:angleHead]
273 << [putlabelLeft [TeX `$\alpha$´] [mspoint arc2 0.5] ~0.5]
278 << [putlabelRight [TeX `$r$´] [mspoint p 0.5] 0]
283 << [putlabelRight [TeX `$r$´] [mspoint p 0.5] 0]
286 pw: pr + [cos 0.5*rearAngle]*r*sl.T
289 •page << [stroke p1 head:angleHead tail:angleHead]
290 << [putlabelLeft [TeX `$w$´] [mspoint p1 0.5] 1]
291 << [stroke p2 head:angleHead tail:angleHead]
292 << [putlabelLeft [TeX `$w$´] [mspoint p2 0.5] ~1]
295 hLine: pr--(+(1.2*r*sl.T))
296 arc1: [ccw_arc pr hLine.end.p e1.end.p 0.9*r]
297 arc2: [cw_arc pr hLine.end.p e2.end.p 0.9*r]
298 •page << [stroke hLine]
299 << [stroke arc1 head:angleHead tail:angleHead]
300 << [putlabelLeft [TeX `$\beta$´] [mspoint arc1 0.5] 1]
301 << [stroke arc2 head:angleHead tail:angleHead]
302 << [putlabelLeft [TeX `$\beta$´] [mspoint arc2 0.5] ~1]
308 arc: [sidepath [upsample_bends 20° arc0] offset]
309 •page << [stroke arc head:angleHead tail:angleHead]
310 << [stroke arc0.begin.p--(+arc0.begin.N*1.5*offset)]
311 << [stroke arc0.end.p--(+arc0.end.rN*~2*offset)]
312 << [putlabelBelow [TeX `$l$´] [mspoint arc 0.8] 0]
317 arc: [sidepath [upsample_bends 20° arc0] offset]
318 •page << [stroke arc head:angleHead tail:angleHead]
319 << [stroke arc0.begin.p--(+arc0.begin.N*1.5*offset)]
320 << [stroke arc0.end.p--(+arc0.end.rN*~2*offset)]
321 << [putlabelAbove [TeX `$h$´] [mspoint arc 0.7] 0]
322 << [putlabelBelow [TeX `$h$´] [mspoint e1 0.7] 0]
323 << [putlabelAbove [TeX `$h$´] [mspoint e2 0.7] 0]