| 1 |
% simplecenterofmass.mp |
| 2 |
% L. Nobre G. |
| 3 |
% 2012 |
| 4 |
|
| 5 |
verbatimtex \documentclass{article}\begin{document} etex; |
| 6 |
|
| 7 |
beginfig(0); |
| 8 |
numeric u, i, j, s, as, bs, cs, ds; |
| 9 |
pen pena, penb, penc, pend; |
| 10 |
u = 1.5mm; |
| 11 |
s = 7.1u; |
| 12 |
as = 2u; |
| 13 |
bs = 3u; |
| 14 |
cs = 5u; |
| 15 |
ds = 0.8u; |
| 16 |
pena = pencircle scaled as; |
| 17 |
penb = pencircle scaled bs; |
| 18 |
penc = pencircle scaled cs; |
| 19 |
pend = pencircle scaled ds; |
| 20 |
linecap := squared; |
| 21 |
for i=1 upto 4: |
| 22 |
for j=1 upto 3: |
| 23 |
draw ((i-1)*s,(j-1)*s)-- |
| 24 |
((i-1)*s,j*s)-- |
| 25 |
(i*s,j*s)-- |
| 26 |
(i*s,(j-1)*s)--cycle withcolor 0.7white; |
| 27 |
endfor; |
| 28 |
endfor; |
| 29 |
z1 = (s,3s); |
| 30 |
z2 = (3s,3s); |
| 31 |
z3 = (4s,3s); |
| 32 |
z4 = (0,0); |
| 33 |
z5 = (1s,2s); |
| 34 |
z6 = (2s,2s); |
| 35 |
z7 = (3s,2s); |
| 36 |
z8 = (1s,1s); |
| 37 |
z9 = (2s,1s); |
| 38 |
linecap := rounded; |
| 39 |
pickup pena; |
| 40 |
draw z1; |
| 41 |
draw z2; |
| 42 |
pickup penb; |
| 43 |
draw z3; |
| 44 |
pickup penc; |
| 45 |
draw z4; |
| 46 |
pickup pend; |
| 47 |
for i=5 upto 9: |
| 48 |
draw z[i]; |
| 49 |
endfor; |
| 50 |
label.urt(btex 1 kg etex, z1); |
| 51 |
label.urt(btex 1 kg etex, z2); |
| 52 |
label.rt(btex 2 kg etex, z3+(bs/2,0)); |
| 53 |
label.urt(btex 8 kg etex, z4+(0,cs/2)); |
| 54 |
label.urt(btex A etex, z5); |
| 55 |
label.urt(btex B etex, z6); |
| 56 |
label.urt(btex C etex, z7); |
| 57 |
label.urt(btex D etex, z8); |
| 58 |
label.urt(btex E etex, z9); |
| 59 |
endfig; |
| 60 |
|
| 61 |
beginfig(1); |
| 62 |
numeric u, i, j, s, opt; |
| 63 |
pen pena, penb; |
| 64 |
pair PO[]; |
| 65 |
u = 1.5mm; |
| 66 |
s = 7.1u; |
| 67 |
pena = pencircle scaled 1.6u; |
| 68 |
penb = pencircle scaled 0.6u; |
| 69 |
linecap := squared; |
| 70 |
for i=1 upto 4: |
| 71 |
for j=1 upto 3: |
| 72 |
draw ((i-1)*s,(j-1)*s)-- |
| 73 |
((i-1)*s,j*s)-- |
| 74 |
(i*s,j*s)-- |
| 75 |
(i*s,(j-1)*s)--cycle withcolor 0.7white; |
| 76 |
endfor; |
| 77 |
endfor; |
| 78 |
z1 = (0,0); |
| 79 |
z2 = (4,3); |
| 80 |
z4 = (1,2); |
| 81 |
z5 = (2,2); |
| 82 |
z6 = (3,2); |
| 83 |
z7 = (1,1); |
| 84 |
z8 = (2,1); |
| 85 |
forever: |
| 86 |
opt := uniformdeviate(1); |
| 87 |
if opt<0.3333: |
| 88 |
PO3 := (1,3); |
| 89 |
elseif opt<0.6667: |
| 90 |
PO3 := (0,3); |
| 91 |
else: |
| 92 |
PO3 := (0,2); |
| 93 |
fi; |
| 94 |
opt := uniformdeviate(1); |
| 95 |
if opt<0.3333: |
| 96 |
PO9 := z4; |
| 97 |
elseif opt<0.6667: |
| 98 |
PO9 := z5; |
| 99 |
else: |
| 100 |
PO9 := z7; |
| 101 |
fi; |
| 102 |
numeric massadois, massatres; |
| 103 |
PO9 = massadois*(z2-PO9)+massatres*(PO3-PO9); |
| 104 |
exitif (massadois>0) and (massatres>0); |
| 105 |
endfor; |
| 106 |
linecap := rounded; |
| 107 |
z3 = PO3; |
| 108 |
for i=1 upto 3: |
| 109 |
draw z[i] scaled s withpen pena; |
| 110 |
endfor; |
| 111 |
for i=4 upto 8: |
| 112 |
draw z[i] scaled s withpen penb; |
| 113 |
endfor; |
| 114 |
label.urt(decimal(round(massatres*24)) & "kg", z3 scaled s); |
| 115 |
label.urt(decimal(round(massadois*24)) & "kg", z2 scaled s); |
| 116 |
label.urt("24kg", z1 scaled s); |
| 117 |
label.urt(btex A etex, z4 scaled s); |
| 118 |
label.urt(btex B etex, z5 scaled s); |
| 119 |
label.urt(btex C etex, z6 scaled s); |
| 120 |
label.urt(btex D etex, z7 scaled s); |
| 121 |
label.urt(btex E etex, z8 scaled s); |
| 122 |
draw fullcircle scaled 1.6u shifted (PO9 scaled s) withcolor red; |
| 123 |
endfig; |
| 124 |
|
| 125 |
verbatimtex \end{document} etex |
| 126 |
|
| 127 |
end; |