| 1 |
% torusexperiment.mp |
| 2 |
% L. Nobre G. |
| 3 |
% 2014 |
| 4 |
|
| 5 |
% DO NOT CHANGE PARAMETERS. YOU HAVE BEEN WARNED! |
| 6 |
|
| 7 |
prologues := 1; |
| 8 |
input featpost3Dplus2D; |
| 9 |
%SphericalDistortion := true; |
| 10 |
%ParallelProj := true; |
| 11 |
beginfig(1); |
| 12 |
Spread:=70; |
| 13 |
numeric bigray, smaray, angstep; |
| 14 |
color toruscenter, torusmoment, nearaxe, sideaxe, viewline; |
| 15 |
color circlecenter, circlemoment; |
| 16 |
numeric ang, ind, i, anglim; |
| 17 |
path cpath, apath, opath, ipath, wp, ep; |
| 18 |
pair outerp[], innerp[], refpair; |
| 19 |
pen markpen; |
| 20 |
boolean cuspcond; |
| 21 |
picture holepic; |
| 22 |
color hvec, fakef, visualcircenter, hvecf, perpvec, axisvec; |
| 23 |
numeric rratio, hratio, visualray, resultang; |
| 24 |
numeric fakedist, fakeangle, fakeviewlimitangle, tmpangle; |
| 25 |
markpen = pencircle scaled 5pt; |
| 26 |
pickup markpen; |
| 27 |
bigray = 5; |
| 28 |
smaray = 1; |
| 29 |
%message "Villarceau angle: " & decimal(angle(bigray+-+smaray,smaray)); |
| 30 |
message "Actual view angle: " & decimal(angle(X(f)++Y(f),Z(f))); |
| 31 |
angstep= 0.5; |
| 32 |
toruscenter = black; |
| 33 |
torusmoment = (0,0,1); |
| 34 |
% f := (3,-6,3); |
| 35 |
%%%%%%%%%%%%%%%%%%%%%%%%%%% f := 3*(0,4.24706,0.67267); fakedist = 7.3; |
| 36 |
f := (7,4,2); fakedist = 4.3; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 37 |
fakeangle = 9; |
| 38 |
fakeviewlimitangle = 2; |
| 39 |
% fakef = (0,4,3); |
| 40 |
% fakef = f; |
| 41 |
% fakef = (-Y(f),X(f),Z(f)); |
| 42 |
fakef = (0,fakedist*cosd(fakeangle),fakedist*sind(fakeangle)); |
| 43 |
%show fakef; |
| 44 |
%endfig; |
| 45 |
%end. |
| 46 |
if cdotprod(f-viewcentr,torusmoment)<0 : |
| 47 |
torusmoment := -torusmoment; |
| 48 |
fi; |
| 49 |
refpair = unitvector( rp(toruscenter+torusmoment)-rp(toruscenter) ); |
| 50 |
viewline = f-toruscenter; |
| 51 |
ind = 0; |
| 52 |
sideaxe = bigray*ncrossprod( torusmoment, viewline ); |
| 53 |
nearaxe = bigray*ncrossprod( sideaxe, torusmoment ); |
| 54 |
anglim = 0.5*angstep-180; |
| 55 |
hvec = cdotprod(f-toruscenter,N(torusmoment))*N(torusmoment); |
| 56 |
hratio = conorm(hvec)/bigray; |
| 57 |
rratio = conorm(f-toruscenter-hvec)/bigray; |
| 58 |
for ang=anglim step angstep until -anglim: |
| 59 |
ind := incr( ind ); |
| 60 |
circlecenter:= nearaxe*cosd(ang)+sideaxe*sind(ang); |
| 61 |
circlemoment:=-nearaxe*sind(ang)+sideaxe*cosd(ang); |
| 62 |
cpath:=spatialhalfcircle(circlecenter,circlemoment,smaray,true); |
| 63 |
if ang>=0: |
| 64 |
outerp[ind]=point 0 of cpath; |
| 65 |
innerp[ind]=point (length cpath) of cpath; |
| 66 |
elseif ang<0: |
| 67 |
innerp[ind]=point 0 of cpath; |
| 68 |
outerp[ind]=point (length cpath) of cpath; |
| 69 |
fi; |
| 70 |
endfor; |
| 71 |
opath = for i=1 upto ind: outerp[i].. endfor cycle; |
| 72 |
ipath = for i=1 upto ind: innerp[i].. endfor cycle; |
| 73 |
holepic = currentpicture; |
| 74 |
clip holepic to ipath; |
| 75 |
unfill opath; |
| 76 |
draw holepic; |
| 77 |
draw ipath withcolor red; |
| 78 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 79 |
% There is an analytic way of getting the angle of the cusp point! % |
| 80 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 81 |
i := ceiling(1+180/angstep); |
| 82 |
forever: |
| 83 |
i := incr( i ); |
| 84 |
cuspcond := refpair dotprod innerp[i+1] < refpair dotprod innerp[i]; |
| 85 |
exitif cuspcond or ( i > ind-1 ); |
| 86 |
endfor; |
| 87 |
resultang = anglim+angstep*(i-1); |
| 88 |
write decimal(smaray/bigray) & " " & decimal(rratio) & " " & decimal(hratio) & " " & decimal(resultang) to "torusexperimentoneline.dat"; |
| 89 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 90 |
ep = outerp[ind-i]--innerp[ind-i]; |
| 91 |
wp = innerp[i]--outerp[i]; |
| 92 |
unfill buildcycle(opath,ep,reverse ipath,wp); |
| 93 |
draw opath withcolor green; |
| 94 |
draw subpath (i,ind-i) of ipath withcolor red; |
| 95 |
hvecf = cdotprod(fakef-toruscenter,N(torusmoment))*N(torusmoment); |
| 96 |
visualcircenter = 0.5[toruscenter+hvecf,fakef]; |
| 97 |
axisvec = fakef-visualcircenter; |
| 98 |
visualray = conorm( axisvec ); |
| 99 |
perpvec = ncrossprod(axisvec,torusmoment)*visualray; |
| 100 |
color tmpf, tmpc, tmpp[], tmpq[], tmpa, tmpv; |
| 101 |
numeric theta, alpha, beta; |
| 102 |
tmpv = N(torusmoment); |
| 103 |
i := 0; |
| 104 |
drawoptions( withcolor blue withpen pencircle scaled 5pt ); |
| 105 |
for theta=2*anglim step angstep until -2*anglim: |
| 106 |
tmpf := visualcircenter+planarrotation( axisvec, perpvec, theta ); |
| 107 |
tmpa := N( planarrotation( axisvec, perpvec, theta/2 ) ); |
| 108 |
tmpc := toruscenter+tmpa*bigray; |
| 109 |
beta := getangle(tmpa,tmpf-tmpc); |
| 110 |
alpha := angle( smaray, conorm( tmpf-tmpc ) +-+ smaray ); %%%%%%%%%%%% |
| 111 |
tmpp[i] := tmpc + smaray*planarrotation( -tmpa, tmpv, 180-alpha-beta ); |
| 112 |
tmpq[i] := tmpc + smaray*planarrotation( -tmpa, tmpv, 180+alpha-beta ); |
| 113 |
if i>0: |
| 114 |
tmpangle := getangle(tmpp[i]-tmpp[i-1],tmpp[i]-fakef); |
| 115 |
%write decimal(i) & " " & decimal(tmpangle) to "torusexperimentangles.dat"; |
| 116 |
if (tmpangle<fakeviewlimitangle) or (180-tmpangle<fakeviewlimitangle): |
| 117 |
draw rp(tmpp[i])--rp(fakef) withpen pencircle scaled 0pt; |
| 118 |
fi; |
| 119 |
fi; |
| 120 |
i := incr(i); |
| 121 |
endfor; |
| 122 |
draw rp(fakef); |
| 123 |
if smaray>bigray: |
| 124 |
draw rp(toruscenter+tmpv*(smaray+-+bigray)); |
| 125 |
draw rp(toruscenter-tmpv*(smaray+-+bigray)); |
| 126 |
fi; |
| 127 |
ind := i-1; |
| 128 |
drawoptions(); |
| 129 |
pickup pencircle scaled 0pt; |
| 130 |
draw rp(fakef)--rp((X(fakef),Y(fakef),0))--rp((0,bigray,0))--cycle dashed evenly; |
| 131 |
draw goodcirclepath((0,bigray,0),red,smaray) dashed evenly; |
| 132 |
draw for i=0 upto ind: rp(tmpp[i]).. endfor cycle; |
| 133 |
draw for i=0 upto ind: rp(tmpq[i]).. endfor cycle; |
| 134 |
pickup pencircle scaled 2pt; |
| 135 |
draw spatialhalfcircle( toruscenter, torusmoment, bigray+smaray, true ); |
| 136 |
%draw rigorouscircle( toruscenter, torusmoment, bigray-smaray ); |
| 137 |
draw rigorouscircle( toruscenter+smaray*tmpv, torusmoment, bigray ); |
| 138 |
%draw rigorouscircle( toruscenter-smaray*tmpv, torusmoment, bigray ); |
| 139 |
picture tmppicture; |
| 140 |
path zoomwindow; |
| 141 |
zoomwindow = (550,230)--(750,230)--(750,330)--(550,330)--cycle; |
| 142 |
tmppicture = currentpicture; |
| 143 |
clip tmppicture to zoomwindow; |
| 144 |
endfig; |
| 145 |
|
| 146 |
beginfig(2); |
| 147 |
draw tmppicture scaled 4; |
| 148 |
endfig; |
| 149 |
|
| 150 |
end. |
| 151 |
|
| 152 |
|