diff options
Diffstat (limited to 'graphics/circuit_macros/examples/svg/GeometrySVG.m4')
-rw-r--r-- | graphics/circuit_macros/examples/svg/GeometrySVG.m4 | 268 |
1 files changed, 95 insertions, 173 deletions
diff --git a/graphics/circuit_macros/examples/svg/GeometrySVG.m4 b/graphics/circuit_macros/examples/svg/GeometrySVG.m4 index 5dc1284d08..de5fc62523 100644 --- a/graphics/circuit_macros/examples/svg/GeometrySVG.m4 +++ b/graphics/circuit_macros/examples/svg/GeometrySVG.m4 @@ -1,14 +1,12 @@ .PS # Geometry.m4 +# Some constructions from https://tex.stackexchange.com/ gen_init - maxpswid = 10 - scale = 5/4 -Fig1: [ - - A: Here; "A" at A above - B: A+(-1,-3.5); "B" at B below rjust - C: B+(4.6,0); "C" at C below ljust +Fig1: [ ls = 2/3 # local scale + A: Here; "A" at A above + B: A+(-1*ls,-3.5*ls); "B" at B below rjust + C: B+(4.6*ls,0); "C" at C below ljust AB: line from A to B BC: line from B to C CA: line from C to A @@ -45,181 +43,45 @@ Fig1: [ line dashed from X to Y chop -linewid/2 RightAngle(A,Z,Y) - ] scaled 0.8 - -Fig2: [ -#.PS -# Lyap.m4 -threeD_init -#scale = 1/1.2 - -viewaz = 30 -viewel = 18 -setview(viewaz,viewel) - -Origin: Project(0,0,0) -# Components of view vector W -w1 = view3D1 -w2 = view3D2 -w3 = view3D3 -# Shape factor of the ellipse on the xy plane -q = Cos(40) - -# cost function -h = 0.5 -c = 1 -# The projected ellipse is (x/q)^2 + y^2 = c. -# The cost is v = c+h -define(`vs',``$2'*q*cos(`$1'),`$2'*sin(`$1')') -define(`vp',`vs(`$1',`$2'),0') -define(`vx',`sum3D(vp(`$1',`$2'),0,0,h+(`$2')^2)') - -# The gradient of v is (2x/q, 2y, -1) and the line -# separating front and back is W^T * grad(v) = 0 -# This line intersects the projected ellipse at -# x1,y1 and x2,y2 - ap = w2^2*q^2/w1^2+1 - bp = -w2*w3*q^2/w1^2 - cp = w3^2*q^2/4/w1^2-c - m = sqrt(bp^2-4*ap*cp) - y1 = (-bp+m)/ap/2 ; x1 = (w3-2*y1*w2)*q/2/w1 - y2 = (-bp-m)/ap/2 ; x2 = (w3-2*y2*w2)*q/2/w1 - t1 = atan2(y1,x1) - t2 = atan2(y2,x2) - theta1 = min(t1,t2) - theta2 = max(t1,t2) - -# tangent curve - nT = 11 - for i = 0 to nT do { - y = y1 + (y2-y1)/nT*i - theta = atan2(y,(w3-2*y*w2)*q/2/w1) - r = y/sin(theta) - T[i]: Project(vx(theta,r)) - } - -# front and back parts of the top curve - n = 12 - for i = 0 to n do { - theta = theta1 + (theta2-theta1)/n*i - F[i]: Project(vx(theta,c)) - Fp[i]: Project(vp(theta,c)) - } - for i = 0 to n do { - theta = theta2 + (theta1+twopi_-theta2)/n*i - B[i]: Project(vx(theta,c)) - Bp[i]: Project(vp(theta,c)) - } - -# trajectory -rotations = 1.55 -nx = 7 -thetas = 75*dtor_ -thetaf = thetas - rotations*twopi_ -rx = c*0.9 -beta = exp(log(.5)/20) - -define(`defX',` rx = `$5' ; np = np-1 - ts = `$1' ; tf = `$2' - for i = 0 to `$3' do { - tha = ts + (tf-ts)*i/(`$3') - for thx = tha to -twopi_ by twopi_ do {} - `$4'[i]: Project(vx(thx,rx)) - Xp[np]: Project(vp(thx,rx)) - np = np+1 - rx = beta*rx - }') - -np = 1 -defX(thetas,theta1,nx,X1,rx) -defX(theta1,theta2-twopi_,nx,X2,rx/beta) -defX(theta2-twopi_,theta1-twopi_,nx,X3,rx/beta) -defX(theta1-twopi_,thetaf,5,X4,rx/beta) - -# First draw the inside back -# B is the back curve -# T is the outline -ifpstricks(` -\psset{gradbegin=lightgray,gradend=darkgray,gradlines=1000} -\pscustom[fillstyle=gradient,gradmidpoint=0.7]{ - fitcurve(B,n) - for i = 0 to nT do {TT[i]: T[nT-i] } - fitcurve(TT,nT) -\relax} ', -` fitcurve(B,n) - for i = 0 to nT do {TT[i]: T[nT-i] } - fitcurve(TT,nT) ') - -# Centre axis -thinlines_ -line from Origin to Project(0,0,h) -# F[0] is the leftmost point of the front curve -line from F[0] to Fp[0] -# F[n] is the rightmost point of the front curve -line from F[n] to Fp[n] -thicklines_ - -# Now draw the outside front -ifpstricks(` -\newgray{gray1}{0.9}% -\newgray{gray2}{0.4}% -\psset{gradbegin=gray1,gradend=gray2,gradlines=1000} -\pscustom[linewidth=0pt,fillstyle=gradient,gradmidpoint=0.99]{ - fitcurve(F,n) - fitcurve(T,nT) -\relax} ', -` shade(1,fitcurve(F,n) - fitcurve(T,nT)) ') -# T is the limit curve of visibility - fitcurve(T,nT) -# F is the top front - fitcurve(F,n) -# Front and back projections of the top on xy - fitcurve(Fp,n) - fitcurve(Bp,n) - -# The trajectory in pieces, to allow dashed parts - fitcurve(X1,nx) - fitcurve(X2,nx,dotted 0.025) - fitcurve(X3,nx) - fitcurve(X4,3,dotted 0.015) - arca(from X4[4] to X4[2],ccw,0.3,<-) - -# Projected trajectory - np = np-2 - fitcurve(Xp,np-1) - arca(from Xp[np] to Xp[np-2],ccw,0.18,<-) - "svg_it(X(t))" at Xp[np]-(2bp__,0) ljust - -# Axes and vertical lines -thinlines_ - line from X1[0] to Xp[0] -arrow from Origin to Project(1.5,0,0) -"svg_it(x)`'svg_sub(1)" rjust below -arrow from Origin to Project(0,1.5,0) -"svg_it(x)`'svg_sub(2)" wid 10bp__ ljust -line dashed from Project(0,0,h) to F[n/2] chop 0 chop arrowht/4 -arrow from F[n/2] to Project(0,0,2) -"svg_it(v(X))" ljust - -"svg_it(0)" at Origin+(0,1 pt__) below -"svg_Omega" at Project(0,0.9*c,0) above -"svg_it(v(X) = c)" at (Project(vp(100*dtor_,c)))+(2bp__,0) above ljust - -#.PE - ] scaled 1.5 with .w at last [].e+(0.5,0) + ] + +Fig2: [ ls = 3/4 # local scale +# https://tex.stackexchange.com/questions/593272/drawing-complex-geometry + P: dot(at Here); "P" at P.s below + N: dot(at P+(3.5*ls,1.5*ls)); "N" at N.se ljust below + O: dot(at (N,P)); "O" at O.s below + R: dot(at 1/3 between O and P);"R" at R.s below + M: dot(at (R,N)); "M" at M.se ljust below + Q: dot(at (M.x,M.y+distance(M,N)/distance(N,O)*distance(P,O)));"Q" at Q.e ljust + line from P to Q then to N then to O + B: line to P chop -0.3 + line from M to N + Pu: line from R to Q chop 0 chop -0.3 + H: line from P to N chop 0 chop -0.3 + X: dot(at Intersect_(Pu,H)); "X" at X.se ljust below + thinlines_ + RightAngle(Q,M,N) + RightAngle(Q,N,H.end) + RightAngle(N,O,B.start) + ArcAngle(N,P,Q,0.4); "svg_beta" at last arc.ne above ljust + ArcAngle(O,P,N,0.5); "svg_alpha" at last arc.start+(5bp__,8bp__) + ArcAngle(R,Q,N,0.5); "svg_alpha" at last arc.start+(8bp__,-5bp__) + ] with .w at Fig1.e+(-0.4,0) Fig3: [ +# FourbarSVG.m4 # https://tex.stackexchange.com/questions/609452/help-drawing-a-more-sophisticated-right-triangle-with-tikz-or-something-else -gen_init - unit = 0.8 + textkht = 12/72 + unit = 0.6 C: Here; { "C" at C rjust below } B: C+(4*unit,0); { "B" at B ljust below } A: C+(0,3*unit); { "A" at A rjust above } H: PerpTo(C,A,B); { "H" at H ljust above } line from C to H then to B then to C shaded rgbstring(0.5,0.8,0.9) +# line from C to H then to B then to C shaded "CornflowerBlue" line from C to H then to A then to C shaded rgbstring(0.8,0.9,0.7) +# line from C to H then to A then to C shaded "SpringGreen" ArcAngle(C,A,B,unit*0.4) ArcAngle(C,A,B,unit*0.5) ArcAngle(A,B,C,unit*0.5,,"svg_theta" rjust) @@ -228,6 +90,66 @@ gen_init RightAngle(B,C,A,unit*0.17) RightAngle(C,H,A,unit*0.17) - ] with .sw at Fig2.se+(0.2,0) + ] with .nw at Fig1.sw+(0.2,-0.3) + +Fig4: [ + +# FourbarSVG.m4 +# https://tex.stackexchange.com/questions/563831/how-to-draw-four-bar-linkage-with-center-of-mass +ls = 1/25.4 # local scale + + a = 18*ls + b = 73*ls + c = 47*ls + d = 72*ls + A0: Here + B0: A0+(d,0) + circlerad = 1*ls + +define(`pivot',`[ + C: circle + line down_ 4*ls from C+(2*ls,0) + arc from last line.start to C+(-2*ls,0) with .c at C + line down_ 4*ls + B: line thick 1.6 right 7*ls with .c at (C,Here) + thinlines_ + sep = 0.9*ls + nhash = B.len/sep + for i=0 to nhash do { line down sep left sep from B.end-(i/nhash*B.len,0) } + thicklines_ + ]') + + pivot with .C at A0; "A`'svg_sub(0)" at A0-(5,0)*ls + circle dashed rad a at A0 + pivot with .C at B0; "B`'svg_sub(0)" at B0-(5,0)*ls + "d = A`'svg_sub(0)B`'svg_sub(0)" at 0.5<A0,B0> + + B1: Cintersect(A0,a+b,B0,c) + B2: Cintersect(A0,b-a,B0,c) + arc dashed from B1 to B2 with .c at B0 + + A0B1: line thick 1.6 from A0 to B1 chop 2*ls chop 0 + line thick 1.6 from B0 to B1 chop 2*ls chop 0 "c" ljust + circle fill_(1) at B1; "B`'svg_sub(1)" wid 3*ls at B1+(5,0)*ls + A1: circle fill_(1) at LCintersect(A0B1,A0,a,R) + "A`'svg_sub(1)" at A1+(5,0)*ls + + A2: b/(b-a) between B2 and A0; "a" at 0.4<A2,A0> above rjust + "b" at 0.4<A1,B1> above rjust + A2B2: line thick 1.6 from A2 to B2 + line thick 1.6 from B0 to B2 chop 2*ls chop 0 + circle fill_(1) at B2; "B`'svg_sub(2)" at B2+(5,0)*ls + circle fill_(1) at A2; "A`'svg_sub(2)" at A2+(5,0)*ls + + thinlines_ + line from B0+(3*ls,0) right 4*ls + ArcAngle(Here,B0,B1,5*ls) ->; "svg_psi`'svg_sub(0)" at last arc.ne above ljust + ArcAngle(B1,B0,B2,8*ls) ->; "svg_psi" at last arc.n+(-3*ls,0) above + ArcAngle(A1,A0,B2,b*0.45) ->; "svg_theta" at last arc.start+(0,4*ls) + line from A0+(3*ls,0) right 8*ls + ArcAngle(Here,A0,B1,9*ls) ->; "svg_theta`'svg_sub(0)" \ + at last arc.start+(2,2)*ls + + ] with .nw at Fig3.ne+(0.2,0.2) .PE |