diff options
author | Norbert Preining <norbert@preining.info> | 2021-06-04 03:02:48 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2021-06-04 03:02:48 +0000 |
commit | a5ae129f3aa3a3a0aeaa21c55b75a1d543fe4111 (patch) | |
tree | fe5e1e212aec203e668df8581a17374cdde352a1 /graphics/circuit_macros/lib3D.m4 | |
parent | d231c6331f53a048d29c2f847254a9f56d5ee2dd (diff) |
CTAN sync 202106040302
Diffstat (limited to 'graphics/circuit_macros/lib3D.m4')
-rw-r--r-- | graphics/circuit_macros/lib3D.m4 | 125 |
1 files changed, 75 insertions, 50 deletions
diff --git a/graphics/circuit_macros/lib3D.m4 b/graphics/circuit_macros/lib3D.m4 index 12f5170274..38ccc99d23 100644 --- a/graphics/circuit_macros/lib3D.m4 +++ b/graphics/circuit_macros/lib3D.m4 @@ -1,9 +1,9 @@ divert(-1) lib3D.m4 Macros for rotation, projection, and other operations on argument triples representing - 3D vectors. + 3D vectors or colors. -* Circuit_macros Version 9.5, copyright (c) 2021 J. D. Aplevich under * +* Circuit_macros Version 9.6, copyright (c) 2021 J. D. Aplevich under * * the LaTeX Project Public Licence in file Licence.txt. The files of * * this distribution may be redistributed or modified provided that this * * copyright notice is included and provided that modifications are clearly * @@ -26,21 +26,36 @@ ifdef(`libgen_',,`include(libgen.m4)divert(-1)') P =( -sin(az), cos(az), 0 ) (-sin(el)cos(az),-sin(az)sin(el),cos(el))' define(`setview',` -# setview - m4azim=ifelse(`$1',,0,`$1',0,0,`prod_(`$1',dtor_)') - m4elev=ifelse(`$2',,0,`$2',0,0,`prod_(`$2',dtor_)') - m4rot =ifelse(`$3',,0,`$3',0,0,`prod_(`$3',dtor_)') - m4caz=ifelse(`$1',,1,`$1',0,1,`$1',90,0,`$1',-90, 0,cos(m4azim)) - m4saz=ifelse(`$1',,0,`$1',0,0,`$1',90,1,`$1',-90,-1,sin(m4azim)) - m4cel=ifelse(`$2',,1,`$2',0,1,`$2',90,0,`$2',-90, 0,cos(m4elev)) - m4sel=ifelse(`$2',,0,`$2',0,0,`$2',90,1,`$2',-90,-1,sin(m4elev)) - m4cro=ifelse(`$3',,1,`$3',0,1,`$3',90,0,`$3',-90, 0,cos(m4rot)) - m4sro=ifelse(`$3',,0,`$3',0,0,`$3',90,1,`$3',-90,-1,sin(m4rot)) - view3D1=m4caz*m4cel - view3D2=m4saz*m4cel - view3D3=m4sel dnl - ifdef(`setlight_',,`; light3D1=view3D1; light3D2=view3D2; light3D3=view3D3') +`# setview($@)' +define(`m4azim',ifelse(`$1',,0,prod_($1,dtor_)))dnl +define(`m4elev',ifelse(`$2',,0,prod_($2,dtor_)))dnl +define(`m4rot', ifelse(`$3',,0,prod_($3,dtor_)))dnl +define(`m4azimr',`ifelse(`$1',,0,`prod_(`$1',dtor_)')')dnl +define(`m4elevr',`ifelse(`$2',,0,`prod_(`$2',dtor_)')')dnl +define(`m4rotx',`ifelse(`$3',,0,`prod_(`$3',dtor_)')')dnl +define(`m4caz', + `ifelse(`$1',,1,`$1',0,1,`$1',90,0,`$1',-90, 0,m4cos(m4azim))')dnl +define(`m4saz', + `ifelse(`$1',,0,`$1',0,0,`$1',90,1,`$1',-90,-1,m4sin(m4azim))')dnl +define(`m4cel', + `ifelse(`$2',,1,`$2',0,1,`$2',90,0,`$2',-90, 0,m4cos(m4elev))')dnl +define(`m4sel', + `ifelse(`$2',,0,`$2',0,0,`$2',90,1,`$2',-90,-1,m4sin(m4elev))')dnl +define(`m4cro',`ifelse(`$3',,1,`$3',0,1,`$3',90,0,`$3',-90, 0,m4cos(m4rot))')dnl +define(`m4sro',`ifelse(`$3',,0,`$3',0,0,`$3',90,1,`$3',-90,-1,m4sin(m4rot))')dnl + view3D1=m4caz*m4cel;dnl + view3D2=m4saz*m4cel;dnl + view3D3=m4sel + ifdef(`setlight_',,`light3D1=view3D1; light3D2=view3D2; light3D3=view3D3') +dnl Unit vectors projected on the view plane + UPx_: project(1,0,0) + UPy_: project(0,1,0) + UPz_: project(0,0,1) +`# setview end' ') +define(`m4cos',`ifelse(`$1',0,1,cos(`$1'))') +define(`m4sin',`ifelse(`$1',0,0,sin(`$1'))') + The resulting view vector #efine(`View3D',`PtoBase3D(1,0,0)') define(`View3D',`view3D1,view3D2,view3D3') @@ -51,36 +66,45 @@ define(`Pr_xy',`$1,$2') define(`Pr_xz',`$1,$3') define(`Pr_yz',`$2,$3') - Projection coords back to orig 3D coords + Projection coords back to orig 3D coords define(`PtoBase3D', `rot3Dz(m4azim,rot3Dy(-m4elev,rot3Dx(-m4rot,`$1',`$2',`$3')))') - This does the 3D to 2D axonometric projection - i.e. project(x,y,z) produces coordinate pair - u,v on the 2D plane defined by the view angles. -define(`project', -`Pr_yz(rot3Dx(m4rot,rot3Dy(m4elev,rot3Dz(-m4azim,`$1',`$2',`$3'))))') + This does the 3D to 2D axonometric projection + i.e. project(x,y,z) produces coordinate pair + u,v on the 2D plane defined by the view angles + and Project(x,y,z) produces position (u,v) +ifdpic( +`define(`project', + `Pr_yz(rot3Dx(m4rot,rot3Dy(m4elev,rot3Dz(-m4azim,`$1',`$2',`$3'))))') + define(`Project',`(ifelse(`$1',0, + `ifelse(`$2',0,`ifelse(`$3',0,`(0,0)',UPz_*(`$3'))', + `UPy_*(`$2')`'ifelse(`$3',0,,+UPz_*(`$3'))')', + `UPx_*(`$1')`'ifelse(`$2',0,,+UPy_*(`$2'))`'ifelse(`$3',0,,+UPz_*(`$3'))'))')', +`define(`project', + `Pr_yz(rot3Dx(m4rot,rot3Dy(m4elev,rot3Dz(-m4azim,`$1',`$2',`$3'))))') + define(`Project',`(project($@))')') `Rotation about x axis rot3Dx(angle,x1,x2,x3)' -define(`rot3Dx',``$2',diff_(prod_(cos(`$1'),`$3'),prod_(sin(`$1'),`$4')),dnl - sum_(prod_(sin(`$1'),`$3'),prod_(cos(`$1'),`$4'))') +define(`rot3Dx',``$2',diff_(prod_(m4cos(`$1'),`$3'),prod_(m4sin(`$1'),`$4')),dnl + sum_(prod_(m4sin(`$1'),`$3'),prod_(m4cos(`$1'),`$4'))') `Rotation about y axis rot3Dy(angle,x1,x2,x3)' -define(`rot3Dy',`sum_(prod_(cos(`$1'),`$2'),prod_(sin(`$1'),`$4')),`$3',dnl - diff_(prod_(cos(`$1'),`$4'),prod_(sin(`$1'),`$2'))') +define(`rot3Dy',`sum_(prod_(m4cos(`$1'),`$2'),prod_(m4sin(`$1'),`$4')),`$3',dnl + diff_(prod_(m4cos(`$1'),`$4'),prod_(m4sin(`$1'),`$2'))') `Rotation about z axis rot3Dz(angle,x1,x2,x3)' -define(`rot3Dz',`diff_(prod_(cos(`$1'),`$2'),prod_(sin(`$1'),`$3')),dnl - sum_(prod_(sin(`$1'),`$2'),prod_(cos(`$1'),`$3')),`$4'') +define(`rot3Dz',`diff_(prod_(m4cos(`$1'),`$2'),prod_(m4sin(`$1'),`$3')),dnl + sum_(prod_(m4sin(`$1'),`$2'),prod_(m4cos(`$1'),`$3')),`$4'') `Cross product cross3D(x1,y1,z1,x2,y2,z2)' define(`cross3D',`diff_(prod_(`$2',`$6'),prod_(`$3',`$5')),dnl - diff_(prod_(`$3',`$4'),prod_(`$1',`$6')),dnl - diff_(prod_(`$1',`$5'),prod_(`$2',`$4'))') + diff_(prod_(`$3',`$4'),prod_(`$1',`$6')),dnl + diff_(prod_(`$1',`$5'),prod_(`$2',`$4'))') `Dot product dot3D(x1,y1,z1,x2,y2,z2)' define(`dot3D',`(sum_( - sum_(prod_(`$1',`$4'),prod_(`$2',`$5')),prod_(`$3',`$6')))') + sum_(prod_(`$1',`$4'),prod_(`$2',`$5')),prod_(`$3',`$6')))') Vector addition, subtraction, scalar product define(`sum3D',`sum_(`$1',`$4'),sum_(`$2',`$5'),sum_(`$3',`$6')') define(`diff3D',`diff_(`$1',`$4'),diff_(`$2',`$5'),diff_(`$3',`$6')') @@ -92,40 +116,41 @@ define(`dcosine3D',`(ifelse(`$1',1,`$2',`$1',2,`$3',`$4'))') define(`length3D',`sqrt((`$1')^2+(`$2')^2+(`$3')^2)') Unit vector define(`unit3D',`sprod3D(1/length3D(`$1',`$2',`$3'),`$1',`$2',`$3')') + Proportion: between3D(x,Vec1,Vec2), i.e. + Vec1 * (1-x) + Vec2 * x +define(`between3D',`sum3D(sprod3D((1-(`$1')),`$2',`$3',`$4'), + sprod3D( `$1',`$5',`$6',`$7'))') - `Assign the direction cosines to variables - assign3D([u],[v],[w],x,y,z); eg + `assign3D([u],[v],[w],x,y,z); eg assign3D(u,v,w,cross3D(x1,y1,z1,x2,y2,z2)) - assigns the 4th arg to u, the 5th to v, - and the 6th to w as u, v,or w are nonblank' -define(`assign3D', -`ifelse(`$1',,,`$1' = `$4') - ifelse(`$2',,,`$2' = `$5') - ifelse(`$3',,,`$3' = `$6')') + assigns u = 4th arg, v = 5th arg, w = 6th arg, + for nonblank u, v, or w' +define(`assign3D',`assign3($@)') + `vassign3D(name,x,y,z); eg vassign3D(u,x,y,z) - assigns u[1] to x, u[2] to y, u[3] to z' + assigns u[1] = x, u[2] = y, u[3] = z' define(`vassign3D',`for i_vassign3D = 1 to 3 do { exec sprintf("`$1'[i_vassign3D] = $%g",i_vassign3D+3) }') Write out the 3 arguments for debug define(`print3D',`print sprintf("`$1'(%g,%g,%g)",`$2',`$3',`$4')') - `setlightlight (azimuth, elevation, rotation) + `setlight (azimuth, elevation, rotation) Set angles (degrees) for 3D highlighting. Defaults are the previous values for setview(). The Light3D vector is defined as for View3D.' define(`setlight',`define(`setlight_') - m4hzim=ifelse(`$1',,m4azim,`$1',0,0,`prod_(`$1',dtor_)') - m4hlev=ifelse(`$2',,m4elev,`$2',0,0,`prod_(`$2',dtor_)') - m4hot =ifelse(`$3',,m4rot,`$3',0,0,`prod_(`$3',dtor_)') - m4chz=ifelse(`$1',0,1,`$1',90,0,`$1',-90, 0,cos(m4hzim)) - m4shz=ifelse(`$1',0,0,`$1',90,1,`$1',-90,-1,sin(m4hzim)) - m4chl=ifelse(`$2',0,1,`$2',90,0,`$2',-90, 0,cos(m4hlev)) - m4shl=ifelse(`$2',0,0,`$2',90,1,`$2',-90,-1,sin(m4hlev)) - m4cho=ifelse(`$3',0,1,`$3',90,0,`$3',-90, 0,cos(m4hot)) - m4sho=ifelse(`$3',0,0,`$3',90,1,`$3',-90,-1,sin(m4hot)) + define(`m4hzim',`ifelse(`$1',,m4azimr,`prod_(`$1',dtor_)')')dnl + define(`m4hlev',`ifelse(`$2',,m4elevr,`prod_(`$2',dtor_)')')dnl + define(`m4hot',`ifelse(`$3',,m4rotx,`prod_(`$3',dtor_)')')dnl + define(`m4chz',`ifelse(`$1',0,1,`$1',90,0,`$1',-90, 0,cos(m4hzim))')dnl + define(`m4shz',`ifelse(`$1',0,0,`$1',90,1,`$1',-90,-1,sin(m4hzim))')dnl + define(`m4chl',`ifelse(`$2',0,1,`$2',90,0,`$2',-90, 0,cos(m4hlev))')dnl + define(`m4shl',`ifelse(`$2',0,0,`$2',90,1,`$2',-90,-1,sin(m4hlev))')dnl + define(`m4cho',`ifelse(`$3',0,1,`$3',90,0,`$3',-90, 0,cos(m4hot))')dnl + define(`m4sho',`ifelse(`$3',0,0,`$3',90,1,`$3',-90,-1,sin(m4hot))')dnl light3D1=m4chz*m4chl light3D2=m4shz*m4chl light3D3=m4shl |