Debian Codegraph @

texmf-dist/doc/latex/luatikz/example/radon1.lua

raw
1 tikz.within( '*' )
2
3 local cos = math.cos
4 local sin = math.sin
5 local pi = math.pi
6
7 -- granularity of calculation
8 local fine = 10
9
10 -- factor the projection length is reduced
11 local fproj = 0.35
12
13 -- strength of the ellipse mediums
14 local s1 = 1.00
15 local s2 = 1.50
16 local s3 = 1.75
17
18 local e1 = ellipse{ at=p{ 0.00, 0.00 }, xradius=3.00, yradius=3.00 }
19 local e2 = ellipse{ at=p{ 0.40, 1.20 }, xradius=0.85, yradius=0.50 }
20 local e3 = ellipse{ at=p{ 0.00, -0.89 }, xradius=1.00, yradius=0.60 }
21
22 draw{ fill='black!08!white', line_width=1, e1 }
23 draw{ fill='black!16!white', line_width=1, e2 }
24 draw{ fill='black!24!white', line_width=1, e3 }
25
26 -- list of projection angles
27 local listphi =
28 {
29 -1/4 * pi,
30 2/4 * pi,
31 5/4 * pi,
32 }
33
34 -- length of projection lines
35 local lenmaintop = 5.0
36 local lenmainbot = 6.5
37
38 for proji, phimain in ipairs( listphi )
39 do
40 local lmain =
41 line{
42 p{ cos( phimain ), sin( phimain ) } * -lenmaintop,
43 p{ cos( phimain ), sin( phimain ) } * lenmainbot,
44 }
45 local phinorm = phimain - pi/2
46
47 -- gets a point on the projection.
48 -- dp: distance from projection center
49 -- dv: projection value
50 function getpproj( dp, dv )
51 return(
52 lmain.p2
53 + p{ cos( phinorm ) * dp, sin( phinorm ) * dp }
54 + p{ cos( phimain ) * dv * fproj, sin( phimain ) * dv * fproj }
55 )
56 end
57
58 -- distance of projection line
59 local ddis = 1 / fine
60
61 -- list of all projection points
62 local listp = { }
63
64 for i = -3.5 * fine, 3.5 * fine
65 do
66 local p1i =
67 lmain.p1
68 + p{ cos( phinorm ) * ddis * i, sin( phinorm ) * ddis * i }
69 local li = line{ p1i, p1i + ( lmain.p2 - lmain.p1 ) }
70 local lv = 0
71 local is1 = e1.intersectLine( li )
72
73 if is1 and #is1 > 1
74 then
75 local lis = line{ is1[ 1 ], is1[ 2 ] }
76 lv = lv + lis.length * s1
77 end
78
79 local is2 = e2.intersectLine( li )
80 if is2 and #is2 > 1
81 then
82 local lis = line{ is2[ 1 ], is2[ 2 ] }
83 lv = lv + lis.length * s2
84 end
85
86 local is3 = e3.intersectLine( li )
87 if is3 and #is3 > 1
88 then
89 local lis = line{ is3[ 1 ], is3[ 2 ] }
90 lv = lv + lis.length * s3
91 end
92
93 local pproj = getpproj( ddis * i, lv )
94 if i % ( 0.7 * fine ) == 0
95 then
96 draw{
97 dotted, arrow, line_width=0.5,
98 line{ li.p1, getpproj( ddis * i, -0.20 ) },
99 }
100 draw{
101 dotted, line_width=0.5,
102 line{ li.p1, pproj },
103 }
104 end
105 table.insert( listp, pproj )
106 end
107
108 -- draws the projection screen
109 local lenlproj = 8
110 draw{
111 line{
112 getpproj( lenlproj / 2, 0 ),
113 getpproj( -lenlproj / 2, 0 ),
114 }
115 }
116
117 -- draws the projection curve
118 draw{ line_width=1, polyline{ table.unpack( listp ) } }
119 end