| 1 |
% plaintangency.mp |
| 2 |
% L. Nobre G. |
| 3 |
% IYP (2005) |
| 4 |
|
| 5 |
%input mp-tool; |
| 6 |
|
| 7 |
def paircrossprod(expr A, B) = |
| 8 |
( (xpart A)*(ypart B) - (xpart B)*(ypart A) ) |
| 9 |
enddef; |
| 10 |
|
| 11 |
def firsttangencypoint( expr Path, Point, ResolvN ) = |
| 12 |
begingroup |
| 13 |
save auxp, i, cutp, va, vb; |
| 14 |
path auxp; |
| 15 |
numeric i; |
| 16 |
pair cutp, va, vb; |
| 17 |
auxp = |
| 18 |
hide( va := unitvector( point 0 of Path - Point ); |
| 19 |
vb := unitvector( direction 0 of Path ); ) |
| 20 |
( paircrossprod( va, vb ), 0 ) |
| 21 |
for i=1/ResolvN step 1/ResolvN until length Path: |
| 22 |
hide( va := unitvector( point i of Path - Point ); |
| 23 |
vb := unitvector( direction i of Path ); ) |
| 24 |
...( paircrossprod( va, vb ), i ) |
| 25 |
endfor; |
| 26 |
cutp = auxp intersectionpoint ( origin--( 0, length Path ) ); |
| 27 |
( point ( ypart cutp ) of Path ) |
| 28 |
endgroup |
| 29 |
enddef; |
| 30 |
|
| 31 |
beginfig(0); |
| 32 |
numeric u, i; |
| 33 |
u = 5mm; |
| 34 |
pen a, b, c; |
| 35 |
a = pencircle scaled 3pt; |
| 36 |
b = pencircle scaled 5pt; |
| 37 |
c = pencircle scaled 1pt; |
| 38 |
z1 = (1u,1u); |
| 39 |
z2 = (4u,4u); |
| 40 |
z3 = (4u,5u); |
| 41 |
z4 = (3u,5u); |
| 42 |
z5 = (3u,6u); |
| 43 |
z6 = (4u,7u); |
| 44 |
z7 = (6u,1u); |
| 45 |
path cp; |
| 46 |
cp = z1{up}..z2..z3..z4..z5..{up}z6; |
| 47 |
draw cp withpen c; |
| 48 |
for i=1 upto 6: |
| 49 |
draw z[i] withpen a withcolor 0.5*(red+green); |
| 50 |
endfor; |
| 51 |
z8 = firsttangencypoint( cp, z7, 5 ); |
| 52 |
draw z7 withpen b withcolor green; |
| 53 |
draw z7--z8 withpen c withcolor blue; |
| 54 |
endfig; |
| 55 |
|
| 56 |
beginfig(1); |
| 57 |
numeric u; |
| 58 |
u = 5mm; |
| 59 |
pen a, b, c; |
| 60 |
path auxp; |
| 61 |
numeric i, auxn, yfact, sinfact, res; |
| 62 |
pair cutp, vA, vB; |
| 63 |
yfact = 30; |
| 64 |
sinfact = 40; |
| 65 |
res = 15; |
| 66 |
a = pencircle scaled 3pt; |
| 67 |
b = pencircle scaled 5pt; |
| 68 |
c = pencircle scaled 1pt; |
| 69 |
z1 = (1u,1u); |
| 70 |
z2 = (4u,4u); |
| 71 |
z3 = (4u,5u); |
| 72 |
z4 = (3u,5u); |
| 73 |
z5 = (3u,6u); |
| 74 |
z6 = (4u,7u); |
| 75 |
z7 = (6u,2.8u); |
| 76 |
path cp; |
| 77 |
cp = z1{up}..z2..z3..z4..z5..{up}z6; |
| 78 |
draw z7 withpen b withcolor green; |
| 79 |
draw cp withpen a; |
| 80 |
auxp = hide( vA := unitvector(point 0 of cp - z7); |
| 81 |
vB := unitvector(direction 0 of cp); ) |
| 82 |
( sinfact*((xpart vA)*(ypart vB) - (xpart vB)*(ypart vA)), 0 ) |
| 83 |
for i=1/res step 1/res until length cp: |
| 84 |
hide( vA := unitvector(point i of cp - z7); |
| 85 |
vB := unitvector(direction i of cp); ) |
| 86 |
...(sinfact*((xpart vA)*(ypart vB)-(xpart vB)*(ypart vA)),i*yfact) |
| 87 |
endfor; |
| 88 |
draw auxp withcolor blue+green; |
| 89 |
draw origin--(sinfact,0) withcolor red; |
| 90 |
draw origin--( 0, yfact*length cp ) withcolor red+green; |
| 91 |
cutp = auxp intersectionpoint ( origin--( 0, yfact*length cp ) ); |
| 92 |
draw cutp withpen a; |
| 93 |
auxn = ( ypart cutp )/yfact; |
| 94 |
show auxn; |
| 95 |
z8 = point auxn of cp; |
| 96 |
draw z8 withpen b withcolor green; |
| 97 |
draw z7--1.8[z7,z8] withpen c withcolor blue; |
| 98 |
endfig; |
| 99 |
|
| 100 |
end. |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|