Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/extras/Lyap.m4

raw
1 .PS
2 # Lyap.m4
3 threeD_init
4 scale = 1/1.2
5
6 viewaz = 30
7 viewel = 18
8 setview(viewaz,viewel)
9
10 Origin: Project(0,0,0)
11 # Components of view vector W
12 w1 = view3D1
13 w2 = view3D2
14 w3 = view3D3
15 # Shape factor of the ellipse on the xy plane
16 q = Cos(40)
17
18 # cost function
19 h = 0.5
20 c = 1
21 # The projected ellipse is (x/q)^2 + y^2 = c.
22 # The cost is v = c+h
23 define(`vs',`(`$2')*q*cos(`$1'),(`$2')*sin(`$1')')
24 define(`vp',`vs(`$1',`$2'),0')
25 define(`vx',`sum3D(vp(`$1',`$2'),0,0,h+(`$2')^2)')
26
27 # The gradient of v is (2x/q, 2y, -1) and the line
28 # separating front and back is W^T * grad(v) = 0
29 # This line intersects the projected ellipse at
30 # x1,y1 and x2,y2
31 ap = w2^2*q^2/w1^2+1
32 bp = -w2*w3*q^2/w1^2
33 cp = w3^2*q^2/4/w1^2-c
34 m = sqrt(bp^2-4*ap*cp)
35 y1 = (-bp+m)/ap/2 ; x1 = (w3-2*y1*w2)*q/2/w1
36 y2 = (-bp-m)/ap/2 ; x2 = (w3-2*y2*w2)*q/2/w1
37 t1 = atan2(y1,x1)
38 t2 = atan2(y2,x2)
39 theta1 = min(t1,t2)
40 theta2 = max(t1,t2)
41
42 # tangent curve
43 nT = 11
44 for i = 0 to nT do {
45 y = y1 + (y2-y1)/nT*i
46 theta = atan2(y,(w3-2*y*w2)*q/2/w1)
47 r = y/sin(theta)
48 T[i]: Project(vx(theta,r))
49 }
50
51 # front and back parts of the top curve
52 n = 12
53 for i = 0 to n do {
54 theta = theta1 + (theta2-theta1)/n*i
55 F[i]: Project(vx(theta,c))
56 Fp[i]: Project(vp(theta,c))
57 }
58 for i = 0 to n do {
59 theta = theta2 + (theta1+twopi_-theta2)/n*i
60 B[i]: Project(vx(theta,c))
61 Bp[i]: Project(vp(theta,c))
62 }
63
64 # trajectory
65 rotations = 1.55
66 nx = 7
67 thetas = 75*dtor_
68 thetaf = thetas - rotations*twopi_
69 rx = c*0.9
70 beta = exp(log(.5)/20)
71
72 define(`defX',` rx = `$5' ; np = np-1
73 ts = `$1' ; tf = `$2'
74 for i = 0 to `$3' do {
75 tha = ts + (tf-ts)*i/(`$3')
76 for thx = tha to -twopi_ by twopi_ do {}
77 `$4'[i]: Project(vx(thx,rx))
78 Xp[np]: Project(vp(thx,rx))
79 np = np+1
80 rx = beta*rx
81 }')
82
83 np = 1
84 defX(thetas,theta1,nx,X1,rx)
85 defX(theta1,theta2-twopi_,nx,X2,rx/beta)
86 defX(theta2-twopi_,theta1-twopi_,nx,X3,rx/beta)
87 defX(theta1-twopi_,thetaf,5,X4,rx/beta)
88
89 # First draw the inside back
90 # B is the back curve
91 # T is the outline
92 ifpstricks(`
93 \psset{gradbegin=lightgray,gradend=darkgray,gradlines=1000}
94 \pscustom[fillstyle=gradient,gradmidpoint=0.7]{
95 fitcurve(B,n)
96 for i = 0 to nT do {TT[i]: T[nT-i] }
97 fitcurve(TT,nT)
98 \relax} ',
99 ` fitcurve(B,n)
100 for i = 0 to nT do {TT[i]: T[nT-i] }
101 fitcurve(TT,nT) ')
102
103 # Centre axis
104 thinlines_
105 line from Origin to Project(0,0,h)
106 # F[0] is the leftmost point of the front curve
107 line from F[0] to Fp[0]
108 # F[n] is the rightmost point of the front curve
109 line from F[n] to Fp[n]
110 thicklines_
111
112 # Now draw the outside front
113 ifpstricks(`
114 \newgray{gray1}{0.9}%
115 \newgray{gray2}{0.4}%
116 \psset{gradbegin=gray1,gradend=gray2,gradlines=1000}
117 \pscustom[linewidth=0pt,fillstyle=gradient,gradmidpoint=0.99]{
118 fitcurve(F,n)
119 fitcurve(T,nT)
120 \relax} ',
121 ` shade(1,fitcurve(F,n)
122 fitcurve(T,nT)) ')
123 # T is the limit curve of visibility
124 fitcurve(T,nT)
125 # F is the top front
126 fitcurve(F,n)
127 # Front and back projections of the top on xy
128 fitcurve(Fp,n)
129 fitcurve(Bp,n)
130
131 # The trajectory in pieces, to allow dashed parts
132 fitcurve(X1,nx)
133 fitcurve(X2,nx,dotted 0.025)
134 fitcurve(X3,nx)
135 fitcurve(X4,3,dotted 0.015)
136 arca(from X4[4] to X4[3],ccw,0.3,<-)
137
138 # Projected trajectory
139 np = np-2
140 fitcurve(Xp,np-1)
141 arca(from Xp[np] to Xp[np-2],ccw,0.18,<-)
142 "$X(t)$" at Xp[np]-(2bp__,0) ljust
143
144 # Axes and vertical lines
145 thinlines_
146 line from X1[0] to Xp[0]
147 line from X4[4] to Xp[np]
148 arrow from Origin to Project(1.5,0,0)
149 "$x_1$" rjust below
150 arrow from Origin to Project(0,1.5,0)
151 "$x_2$" ljust
152 line dashed from Project(0,0,h) to F[n/2] chop 0 chop arrowht/4
153 arrow from F[n/2] to Project(0,0,2)
154 "$v(X)$" ljust
155
156 "`${0}$'" at Origin+(0,1 pt__) below
157 "$\Omega$" at Project(0,0.9*c,0)+(0,3bp__) above
158 "`$v(X) = c$'" at (Project(vp(100*dtor_,c)))+(2bp__,0) above ljust
159
160 .PE