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, 2014 Henrik Tidefelt
19 ##needs ..Applications..Blockdraw
20 ##needs ..Shapes..Geometry / pathmapping
21 ##preamble \usepackage{amsmath}
24 ##lookin ..Shapes..Geometry
25 ##lookin ..Applications..Blockdraw
27 lengthMarks: \ n p r:void a:75° →
29 the_r: [if [typeof r]=Data..Type..§Void Traits..@width*10 r]
35 [[Data..range '0 n-'1].foldl
39 sl: [p 0.5*l_p + ( e*1 - 0.5*(n-'1) ) * d]
40 [shift sl.p]*rot [] [Graphics..stroke the_r*sl.T--~the_r*sl.T]
47 IO..•page << [shift (~4cm,~1cm)][][Layout..center [Graphics..TeX `
50 2\, \alpha &= \text{\texttt{frontAngle}}
52 2\, \beta &= \text{\texttt{rearAngle}}
56 \text{\texttt{width}}, & \text{if \texttt{width} is a Data..Type..§Length}
58 \max \left\{\, 3\,\mathrm{bp},\, \text{\texttt{width}}\, \text{\texttt{Traits..@width}} \,\right\}, & \text{if \texttt{width} is a Data..Type..§Float}
68 pth: { c: [Geometry..circle 5cm] [c 2.3]--[c 3.3] }
70 /** First we set up variables that mirror the formal parameters of ShapesArrow.
72 p: [Geometry..reverse pth]
77 /** Show the arrowhead.
79 IO..•page << Traits..@stroking:[Traits..gray 0.7] | [Graphics..stroke pth head:[Graphics..ShapesArrow width:width frontAngle:frontAngle rearAngle:rearAngle ...]]
81 /** Then we paste the implementation of ShapesArrow...
84 lMax: 0.99*[Numeric..Math..abs p]
85 w: 0.5*[if [typeof width]=Data..Type..§Float Traits..@width*width width]
86 el: [Numeric..Math..min w/[Numeric..Math..sin 0.5*frontAngle] lMax]
87 l: [Numeric..Math..min w * ( [Numeric..Math..cot 0.5*frontAngle] - [Numeric..Math..cot 0.5*rearAngle] ) lMax]
88 e: [p 0]--[p el] >> [shift ~z]
94 r: w / [Numeric..Math..sin 0.5*rearAngle]
95 d1: sl.p + [[rotate 0.5*rearAngle] (r*sl.T)] - z
96 d2: sl.p + [[rotate ~0.5*rearAngle] (r*sl.T)] - z
98 /** The following paths are not bound to variables in the implementation, but we need them here.
100 e1: [[shift z]*[rotate [angle d1]-dra]*[scale (|d1|)/drl] e]
101 e2: [[shift z]*[rotate [angle d2]-dra]*[scale (|d2|)/drl] e]
103 /** ... so that we can annotate the result!
106 IO..•page << Traits..@width:3bp & Traits..@stroking:[Traits..gray 0.8] | [Graphics..stroke pth]
108 Traits..@width:1.5bp & Traits..@stroking:Traits..RGB..BLUE
111 IO..•page << [Graphics..stroke [shift z][]e]
112 << [Graphics..stroke e1]
113 << [Graphics..stroke e2]
116 Traits..@width:5bp & Traits..@stroking:Traits..RGB..RED
119 IO..•page << [Graphics..spot pr] << [Graphics..spot z] << [Graphics..spot e1.end.p] << [Graphics..spot e2.end.p]
122 hStyle: Traits..@width:0.5bp & Traits..@stroking:[Traits..gray 0.2]
123 angleHead: [Graphics..ShapesArrow width:2bp ...]
131 IO..•page << [Graphics..stroke [shift z][]( e1.begin.T*r0--e1.begin.T*~r1 )]
132 IO..•page << [Graphics..stroke [shift z][]( e2.begin.T*r0--e2.begin.T*~r1 )]
135 arc: [shift z] [] [Geometry..ccw_arc (0m,0m) [rotate ~(5mm/rAngle)][]e2.begin.T*~r1 e2.begin.T*~r1 rAngle]
136 IO..•page << [Graphics..stroke [shift z] [] [Geometry..ccw_arc (0m,0m) e2.begin.T*~r1 e1.begin.T*~r1 rAngle]]
137 << [Graphics..stroke [shift z] [] [Geometry..cw_arc (0m,0m) [rotate (5mm/rAngle)][]e1.begin.T*~r1 e1.begin.T*~r1 rAngle]
139 << [Graphics..stroke arc head:angleHead]
140 << [putlabelRight [Graphics..TeX `$\approx 2\, \alpha$´] arc.begin.p ~1]
143 arc1: [shift z] [] [Geometry..cw_arc (0m,0m) e1.begin.T*~r1 p.begin.T*~r1 0.5*(r1+r2)]
144 arc2: [shift z] [] [Geometry..ccw_arc (0m,0m) e2.begin.T*~r1 p.begin.T*~r1 0.5*(r1+r2)]
145 IO..•page << [Graphics..stroke z--(+~r2*p.begin.T)]
146 << [Graphics..stroke [[shift z]*[rotate 0.5*frontAngle] ~(r1+1bp)*p.begin.T--(+(~(r2-r1)*p.begin.T))]]
147 << [Graphics..stroke [[shift z]*[rotate ~0.5*frontAngle] ~(r1+1bp)*p.begin.T--(+(~(r2-r1)*p.begin.T))]]
148 << [Graphics..stroke arc1 head:angleHead tail:angleHead]
149 << [Graphics..stroke arc2 head:angleHead tail:angleHead]
150 << [putlabelRight [Graphics..TeX `$\alpha$´] [Layout..mspoint arc1 0.5] ~1]
151 << [putlabelRight [Graphics..TeX `$\alpha$´] [Layout..mspoint arc2 0.5] ~1]
155 IO..•page << [Graphics..stroke p]
156 << [putlabelRight [Graphics..TeX `$r$´] [Layout..mspoint p 0.5] 0]
160 IO..•page << [Graphics..stroke p]
161 << [putlabelRight [Graphics..TeX `$r$´] [Layout..mspoint p 0.5] 0]
164 pw: pr + [Numeric..Math..cos 0.5*rearAngle]*r*sl.T
167 IO..•page << [Graphics..stroke p1 head:angleHead tail:angleHead]
168 << [putlabelLeft [Graphics..TeX `$w$´] [Layout..mspoint p1 0.5] 1]
169 << [Graphics..stroke p2 head:angleHead tail:angleHead]
170 << [putlabelLeft [Graphics..TeX `$w$´] [Layout..mspoint p2 0.5] ~1]
173 hLine: pr--(+(1.2*r*sl.T))
174 arc1: [Geometry..ccw_arc pr hLine.end.p e1.end.p 0.9*r]
175 arc2: [Geometry..cw_arc pr hLine.end.p e2.end.p 0.9*r]
176 IO..•page << [Graphics..stroke hLine]
177 << [Graphics..stroke arc1 head:angleHead tail:angleHead]
178 << [putlabelLeft [Graphics..TeX `$\beta$´] [Layout..mspoint arc1 0.5] 1]
179 << [Graphics..stroke arc2 head:angleHead tail:angleHead]
180 << [putlabelLeft [Graphics..TeX `$\beta$´] [Layout..mspoint arc2 0.5] ~1]
186 arc: [Geometry..sidepath2 [Geometry..upsample_bends 20° arc0] offset]
187 IO..•page << [Graphics..stroke arc head:angleHead tail:angleHead]
188 << [Graphics..stroke arc0.begin.p--(+arc0.begin.N*1.5*offset)]
189 << [Graphics..stroke arc0.end.p--(+arc0.end.rN*~2*offset)]
190 << [putlabelBelow [Graphics..TeX `$l$´] [Layout..mspoint arc 0.8] 0]
195 arc: [Geometry..sidepath2 [Geometry..upsample_bends 20° arc0] offset]
196 IO..•page << [Graphics..stroke arc head:angleHead tail:angleHead]
197 << [Graphics..stroke arc0.begin.p--(+arc0.begin.N*1.5*offset)]
198 << [Graphics..stroke arc0.end.p--(+arc0.end.rN*~2*offset)]
199 << [putlabelAbove [Graphics..TeX `$h$´] [Layout..mspoint arc 0.7] 0]
210 pth: (~5cm,~10cm)--(3cm,(+0cm))
212 /** First we set up variables that mirror the formal parameters of ShapesArrow.
214 p: [Geometry..reverse pth]
219 /** Show the arrowhead.
221 IO..•page << Traits..@stroking:[Traits..gray 0.7] | [Graphics..stroke pth head:[Graphics..ShapesArrow width:width frontAngle:frontAngle rearAngle:rearAngle ...]]
223 /** Then we paste the implementation of ShapesArrow...
226 lMax: 0.99*[Numeric..Math..abs p]
227 w: 0.5*[if [typeof width]=Data..Type..§Float Traits..@width*width width]
228 el: [Numeric..Math..min w/[Numeric..Math..sin 0.5*frontAngle] lMax]
229 l: [Numeric..Math..min w * ( [Numeric..Math..cot 0.5*frontAngle] - [Numeric..Math..cot 0.5*rearAngle] ) lMax]
230 e: [p 0]--[p el] >> [shift ~z]
236 r: w / [Numeric..Math..sin 0.5*rearAngle]
237 d1: sl.p + [[rotate 0.5*rearAngle] (r*sl.T)] - z
238 d2: sl.p + [[rotate ~0.5*rearAngle] (r*sl.T)] - z
240 /** The following paths are not bound to variables in the implementation, but we need them here.
242 e1: [[shift z]*[rotate [angle d1]-dra]*[scale (|d1|)/drl] e]
243 e2: [[shift z]*[rotate [angle d2]-dra]*[scale (|d2|)/drl] e]
245 /** ... so that we can annotate the result!
248 IO..•page << Traits..@width:3bp & Traits..@stroking:[Traits..gray 0.8] | [Graphics..stroke pth]
250 Traits..@width:1.5bp & Traits..@stroking:Traits..RGB..BLUE
253 IO..•page << [Graphics..stroke [shift z][]e]
254 << [Graphics..stroke e1]
255 << [Graphics..stroke e2]
258 Traits..@width:5bp & Traits..@stroking:Traits..RGB..RED
261 IO..•page << [Graphics..spot pr] << [Graphics..spot z] << [Graphics..spot e1.end.p] << [Graphics..spot e2.end.p]
264 hStyle: Traits..@width:0.5bp & Traits..@stroking:[Traits..gray 0.2]
265 angleHead: [Graphics..ShapesArrow width:2bp ...]
272 arc1: [Geometry..ccw_arc z pr e1.end.p rLbl]
273 arc2: [Geometry..cw_arc z pr e2.end.p rLbl]
274 IO..•page << [Graphics..stroke arc1 head:angleHead tail:angleHead]
275 << [putlabelLeft [Graphics..TeX `$\alpha$´] [Layout..mspoint arc1 0.5] 0]
276 << [Graphics..stroke arc2 head:angleHead tail:angleHead]
277 << [putlabelLeft [Graphics..TeX `$\alpha$´] [Layout..mspoint arc2 0.5] ~0.5]
281 IO..•page << [Graphics..stroke p]
282 << [putlabelRight [Graphics..TeX `$r$´] [Layout..mspoint p 0.5] 0]
286 IO..•page << [Graphics..stroke p]
287 << [putlabelRight [Graphics..TeX `$r$´] [Layout..mspoint p 0.5] 0]
290 pw: pr + [Numeric..Math..cos 0.5*rearAngle]*r*sl.T
293 IO..•page << [Graphics..stroke p1 head:angleHead tail:angleHead]
294 << [putlabelLeft [Graphics..TeX `$w$´] [Layout..mspoint p1 0.5] 1]
295 << [Graphics..stroke p2 head:angleHead tail:angleHead]
296 << [putlabelLeft [Graphics..TeX `$w$´] [Layout..mspoint p2 0.5] ~1]
299 hLine: pr--(+(1.2*r*sl.T))
300 arc1: [Geometry..ccw_arc pr hLine.end.p e1.end.p 0.9*r]
301 arc2: [Geometry..cw_arc pr hLine.end.p e2.end.p 0.9*r]
302 IO..•page << [Graphics..stroke hLine]
303 << [Graphics..stroke arc1 head:angleHead tail:angleHead]
304 << [putlabelLeft [Graphics..TeX `$\beta$´] [Layout..mspoint arc1 0.5] 1]
305 << [Graphics..stroke arc2 head:angleHead tail:angleHead]
306 << [putlabelLeft [Graphics..TeX `$\beta$´] [Layout..mspoint arc2 0.5] ~1]
312 arc: [Geometry..sidepath [Geometry..upsample_bends 20° arc0] offset]
313 IO..•page << [Graphics..stroke arc head:angleHead tail:angleHead]
314 << [Graphics..stroke arc0.begin.p--(+arc0.begin.N*1.5*offset)]
315 << [Graphics..stroke arc0.end.p--(+arc0.end.rN*~2*offset)]
316 << [putlabelBelow [Graphics..TeX `$l$´] [Layout..mspoint arc 0.8] 0]
321 arc: [Geometry..sidepath [Geometry..upsample_bends 20° arc0] offset]
322 IO..•page << [Graphics..stroke arc head:angleHead tail:angleHead]
323 << [Graphics..stroke arc0.begin.p--(+arc0.begin.N*1.5*offset)]
324 << [Graphics..stroke arc0.end.p--(+arc0.end.rN*~2*offset)]
325 << [putlabelAbove [Graphics..TeX `$h$´] [Layout..mspoint arc 0.7] 0]
326 << [putlabelBelow [Graphics..TeX `$h$´] [Layout..mspoint e1 0.7] 0]
327 << [putlabelAbove [Graphics..TeX `$h$´] [Layout..mspoint e2 0.7] 0]