> |
Qdim := proc(P1, P2, {Q:=[ ]},
{corp::{"cart","proj"}:="cart"},#cartesian or projective
{shift::float:=0.5},
{vec::list:=[]},
{scale::{list,integer}:=1},
{leader::{-1,0,1}:= 1},
{dimoffset::{1/6,1/5,1/4,3/4,2/3,1/2,1/3,1,3/2,2,3,4,5,6}:=1},
{point::list:=['color' = ':-blue', symbol = ':-solidcircle', 'symbolsize' = 12]},
{line::list:=['thickness'=3]},
{plopts::list:=[]})
description " plots Quadrance symbol and value (Q)";
uses pl=plots, pt=plottools ;#, RationalTrigonometry;
local a,f,g,h,v1,delta,mp, BoxQ,Qsymbol,ldr,pt1,pt2,pt3,pt4,Scl,xpsn,ypsn,zpsn,
ptxtp1,ptxtp2,txtplt1,txtplt2,plttyp,thk,l12,pts12,perp::boolean:=false,qshift,vshift;
global Projective_Z_Position;
if Projective_Z_Position=1 then
xpsn:=2;
ypsn:=3;
zpsn:=1;
else
xpsn:=1;
ypsn:=2;
zpsn:=3;
end if;
if P1::{list} and P1[1]::{list,'Vector[row]'(3)} then
if P1[1]::'Vector[row]'(3) then
pt1:=[P1[1][xpsn]/P1[1][zpsn],P1[1][ypsn]/P1[1][zpsn]];#print(pt1);
elif P1[1]::list then
pt1:=P1[1];
end if;
plttyp:=`if`(nops(pt1)=3,3,2); # print(pt1,plttyp);
ptxtp1:=[op(pt1),op(P1[2..-1])];
txtplt1:=true;
else
if P1::'Vector[row]'(3) then
pt1:=[P1[xpsn]/P1[zpsn],P1[ypsn]/P1[zpsn]];
else
pt1:=P1;
end if;
plttyp:=nops(pt1);
txtplt1:=false;
end if;
if P2::{list} and P2[1]::{list,'Vector[row]'(3)} then
if P2[1]::'Vector[row]'(3) then
pt2:=[P2[1][xpsn]/P2[1][zpsn],P2[1][ypsn]/P2[1][zpsn]];
elif P2[1]::list then
pt2:=P2[1];
end if;
plttyp:=`if`(nops(pt2)=3,3,2); # print(pt2,plttyp);
ptxtp2:=[op(pt2),op(P2[2..-1])];
txtplt2:=true;
else
if P2::'Vector[row]'(3)then
pt2:=[P2[xpsn]/P2[zpsn],P2[ypsn]/P2[zpsn]];
else
pt2:=P2;
end if;
plttyp:=nops(pt2);
txtplt2:=false;
end if;
#print(Projective_Z_Position,xpsn,ypsn,zpsn);
if type(scale,'numeric') then
Scl:=scale;
else
if scale[1]::Vector[row](3) then
pt3:= [scale[1][xpsn]/scale[1][zpsn],scale[1][ypsn]/scale[1][zpsn]];
else
pt3:=scale[1];
end if;
if scale[2]::Vector[row](3) then
pt4:= [scale[2][xpsn]/scale[2][zpsn],scale[2][ypsn]/scale[2][zpsn]];
else
pt4:=scale[2];
end if;
if plttyp = 2 then
Scl:=evalf(sqrt(((pt3[1]-pt4[1])^2+(pt3[2]-pt4[2])^2)/((pt1[1]-pt2[1])^2+(pt1[2]-pt2[2])^2)));#:-print(Scl);
else
Scl:=evalf(sqrt(((pt3[1]-pt4[1])^2+(pt3[2]-pt4[2])^2)/((pt1[1]-pt2[1])^2+(pt1[2]-pt2[2])^2)));#:-print(Scl);
end if;
end if;
#print(Scl,pt1,pt2,pt3,pt4);
if plttyp =2 then
a :=Scl* dimoffset*0.1*leader*[-pt2[2]+pt1[2], pt2[1]-pt1[1]]; #dimension leader 2d lines
else
a :=Scl* dimoffset*0.1*leader*[-pt2[2]+pt1[2], pt2[1]-pt1[1],pt2[3]-pt1[3]]; #dimension leader 3d lines
end if;
delta:=Scl*(pt2-pt1);
if Q<>[] and eval(':-shift',Q[2..-1])::float then
qshift := eval(':-shift',Q[2..-1]);
else
qshift := shift;
end if;
print("qshift=",qshift);
if vec<>[] and eval(':-shift',vec[2..-1])::float then
vshift := eval(':-shift',vec[2..-1]);
else
vshift := shift;
end if;
print("vshift=",vshift);
mp:=(1-qshift)*pt1+qshift*pt2; #midpoint of line
#:-print(Scl,a,delta,mp);
if plttyp = 2 then
#coorfinates of the sqnbol corners
BoxQ:=[[a[1]+mp[1]+.05*delta[1]-.01*delta[2],a[2]+mp[2]+.05*delta[2]+.01*delta[1]],
[a[1]+mp[1]-.05*delta[1]-.01*delta[2],a[2]+mp[2]-.05*delta[2]+.01*delta[1]],
[a[1]+mp[1]-.05*delta[1]+.01*delta[2],a[2]+mp[2]-.05*delta[2]-.01*delta[1]],
[a[1]+mp[1]+.05*delta[1]+.01*delta[2],a[2]+mp[2]+.05*delta[2]-.01*delta[1]]];
else #3D
BoxQ:=[[a[1]+mp[1]+.05*delta[1]-.01*delta[2],a[2]+mp[2]+.05*delta[2]+.05*delta[1],a[3]+mp[3]+.05*delta[3]],
[a[1]+mp[1]-.05*delta[1]-.01*delta[2],a[2]+mp[2]-.05*delta[2]+.05*delta[1],a[3]+mp[3]-.05*delta[3]],
[a[1]+mp[1]-.05*delta[1]+.01*delta[2],a[2]+mp[2]-.05*delta[2]-.05*delta[1],a[3]+mp[3]-.05*delta[3]],
[a[1]+mp[1]+.05*delta[1]+.01*delta[2],a[2]+mp[2]+.05*delta[2]-.05*delta[1],a[3]+mp[3]+.05*delta[3]]];
end if;
if leader<>0 then
thk:='thickness'=0
elif line<>[] then
thk:=line[op(ListTools:-Search(op(select(has,line,'thickness')),line))];
else
thk:='thickness'=0;
end if;
if corp="cart" then
Qsymbol:=[pt:-line(pt1,pt1+1.05*a,'thickness'=0,plopts[]),
pt:-line(pt1+a,mp-.05*delta+a,thk,plopts[]),
pt:-line(op([BoxQ[1],BoxQ[2]]),'thickness'=0,plopts[]),
pt:-line(op([BoxQ[2],BoxQ[3]]),'thickness'=0,plopts[]),
pt:-line(op([BoxQ[3],BoxQ[4]]),'thickness'=0,plopts[]),
pt:-line(op([BoxQ[4],BoxQ[1]]),'thickness'=0,plopts[]),
pt:-line(pt2+a,mp+.05*delta+a,thk,plopts[]),
pt:-line(pt2,pt2+1.05*a,'thickness'=0,plopts[])];
elif (Q[1])=1 or Q[1]::specfunc(typeset) and ormap(is, [op(Q[1])], 1) and corp="proj" then
if leader=0 or leader=1 then ldr:=1 else ldr:=-1 end if;
Qsymbol:=[pt:-line(mp-.05*delta*dimoffset,mp+ldr*.05*[-delta[2],delta[1]]*dimoffset,thk,plopts[]),
pt:-line(mp+ldr*.05*[-delta[2],delta[1]]*dimoffset,mp+.05*delta*dimoffset,thk,plopts[])];
perp:=true;
else
Qsymbol:=[pt:-line(pt1,pt1+1.05*a,'thickness'=0,plopts[]),
pt:-line(pt1+a,mp-.05*delta+a,thk,plopts[]),
pt:-line(op([BoxQ[1],BoxQ[2]]),'thickness'=0,plopts[]),
pt:-line(op([BoxQ[2],BoxQ[3]]),'thickness'=0,plopts[]),
pt:-line(op([BoxQ[3],BoxQ[4]]),'thickness'=0,plopts[]),
pt:-line(op([BoxQ[4],BoxQ[1]]),'thickness'=0,plopts[]),
pt:-line(pt2+a,mp+.05*delta+a,thk,plopts[]),
pt:-line(pt2,pt2+1.05*a,'thickness'=0,plopts[])];
end if;
if point<>[]then
pts12:=pt:-point([pt1,pt2],point[]); #end points
else
pts12:=NULL;
end if;
if line<>[] then
l12:=pt:-line(pt1,pt2,line[]);
else
l12:=NULL;
end if;
if plttyp = 2 then
if perp=false then
f := pl:-textplot([op(((1-qshift)*pt1+qshift*pt2)+1*(a)),op(Q)]); #Quadrance text
else
f:=NULL; #dont plot value with perp symbol
end if;
if txtplt1 then
g := pl:-textplot( ptxtp1);
else
g:=NULL;
end if;
if txtplt2 then
h := pl:-textplot( ptxtp2);
else
h:= NULL;
end if;
if vec <> [] then
v1:=pl:-textplot([op(((1-vshift)*pt1+vshift*pt2)), op(vec)]);#`#mover(mi("v"),mo("⇀"))`[1,2] {':-below',':-right'}
else
v1:=NULL;
end if;
else
if perp=false then
f := pl:-textplot3d([op(((1-qshift)*pt1+qshift*pt2)+1*(a)),op(Q)]);
else
f:=NULL; #dont plot value with perp symbol
end if;
if txtplt1 then
g := pl:-textplot3d( ptxtp1);
else
g:=NULL;
end if;
if txtplt2 then
h := pl:-textplot3d( ptxtp2);
else
h:=NULL;
end if;
if vec <> [] then
v1:=pl:-textplot3d([op(((1-vshift)*pt1+vshift*pt2)),op(vec)]);#`#mover(mi("v"),mo("⇀"))`[1,2] {':-below',':-right'}
else
v1:=NULL;
end if;
end if;
#:-print("pltyp" , plttyp) ;
if leader = 0 then
pl:-display(pts12,f,g,h,v1,Qsymbol,'axes'=':-none','scaling'=':-constrained');
else
pl:-display(pts12,l12,f,g,h,v1,Qsymbol,'axes'=':-none','scaling'=':-constrained');
end if;
end proc:
|
Procedure Qdim( P1, P2, { Q := [], corp::{"cart", "proj"} := "cart",
dimoffset::{1, 2, 3, 4, 5, 6, 1/2, 1/3, 1/4, 1/5, 1/6, 2/3, 3/2, 3/4} :=
1, leader::{-1, 0, 1} := 1, line::list := ['thickness' = 3], plopts::list
:= [], point::list := ['color' = ':-blue', symbol = ':-solidcircle',
'symbolsize'
= 12], scale::{integer, list} := 1, shift::float := .5,
vec::list := [] } )
These names were used as global names but were not declared: typeset
|
|
> |
Projective_Z_Position:=3:
|
> |
pp1:=<1|3|2>:pp2:=<2|3/2|1/2>:#projective points
|
> |
#default value of shift=0.5
Qdim([pp1,typeset("P1 ",pp1),align={below, right},color=magenta],pp2,dimoffset=3,Q=[typeset("Q=",3),align=[below,right]],vec=[(\n`#mover(mi("v"),mo("⇀"))`[1,2]),align={above,left},font=["century",14]],plopts=[color=blue])
|
> |
#shift =0.8
Qdim([pp1,typeset("P1 ",pp1),align=[below,right],color=magenta],pp2,dimoffset=3,Q=[typeset("Q=",3),align=[below,right]],vec=[(\n`#mover(mi("v"),mo("⇀"))`[1,2]),align={above,left},font=["century",14]],shift=0.8,plopts=[color=blue])
|
> |
#individual shift values for Q and vec override main shift value
Qdim([P5,typeset("P5 ",P5),align=[below,right],color=magenta],[P6,typeset("P6 ",P6),color="Green",align=right],dimoffset=3,Q=[typeset("Q=",20),colour=blue,align=[below,right],shift=0.35],vec=[(\n`#mover(mi("v"),mo("⇀"))`[5,6]),align={above,left},font=["century",14]],shift=0.8,plopts=[color=indigo],line=[thickness=2,linestyle=dash])
|
> |
P1:=[4,5]:P2:=[-1,3]:P3:=[2,-5/2]:
P4:=(1-3/10)*P1+3/10*P2:
P5:=(1-6/10)*P1+6/10*P2:
|
> |
# Stacking dimensions by using scale, leader and dimoffset. Plus use of colour.
plt7:=Qdim([P1,typeset(" P1=",P1),align=[right],colour=red],[P2,typeset("P2=",P2," "),align=[left,above]] ,Q=[typeset("Q12=",29),align =[above,left]] ,leader=-1,dimoffset=5, point=[symbolsize=12,symbol=solidcircle,colour=blue]):
plt8:=Qdim(P1,[P4,typeset("P4=",P4," "),align=[left,above]] ,Q=[typeset("Q14=",261/100),align =[above,left]] ,scale=[P1,P2],leader=-1,dimoffset=1, point=[symbolsize=12,symbol=solidcircle,colour=blue]):
plt9:=Qdim(P1,[P5,typeset("P5=",P5," "),align=[below,right] ] ,Q=[typeset("Q15=",261/25),align =[above,left]] ,scale=[P1,P2],dimoffset=3,leader=-1,point=[symbolsize=12,symbol=solidcircle,colour=blue],plopts=[colour=blue]):
plots:-display(plt7,plt8,plt9)
|
> |
# Form a triangle. More use of colour and leader=0.
plt10:=Qdim(P1,[P3,typeset("P3=",P3),align=[right,below]],leader=0,Q=[typeset(" Q13=",241/4),align =[right]],plopts=[colour=purple]):
plt11:=Qdim(P2,P3,Q=[typeset("Q23=",157/4," "),align =[left]],leader=-1,point=[symbolsize=12,symbol=solidcircle,colour=blue],line=[colour="Green",thickness=2],plopts=[colour=purple]):
plots:-display(plt7,plt8,plt9,plt10,plt11,size=[750,750])
|
> |
# A diagram with default dimension formats.
plt1:=Qdim([P1,typeset(" P1=",P1),align=[right],colour=red],[P2,typeset("P2=",P2),align=[left,above]] ,Q=[typeset("Q12=",29),align =[below,right]] , point=[symbolsize=12,symbol=solidcircle,colour=blue]):
plt2:=Qdim(P1,[P4,typeset("P4=",P4),align=[left,above]] ,Q=[typeset("Q14=",261/100),align =[below,right]] , point=[symbolsize=12,symbol=solidcircle,colour=blue]):
plt3:=Qdim(P2,P4 ,Q=[typeset("Q24=",1421/100," "),align =[below,right]] , point=[]):
plots:-display(plt1,plt2,plt3,size=[600,600])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
> |
# Using scale, leader and dimoffset to create a clearer diagram.
plt4:=Qdim([P1,typeset("P1=",P1),align=[right],colour=red],[P2,typeset("P2=",P2),align=[left,above]] ,Q=[typeset("Q12=",Q29),align =[below,right]] , point=[symbolsize=12,symbol=solidcircle,colour=blue]):
plt5:=Qdim(P1,[P4,typeset("P4=",P4," "),align=[left,above]] ,Q=[typeset("Q14=",261/100),align =[above,left]] ,scale=[P1,P2],leader=-1,dimoffset=2, point=[symbolsize=12,symbol=solidcircle,colour=blue]):
plt6:=Qdim(P2,P4 ,Q=[typeset("Q24=",1421/100),align =[above,left]] ,scale=[P1,P2],dimoffset=2, point=[]):
plots:-display(plt4,plt5,plt6)
|
|