|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
/*
* This file:
* http://anggtwu.net/myqdraw/myqdraw3.mac.html
* http://anggtwu.net/myqdraw/myqdraw3.mac
* (find-myqdraw "/myqdraw3.mac")
* Author: Eduardo Ochs <eduardoochs@gmail.com>
* Homepage: http://anggtwu.net/eev-qdraw.html
* License: Public Domain
* Version: 2025mar18
*
* This is "myqdraw3.mac" - my third attempt to extend qdraw
* in useful ways. Qdraw is this:
*
* https://home.csulb.edu/~woollett/mbe.html
* https://home.csulb.edu/~woollett/mbe13qdraw.pdf
* https://home.csulb.edu/~woollett/qdraw.mac
* (find-windows-beginner-intro "12. Install qdraw")
*
* and myqdraw is explained here:
*
* http://anggtwu.net/eev-qdraw.html
*
* This file defines `myqdraw' and several variants for it.
* `myqdraw' is like `qdraw', but it flattens its arguments.
* Here are the explanations for the suffixes and prefixes:
*
* The prefix "my" means "flatten the arguments".
* The suffix "v" means "vertical output" (for debugging).
* The suffix "1" has several meanings:
* qdraw1 (line(1,2,3,4)) returns drlist instead of drawing it
* myqdraw1 (line(1,2,3,4)) returns drlist instead of drawing it
* myqdraw1v(line(1,2,3,4)) returns drlist in "vertical format"
* myqdraw1.mac is an older version of these functions
* myapply (f,[L]) receives f and a vararg
* myapply1(f, L ) receives a single list instead of a vararg
*
* The suffix "p" means "to pdf".
* The variants with "p" are defined here:
* (find-myqdraw "topdf1.mac" "myqdrawp-modes")
*
* This file loads both "qdraw.mac" and "topdf1.mac". See:
* (find-angg ".maxima/maxima-init.mac" "load_qdraw")
* (find-myqdraw "topdf1.mac")
*
* (defun q3 () (interactive) (find-myqdraw "/myqdraw3.mac"))
* (defun q2 () (interactive) (find-myqdraw "/myqdraw2.mac"))
*
* «.load» (to "load")
* «.myqdraw» (to "myqdraw")
* «.myapply» (to "myapply")
* «.xyrange» (to "xyrange")
* «.myex» (to "myex")
* «.myimp» (to "myimp")
* «.mypara» (to "mypara")
* «.pts_open» (to "pts_open")
* «.myPv» (to "myPv")
* «.zpts» (to "zpts")
* «.directionfield» (to "directionfield")
* «.set-comprehensions» (to "set-comprehensions")
* «.setofxyst» (to "setofxyst")
* «.myterminalpdf» (to "myterminalpdf")
*/
/* «load» (to ".load")
* See: (find-myqdraw "myqdraw-core.mac")
* (find-myqdraw "myqdraw-tex.lisp")
* (find-myqdraw "topdf1.mac")
* and: http://anggtwu.net/eev-qdraw.html#the-loads
* (find-TH "eev-qdraw" "the-loads")
*/
myqdrawdir : pathname_directory(load_pathname);
load(concat(myqdrawdir, "qdraw.mac"));
load(concat(myqdrawdir, "myqdraw-core.mac"));
load(concat(myqdrawdir, "myqdraw-tex.lisp"));
load(concat(myqdrawdir, "topdf1.mac"));
/* «xyrange» (to ".xyrange")
*/
[xmin,ymin, xmax,ymax] : [-1,-1, 5,4];
xyrange0() := [xr(xmin,xmax), yr(ymin,ymax)];
xyrange () := [xr(xmin,xmax), yr(ymin,ymax), more(proportional_axes=xy)];
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
myqdraw(xyrange(), para(cos(t),sin(t), t,0,2*%pi));
[xmin,ymin, xmax,ymax] : [-2,-2, 10,6];
myqdraw(xyrange(), para(cos(t),sin(t), t,0,2*%pi));
*/
/* «myex» (to ".myex")
* (find-es "qdraw" "ex")
*/
myex (fxs,[opts]) := makelist(myapply_fl('ex1, fx, 'x,xmin,xmax, opts), fx,fxs);
myex1(fx, [opts]) := myapply_fl('ex1, fx, x,xmin,xmax, opts);
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
[xmin,xmax] : [-2,2];
myqdraw(myex([x,x^2], lc(orange)));
myqdraw(myex1(x, lc(orange)),
myex1(x^2, lc(red)));
*/
/* «myimp» (to ".myimp")
* (find-es "qdraw" "imp")
*/
myimp (eqs,[opts]) := myapply_fl('imp, eqs, x,xmin,xmax, y,ymin,ymax, opts);
myimp1(eq, [opts]) := myapply_fl('imp1, eq , x,xmin,xmax, y,ymin,ymax, opts);
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
F : x^2 + y^2;
myqdraw(xyrange(), myimp([F=1,F=2]));
myqdraw(xyrange(), myimp1(F=1, lc(orange)),
myimp1(F=2, lc(red)));
*/
/* «mypara» (to ".mypara")
*/
mypara(xy,[rest]) := myapply('para, xy[1],xy[2], rest);
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
P(t) := [cos(t),sin(t)];
myqdraw(xyrange(), mypara(P(t)+[2,2], t,0,2*%pi));
*/
/* «pts_open» (to ".pts_open")
* (find-es "qdraw" "point-types")
*/
pt_open : pt(6);
pt_closed : pt(7);
pts_open(coords, [opts]) :=
[myapply_fl('pts, coords, pc(white),pt_closed,opts),
myapply_fl('pts, coords, pt_open, opts)];
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
myqdraw(xr(-1,4),yr(-1,3),
para(x,1, x,1,3),
pts_open([[1,1],[2,1]]),
pts ([[3,1]]));
*/
/* «myPv» (to ".myPv")
*/
myPv (P,v, Popts,[vopts]) :=
[myapply_fl('pts, [P], Popts),
myapply_fl('vector, P,v, vopts)];
myPPe(P0,P1,eps,Popts,[vopts]) :=
[myapply_fl('pts, [P0,P1], Popts),
myapply_fl('vector, P0,(P1-P0)/eps, vopts)];
myPopts (colr) := [pc(colr),ps(2)];
myvopts (colr) := [lc(colr),hl(0.15),ht(f)];
myPv_c (P,v, colr) := myPv (P,v, myPopts(colr), myvopts(colr));
myPPe_c(P0,P1,eps,colr) := myPPe(P0,P1,eps, myPopts(colr), myvopts(colr));
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
P(t) := [cos(t),sin(t)] + [2,1];
define(vel(t), diff(P(t),t));
myqdraw(xyrange(),
mypara (P(t), t,0,2*%pi, lc(orange)),
myPv_c (P(1), vel(1), red),
myPPe_c(P(2), P(3.2), 1.2, forest_green),
myPPe_c(P(2), P(2.5), 0.5, forest_green),
myPPe_c(P(2), P(2.2), 0.2, forest_green)
);
*/
/* «zpts» (to ".zpts")
*/
ztoxy (z) := [realpart(z), imagpart(z)];
xytoz (x,y) := x + %i*y;
zflatten([zs]) := map('ztoxy, flatten(zs));
zpts (zs,[opts]) := myapply_fl('pts, zflatten(zs), opts);
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
[xmin,ymin, xmax,ymax] : [-3,-3, 3,3];
a : 1 + %i*1/2;
as : makelist(a^n, n,0,10);
myqdraw(xyrange(), zpts(as));
*/
/* «directionfield» (to ".directionfield")
*/
directionfield_r : 5;
directionfield_xs : seq(-2,2);
directionfield_ys : seq(-2,2);
directionfield_0 (x,y,dy,dx,[opts]) :=
block([len,vv,P1,P2],
len : sqrt(dx^2+dy^2),
vv : ([dy,dx]/len)/directionfield_r,
P1 : [x,y]-vv,
P2 : [x,y]+vv,
myapply_fl('line, P1[1],P1[2], P2[1],P2[2], opts))$
directionfield_1 (x,y,dy,dx,[opts]) :=
if dx=0 and dy=0 then [] else directionfield_0(x,y,dy,dx,opts);
directionfield (dy,dx,[opts]) ::=
create_list(directionfield_1(x,y,ev(dy),ev(dx),opts),
x,seq(-2,2), y,seq(-2,2));
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
[xmin,ymin, xmax,ymax] : [-3,-3, 3,3];
myqdraw(xyrange(), directionfield(-y,x-1, lc(red)));
*/
/* «set-comprehensions» (to ".set-comprehensions")
* See: (find-es "qdraw" "set-comprehensions")
* I only implemented a few of the syntaxes from:
* (mpgp 8 "comprehension")
* (mpga "comprehension")
* (mpgp 10 "comprehension-ex123")
* (mpga "comprehension-ex123")
*
* Shorthands: setofst -> set-of-such-that
* setofsc -> set-of-semicolon
* gorf -> generator or filter
* e -> (resulting) expression
*
* Two examples:
* {(x,y,z) | x∈{2,4}, y∈{3,...,5}, z∈{6,6.5,...,8}, x<=y}
* -> setofst([x,y,z], [x,[2,4]], [y,3,5], [z,6,8,0.5], [x<=y])
*
* {x∈{2,4}, y∈{3,...,5}, z∈{6,6.5,...,8}, x<=y ; (x,y,z)}
* -> setofsc([x,[2,4]], [y,3,5], [z,6,8,0.5], [x<=y], [x,y,z])
*
* A `2', `3' or `4' at the end of a function name indicates the
* number of arguments; an `_' at the end indicates a function that
* people can use to understand the translation.
*/
gen2 (var,list) := [var,list];
gen3 (var,a,b) := [var,seq(a,b)];
gen4 (var,a,b,stp) := [var,seqby(a,b,stp)];
guard_(cond) := if cond then [42] else [];
guard (cond) := [_g_, guard_(cond)];
expandgorf (gorf) := apply(['guard,'gen2,'gen3,'gen4][length(gorf)], gorf);
expandgorfs (gorfs) := apply('append, map('expandgorf, gorfs));
expandegorfs(e, gorfs) := append([e], expandgorfs(gorfs));
setofst2_ (e, gorfs) := append([e], expandgorfs(gorfs));
setofst2 (e, gorfs) := apply('create_list, expandegorfs(e, gorfs));
setofst_ (e,[gorfs]) := setofst2_(e, gorfs);
setofst (e,[gorfs]) := setofst2 (e, gorfs);
setofsc_ ([gorfs_e]) := setofst2_(last(gorfs_e), butlast(gorfs_e));
setofsc ([gorfs_e]) := setofst2 (last(gorfs_e), butlast(gorfs_e));
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
expandgorfs ([[x,[2,4]], [y,3,5], [z,6,8,0.5], [x<=y]]);
expandegorfs([x,y,z], [[x,[2,4]], [y,3,5], [z,6,8,0.5], [x<=y]]);
setofst2_ ([x,y,z], [[x,[2,4]], [y,3,5], [z,6,8,0.5], [x<=y]]);
setofst_ ([x,y,z], [x,[2,4]], [y,3,5], [z,6,8,0.5], [x<=y]);
setofsc_ ([x,[2,4]], [y,3,5], [z,6,8,0.5], [x<=y], [x,y,z]);
[xmin,ymin, xmax,ymax] : [-4,-4, 4,4];
myqdraw(xyrange(), pts(setofst([x,x^2], [x,-4,4])))$
myqdraw(xyrange(), pts(setofst([x,y], [x,-4,4,0.5], [y,-4,4,0.5], [y>=x^2])))$
myqdraw(xyrange(), pts(setofst([x,y], [x,-4,4,0.2], [y,-4,4,0.2], [y>=x^2]), ps(1)))$
myqdraw(xyrange(), pts(setofst([x,y], [x,-4,4,0.1], [y,-4,4,0.1], [y>=x^2]), ps(0.5)))$
*/
/* «setofxyst» (to ".setofxyst")
*/
setofxyst_adjust : 4;
setofxyst_2 (cond,stp) :=
setofst([x,y], [x,xmin,xmax,stp], [y,ymin,ymax,stp], [cond]);
setofxyst_pts(cond,stp,[opts]) :=
myapply_fl('pts, setofxyst_2(cond,stp), ps(setofxyst_adjust*stp), opts);
/*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
[xmin,ymin, xmax,ymax] : [-4,-4, 4,4];
setofxyst_adjust : 4;
myqdraw(xyrange(), setofxyst_pts(y>=x^2, 1));
myqdraw(xyrange(), setofxyst_pts(y>=x^2, 1/2));
myqdraw(xyrange(), setofxyst_pts(y>=x^2, 1/4));
myqdraw(xyrange(), setofxyst_pts(y>=x^2, 1/8));
[xmin,ymin, xmax,ymax] : [-2,-2, 2,2];
setofxyst_adjust : 8;
implies(P,Q) := not(P) or Q;
myqdraw(xyrange(), setofxyst_pts('(implies(x^2=y^2, x=y)), 1));
*/
/* «myterminalpdf» (to ".myterminalpdf")
* Similar to: (find-myqdraw "topdf1.mac")
* but minimal.
*/
myterminalpdf (stem) := more(terminal=pdf, file_name=stem);
myincludegraphics(opts,stem) := format("\\includegraphics[~a]{~a.pdf}", opts, stem);
/*
* (find-sh0 "ls -lAF /tmp/test*")
* (find-sh0 "rm -fv /tmp/test*")
*
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("myqdraw3.mac");
P(t) := [cos(t),sin(t)] + [2,1];
drawing : [xyrange(), mypara(P(t), t,0,2*%pi)];
myqdraw(drawing);
myqdraw(drawing, myterminalpdf("/tmp/test"));
myincludegraphics("height=3cm", "test");
* (find-sh0 "ls -lAF /tmp/test*")
** (find-pdf-page "/tmp/test.pdf")
*/
/*
* Local Variables:
* coding: utf-8-unix
* End:
*/