Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/Ball.m4

raw
1 % Ball.m4 stand-alone (PDF)LaTeX example
2 %
3 % Usage: type
4 % m4 pgf.m4 Ball.m4 | dpic -g > Ball.tex; pdflatex Ball
5 % or:
6 % m4 pstricks.m4 Ball.m4 | dpic -p > Ball.tex; latex Ball; dvips Ball
7 %
8 \documentclass{article}
9 ifpgf(`\usepackage{tikz}',`\usepackage{pstricks,pst-grad}')
10 \pagestyle{empty}
11 \begin{document}
12 %
13 .PS
14 threeD_init
15 command "\small{"
16
17 viewazimuth = 15 # Set view angles in degrees
18 viewelevation = 35
19 setview(viewazimuth,viewelevation)
20
21 #def_bisect # Bring in the equation solver
22 NeedDpicTools
23
24 rectwid = 3.2 # basic dimensions
25 rectht = 2
26 alpha = rectht/3
27
28 # Rectangle
29 ifpstricks(
30 `command "\pscustom[fillstyle=gradient,gradmidpoint=1.0,%"
31 command sprintf("gradbegin=gray,gradend=white,gradlines=%g]{",rectwid*200)')
32 line from Project(-rectht/2,-rectwid*1/3,0) \
33 to Project( rectht/2,-rectwid*1/3,0) \
34 then to Project( rectht/2, rectwid*2/3,0) \
35 then to Project(-rectht/2, rectwid*2/3,0) \
36 then to Project(-rectht/2,-rectwid*1/3,0)
37 ifpstricks(command "}%")
38
39 define(`C3D',`0,0,alpha') # Centre of the sphere
40 C: Project(C3D)
41
42 # Shaded sphere
43 ifelse(m4postprocessor,pstricks,
44 `Highlight: Project(sum3D(C3D,rot3Dz(-15*dtor_,rot3Dy(-60*dtor_,alpha,0,0))))
45 command "\pscustom[fillstyle=gradient,gradmidpoint=0.0,%"
46 command sprintf("gradbegin=gray,gradend=white,gradlines=%g,%%",alpha*200)
47 command "GradientCircle=true,GradientScale=1.5,%"
48 command sprintf("GradientPos={(%g,%g)}]{",Highlight.x,Highlight.y)
49 circle rad alpha at C
50 command "}%"',
51 m4postprocessor,pgf,
52 `command sprintf(\# A little too dark, maybe
53 "\dpicdraw[ball color=white](%g,%g) circle (%gin)\dpicstop",\
54 C.x,C.y,alpha/2.54)',
55 `circle rad alpha at C fill_(1) ')
56
57 S: "$S$" at Project(0,0,0) rjust # The sphere bottom touch point
58 "$\alpha$" at 0.5<S,C> rjust
59
60 define(`N3D',`0,0,2*alpha') # North pole
61 N: "N" at Project(N3D) ljust above
62
63 phi = 65*dtor_
64 define(`Phat3D',`rot3Dz(phi,alpha*2.7,0,0)')
65 Phat: "$\hat{P}$" at Project(Phat3D) ljust
66
67 X: Project(rectht/2*0.8,0,0)
68 Y: Project(0,rectwid/2*0.8,0)
69
70 `define' linevis { # ratio # Visibility function for lines fom S to Xb
71 $2 = distance(($1 between S and Xb),C)-alpha }
72
73 `define' invisline { # name # Draw dashed invisible part of line in
74 Xb: $1 # the plane
75 bisect( linevis, 0, 1, 1e-8, x )
76 line dashed from S to x between S and Xb chop 0 chop 0.05 }
77
78 thinlines_ # axes
79 invisline(X)
80 arrow to X chop 0.05 chop 0; "$x,\:\xi$" at Here+(0,3pt__) below
81 invisline(Y)
82 arrow to Y chop 0.05 chop 0; "$y,\:\eta$" ljust
83 line dashed from S to N chop 0 chop 0.05
84 arrow up alpha*0.5 chop 0.05 chop 0 ; "$z,\:\zeta$" above ljust
85 invisline(Phat)
86 line to Phat chop 0.05 chop 0
87 arc ccw -> rad alpha from Project(alpha/2,0,0) to \
88 Project(rot3Dz(phi,alpha/2,0,0))
89 "$\phi$" below at 0.5 between last arc.start and last arc.end
90
91 # vector (ratio along (N to Phat))
92 define(`ray',`sum3D(N3D,sprod3D($1,diff3D(Phat3D,N3D)))')
93 `define' rayvis { # ratio
94 $2 = length3D(diff3D(ray($1),C3D))-alpha }
95
96 bisect( rayvis, 1e-3, 1, 1e-8, p ) # Find P
97 P: "$P$" at Project(ray(p)) ljust above
98
99 thicklines_
100 line dashed from N to P chop 0 chop 0.05
101 line to Phat chop 0.05 chop 0
102
103 define(`meridian',`rot3Dz(phi,rot3Dy(-($1),alpha,0,0))')
104 `define' meridianvis { # angle # Visibility function on the meridian
105 $2 = dot3D(meridian($1),View3D) }
106
107 thinlines_ # Draw the meridian
108 bisect( meridianvis, 0, pi_, 1e-8, y )
109 n = 0
110 for ang = y-pi_ to y by pi_/20 do {
111 Q[n]: Project(sum3D(C3D,meridian(ang))); n+=1 }
112 fitcurve(Q,n-1)
113 n = 0
114 for ang = y to y+pi_ by pi_/20 do {
115 Q[n]: Project(sum3D(C3D,meridian(ang))); n+=1 }
116 fitcurve(Q,n-1,dashed)
117
118 define(`equator',`rot3Dz($1,alpha,0,0)')
119 `define' equatorvis { # angle # Visibility function on the equator
120 $2 = dot3D(View3D,equator($1)) }
121
122 bisect( equatorvis, 0, pi_, 1e-8, y )
123 n = 0
124 for ang = y-pi_ to y by pi_/20 do {
125 Q[n]: Project(sum3D(C3D,equator(ang))); n+=1 }
126 fitcurve(Q,n-1)
127 n = 0
128 for ang = y to y+pi_ by pi_/20 do {
129 Q[n]: Project(sum3D(C3D,equator(ang))); n+=1 }
130 fitcurve(Q,n-1,dashed)
131
132 line dashed from C to P # beta
133 line dashed from C to Project(sum3D(C3D,equator(phi)))
134 arc ccw -> from 0.6 along_(last line) to 0.6 between C and P
135 "$\beta$" above
136
137 command "}"
138 .PE
139 %
140 \end{document}