# PROGRAM: Vanishing Points # AUTHOR: Andrejs Treibergs # DATE: 6-23-01 > with(plots):with(linalg); Warning, the protected names norm and trace have been redefined and unprotected [BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, coldim, colspace, colspan, companion, concat, cond, copyinto, crossprod, curl, definite, delcols, delrows, det, diag, diverge, dotprod, eigenvals, eigenvalues, eigenvectors, eigenvects, entermatrix, equal, exponential, extend, ffgausselim, fibonacci, forwardsub, frobenius, gausselim, gaussjord, geneqns, genmatrix, grad, hadamard, hermite, hessian, hilbert, htranspose, ihermite, indexfunc, innerprod, intbasis, inverse, ismith, issimilar, iszero, jacobian, jordan, kernel, laplacian, leastsqrs, linsolve, matadd, matrix, minor, minpoly, mulcol, mulrow, multiply, norm, normalize, nullspace, orthog, permanent, pivot, potential, randmatrix, randvector, rank, ratform, row, rowdim, rowspace, rowspan, rref, scalarmul, singularvals, smith, stackmatrix, submatrix, subvector, sumbasis, swapcol, swaprow, sylvester, toeplitz, trace, transpose, vandermonde, vecpotent, vectdim, vector, wronskian] # A cube with long lines to infinity. > bob:=[[0,0,0],[0,0,1],[1000,0,1],[0,1,1],[0,1,0],[1000,0,0],[0,0,0],[0 > ,1000,0],[1,0,0],[1,0,1],[0,1000,0],[0,0,1]]:spacecurve(bob,view=[-1.. > 10,-1..10,-1..10]); > spacecurve(bob,view=[-1..10,-1..10,-1..2],scaling=constrained# > ,axes=normal); # Rotation function. > rogue:=lis->[cos(theta)*lis[1]-sin(theta)*lis[2],sin(theta)*lis[1]+cos > (theta)*lis[2],lis[3]]; > theta:=0.5;hlis:=map(rogue,bob); # Perpendicular projection of cube. # # > ep:=[0.0,-3.5,1.90]; > cp:=[0.0,0.0,0.5];lis:='lis'; > T:=lis->[lis[1]-ep[1],lis[2]-ep[2],lis[3]-ep[3]]: > dp:=T(cp): > r1:=sqrt(dp[1]^2+dp[2]^2): > s1:=dp[1]/r1:c1:=dp[2]/r1: > R:=lis->[c1*lis[1]-s1*lis[2],c1*lis[2]+s1*lis[1],lis[3]]: > rdp:=R(dp): > r2:=sqrt(dp[1]^2+dp[2]^2+dp[3]^2): > s2:=rdp[3]/r2:c2:=rdp[2]/r2: > S:=lis->[lis[1],-s2*lis[2]+c2*lis[3],c2*lis[2]+s2*lis[3]]: > S(rdp): > SRT:=lis->S(R(T(lis))): > GPp:=lis->[op(1,SRT(lis)),op(2,SRT(lis))]:GPpP:=lis->op(3,SRT(lis)): > delta=10.1;GPp(lis);GPpP(lis); ep := [0., -3.5, 1.90] cp := [0., 0., .5] lis := lis delta = 10.1 [1.000000000 lis[1], .3713906764 lis[2] - .464238346 + .9284766909 lis[3]] .9284766909 lis[2] + 3.955310703 - .3713906764 lis[3] > nn:=nops(hlis); kpro:=map(GPp,hlis): > display([plot(kpro,color=`navy`), > plot({[GPp([0,0,-3]),GPp([0,0,10])],[GPp([0,-3,0]),GPp([0,10,0])],[GPp > ([-3,0,0]),GPp([10,0,0])]},color=gray),plot([[0,0]],style=point,symbol > =circle)], scaling=constrained,title=`Parallel Projection in Eye to > Center direction`,axes=none,view=[-21..21,-21..21]); # nn := 12 # Perspective view of cube. # > GPx:=lis->[op(1,GPp(lis))/GPpP(lis),op(2,GPp(lis))/GPpP(lis)]: > colo:=[`magenta`,`red`,`coral`,`yellow`,`green`,`cyan`,`blue`,`navy`,` > violet`,`maroon`]: > nn:=nops(hlis); kpro:=map(GPx,hlis): display([plot(kpro,color=blue), > plot({[GPx([0,0,-3]),GPx([0,0,10])], [GPx([0,-3,0]),GPx([0,10,0])], > [GPx([-3,0,0]),GPx([10,0,0])]},color=black), > plot([GPx([-1111,1111,0]),GPx([1011,1111,0])]),plot([[0,0]],style=poin > t,symbol=circle)], scaling=constrained,title=`Perspective Projection > in Eye to Center direction`,axes=none,view=[-01.1..1.1,-0.7..0.7]); nn := 12 # Construction of vanishing points. > d:=array(1..10): e:=array(1..10): convert(e,list): > for ii from 1 to 10 do; > theta:=(ii+6)/17.45;d[ii]:=map(rogue,bob);e[ii]:= > [[[-2,-1],[5,-1]],[[-tan(theta),-1],[0,-2],[cot(theta),-1]],[(sin(s)+c > os(2.0*theta))/sin(2.0*theta),-1-cos(s)/sin(2.0*theta),s=-Pi/2..Pi/2]] > ;od: > leftwig:=t->[[0,0,0], [-1000.0*tan(t/2.0),1000.0,0], [1,0,0], > [2,0,0],[-1000.0*tan(t/2.0),1000.0,0],[3,0,0]]: > theta:=.5:leflin:=leftwig(theta): rightwig:=t->[[-1,0,0], > [1000.0*tan(Pi/4.0 - t/2.0),1000.0,0], [-2,0,0],[-3,0,0], > [1000.0*tan(Pi/4.0 - t/2.0),1000.0,0],[0,0,0]]: > riglin:=rightwig(theta): > > kproj:=[seq(map(GPx,d[j]),j=1..10)]: ovie:=[seq(plot( > [kproj[j],[GPx([-1111,1111,0]),GPx([1011,1111,0])], > op(e[j]),[GPx([0,0,-300]),GPx([0,0,2.2])], > [GPx([-4,0,0]),GPx([4,0,0])]],scaling=constrained,title=`Perspective > Projection in Eye to Center > direction`,axes=none,view=[-2..2,-3..1]),j=1..10)]: > display(ovie,scaling=constrained,insequence=true); # 3 x 3 x 1 box. > # > boe:=[[0,0,0],[0,0,1],[2,0,1],[2,0,0],[1,0,0],[1,0,1],[1000,0,1],[0,3, > 1],[0,3,0],[1000,0,0],[0,0,0],[0,2,0],[0,2,1],[0,1,1],[0,1,0],[0,1000, > 0],[3,0,0],[3,0,1],[0,1000,0],[0,0,1]]: > spacecurve(boe,view=[-1..10,-1..10,-1..2],scaling=constrained,axes=nor > mal); # Parallel projection of 3x3x1 box wiith measuring lines. > theta:=0.5:hlie:=map(rogue,boe):leflin: > nn:=nops(hlie); kpro:=map(GPp,hlie): kprm:=map(GPp,leflin): > kprr:=map(GPp,riglin):display([plot(kpro,color=`violet`), > plot(kprm,color=`blue`), plot(kprr,color=`green`), > plot({[GPp([0,0,-3]),GPp([0,0,10])],[GPp([0,-3,0]),GPp([0,10,0])],[GPp > ([-5,0,0]),GPp([10,0,0])]},color=gray),plot([[0,0]],style=point,symbol > =circle)], scaling=constrained,title=`Parallel Projection in Eye to > Center direction`,axes=none,view=[-11..11,-3..11]); nn := 20 # Perspective drawing with 3x3x1 bos with measuring lines. > nn:=nops(hlie); kpro:=map(GPx,hlie):kprm:=map(GPx,leflin): > kprr:=map(GPx,riglin): display([plot(kpro,color=`violet`), > plot(kprm,color=`blue`), plot(kprr,color=`green`), > plot({[GPx([0,0,-3]),GPx([0,0,10])], [GPx([0,-3,0]),GPx([0,10,0])], > [GPx([-5,0,0]),GPx([10,0,0])]},color=brown), > plot([GPx([-1111,1111,0]),GPx([1011,1111,0])]),plot([[0,0]],style=poin > t,symbol=circle)], scaling=constrained,title=`Perspective Projection > in Eye to Center direction`,axes=none,view=[-01.1..1.1,-0.7..0.7]); nn := 20 # Perspective drawing of 3x3x1 box with the construction of vanishing # points animation. > lef:=array(1..10):convert(lef,list):rig:=array(1..10):convert(rig,list > ): > for ii from 1 to 10 do; > theta:=(ii+6)/17.45;d[ii]:=map(rogue,boe);e[ii]:= > [[[-2,-1],[5,-1]],[[-tan(theta),-1],[0,-2],[cot(theta),-1]],[(sin(s)+c > os(2.0*theta))/sin(2.0*theta),-1-cos(s)/sin(2.0*theta),s=-Pi/2..Pi/2]] > ; od: > kproj:=[seq(map(GPx,d[j]),j=1..10)]: ovie:=[seq(plot( > [kproj[j],[GPx([-1111,1111,0]),GPx([1011,1111,0])], > op(e[j]),[GPx([0,0,-300]),GPx([0,0,2.2])], > [GPx([-4,0,0]),GPx([4,0,0])]],scaling=constrained,title=`Perspective > Projection in Eye to Center > direction`,axes=none,view=[-2..2,-3..1]),j=1..10)]: > display(ovie,scaling=constrained,insequence=true); # Perspective drawing of 3x3x1 box with the construction of vanishing # points and measuring points animation. # > for ii from 1 to 10 do; theta:=(ii+6)/17.45;d[ii]:=map(rogue,boe); > e[ii]:= > [[cos(s)*sec(theta)-tan(theta),-1-sec(theta)*sin(s),s=0..Pi/2-theta], > [cot(theta)-csc(theta)*cos(s),-1-csc(theta)*sin(s),s=0..theta], > [(sin(s)+cos(2.0*theta))/sin(2.0*theta),-1-cos(s)/sin(2.0*theta),s=-Pi > /2..Pi/2], [[-2,-1],[5,-1]], > [[-tan(theta),-1],[0,-2],[cot(theta),-1]], > [[cot(theta)-csc(theta),-1],[0,-2],[sec(theta)-tan(theta),-1]]]; > lef[ii]:=map(GPx,leftwig(theta)): > rig[ii]:=map(GPx,rightwig(theta));od: > kproj:=[seq(map(GPx,d[j]),j=1..10)]: ovie:=[seq(plot( > [kproj[j],[GPx([-1111,1111,0]),GPx([1011,1111,0])], > op(e[j]),rig[j],lef[j],[GPx([0,0,-300]),GPx([0,0,2.2])], > [GPx([-4,0,0]),GPx([4,0,0])]],scaling=constrained,title=`Constructing > Vanishing Points and Measuring > Points`,axes=none,v