================ BEZIER1 ================ Mapleを用いた実習を行います. Mapleを起動してください. 適当にプログラムの中の数字などを変更して試してみてください. 以下の説明の中で*****ではさまれた部分は Mapleに入力する文字列です.自分で入力あるいはコピーし Enter(Return) キーで実行します. 上から順に,すべて実行するようにしてください. 上で定義した関数を後で利用すること があります. 関数のグラフを描くにはパッケージ plots と plottools を用います. ****** with(plots): with(plottools): ****** ベジエ曲線を描くには、plotを用います. これは、y=f(x)の形になるもの以外も描く必要があるためです. plotを用いて放物線を描いてみましょう. ****** plot([-1 + 2*t, (-1 + 2*t)^2, t=0..1]); ****** 縦と横の比を1対1にするには,1:1のボタンを押すか, PlotメニュのScaling Constrainedを選んで下さい. plotを用いて円(の一部)を描いてみましょう. ****** plot([(1-t^2)/(1+t^2), (2*t)/(1+t^2), t=0..1]); ****** 平面上にベジエ曲線を描くための準備として、まず次を入力してください. ***** lerp := proc(p,q,r,s,t) local R; R:= (s - t)/(s - r)*p + (t - r)/(s - r)*q; end: ***** ***** badecas:=proc(L,r,s) local i, b; b:=L; for i from 1 to nops(L)-1 do b:=seq( lerp(b[j], b[j+1], r,s,t), j=1..nops(L)-i); od; b; end: ***** 次の項目を入力したとき,選択 function definition remmber table assignment が出たときは,maple11では remmber table assignmentを選ぶ. ***** decas:=proc(L,r,s) local i,j, b, cc,c; b:=L; for i from 1 to nops(L)-1 do b:=seq( lerp(b[j], b[j+1], r,s,t), j=1..nops(L)-i); cc(i):=b; od; c:=seq([cc(i)],i=1..nops(L)-1); end: ***** では、放物線の例から始めましょう. ***** cpoly:=[[-1, 1], [0, -1], [1, 1]]; bezier:=badecas(cpoly,0,1): plot([bezier[1],bezier[2], t=0..1],color=blue, thickness=2); ***** 少し曲線をのばしてみましょう. ***** plot([bezier[1],bezier[2], t=-1..2],color=blue, thickness=2); ***** ***** cpoly:=[[-1, 0], [0, 2], [1, 0]]; bezier:=badecas(cpoly,0,1): plot([bezier[1],bezier[2], t=0..1],color=blue, thickness=2); ***** ***** cpoly:=[[1, 0], [1, 1], [0, 1]]; bezier:=badecas(cpoly,0,1): plot([bezier[1],bezier[2], t=0..1],color=blue, thickness=2); ***** ***** cpoly:=[[0, -1], [2, 0], [0, 1]]; bezier:=badecas(cpoly,0,1): AA:=plot(cpoly, color=black, thickness=2): display(AA, plot([bezier[1],bezier[2], t=0..1],color=blue, thickness=2)); ***** ド・カステリョのアルゴリズムと関係をみましょう. ***** cpoly:=[[-1, 1], [0, -1], [1, 1]]; bezier:=badecas(cpoly,0,1): ppoint:=k->pointplot(eval(bezier, t=k/64) , color=black, thickness=2): BB:=decas(cpoly, 0,1): frame:=k-> seq(plot(eval(BB[i],t=k/64), thickness=2), i=1..nops(cpoly)-1): AA:=plot(cpoly, color=black, thickness=2): frame(0):=AA: p:=NULL: for k from 0 to 64 do p:=p, display(AA,frame(k), ppoint(k), plot([bezier[1],bezier[2], t=0..1],color=blue, thickness=2) ): end do: display(p,insequence=true, axes=none); ***** ***** cpoly:=[[1, 0], [1, 1], [0, 1]]; bezier:=badecas(cpoly,0,1): ppoint:=k->pointplot(eval(bezier, t=k/64) , color=black, thickness=2): BB:=decas(cpoly, 0,1): frame:=k-> seq(plot(eval(BB[i],t=k/64), thickness=2), i=1..nops(cpoly)-1): AA:=plot(cpoly, color=black, thickness=2): frame(0):=AA: p:=NULL: for k from 0 to 64 do p:=p, display(AA,frame(k), ppoint(k), plot([bezier[1],bezier[2], t=0..1],color=blue, thickness=2) ): end do: display(p,insequence=true, axes=none); ***** 3次曲線を考えましょう. ***** cpoly:=[[3,2], [-1, -3], [-1, 3], [3,-2]]; bezier:=badecas(cpoly,0,1): ppoint:=k->pointplot(eval(bezier, t=k/64) , color=black, thickness=2): BB:=decas(cpoly, 0,1): frame:=k-> seq(plot(eval(BB[i],t=k/64), thickness=2), i=1..nops(cpoly)-1): AA:=plot(cpoly, color=black, thickness=2): frame(0):=AA: p:=NULL: for k from 0 to 64 do p:=p, display(AA,frame(k), ppoint(k), plot([bezier[1],bezier[2], t=0..1],color=blue, thickness=2) ): end do: display(p,insequence=true, axes=none); ***** つぎ場合と比較してみましょう. ***** cpoly:=[[3,2], [-1, -2], [-1,2], [3,-2]]; ***** ***** cpoly:=[[3,2], [-1, -1], [-1, 1], [3,-2]]; ***** 高次のベジエ曲線の場合を考えましょう. ***** cpoly:=[[-1,0], [-1,2], [2,3], [4,1], [3, -1]]; ***** ***** cpoly:=[[0,0],[-3,0],[-3,1],[-1,1], [-1,3], [-3,3]]; ***** ***** cpoly:=[[-1, 0], [1, 2], [-1, 2], [0, 3], [1, 2], [1, 0], [-1, 2], [-1, 0]]; ***** ***** bezier1:=proc(L, r,s) local n, b, bb, k; n:=nops(L)-1; b:= [sum(n!/(k!*(n-k)!)*(u^k)*((1-u)^(n-k))*L[k+1][1], k=0..n), sum(n!/(k!*(n-k)!)*(u^k)*((1-u)^(n-k))*L[k+1][2],k=0..n)]: bb:=plot([b[1], b[2], u=r..s], color=blue, thickness=2); end: ***** ***** cpoly:=[[2652/15625, 200512416/244140625], [-106132/234375, -9917022752/3662109375], [-1342484/1640625, -19394337248/25634765625], [-528372/546875, 1869010208/1220703125], [-219388/234375, 8206418272/3662109375], [-251836/328125, 11238002464/8056640625], [-273468/546875, -317292768/3759765625], [-40612/234375, -9268160096/8056640625], [40612/234375, -9268160096/8056640625], [273468/546875, -317292768/3759765625], [251836/328125, 11238002464/8056640625], [219388/234375, 8206418272/3662109375], [528372/546875, 1869010208/1220703125], [1342484/1640625, -19394337248/25634765625], [106132/234375, -9917022752/3662109375], [-2652/15625, 200512416/244140625]]; ***** ***** bezier1(cpoly, 0, 1); ***** ***** AA:=plot(cpoly, color=black, thickness=2): p:=NULL: for j from 1 to 128 do p:=p, display(AA, bezier1(cpoly, 0, j/128) ): end do: display(p,insequence=true, axes=none); ***** いろいろなベジエ点を与えて,ベジエ曲線を作って見ましょう. 何かおもしろそうなものができたら、教えて下さい.