1 / 13

CG プログラミング論

CG プログラミング論. 平成 26 年 5 月 19 日 森田 彦. グラフのy座標. (x 0 +100,y 0 -50). グラフのx座標. <コンピュータ上の座標>. (0,0). x軸. 50. 線分3. y軸. y 0. 50. 線分2. 50. 線分1. x 0. (x 0 ,y 0 ). 100. 50. 25. 基礎課題 4 - 1. void DrawGraphics(Graphics g) { int x0,y0,lx,ly; lx=200; //x 軸の長さ ly=180; //y 軸の長さ

henrik
Télécharger la présentation

CG プログラミング論

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CGプログラミング論 平成26年5月19日 森田 彦

  2. グラフのy座標 (x0+100,y0-50) グラフのx座標 <コンピュータ上の座標> (0,0) x軸 50 線分3 y軸 y0 50 線分2 50 線分1 x0 (x0,y0) 100 50 25 基礎課題4-1 void DrawGraphics(Graphics g) { int x0,y0,lx,ly; lx=200; //x軸の長さ ly=180; //y軸の長さ x0=10; //グラフの原点のx座標 y0=200; //グラフの原点のy座標 g.setColor(Color.black); //軸の描画色を黒色に指定 g.drawLine(x0,y0,x0+lx,y0); //x軸の描画 g.drawLine(x0,y0,x0,y0-ly); //y軸の描画 g.setColor(Color.blue); //グラフの描画色を青色に指定 g.drawLine(x0,y0,x0+100, y0-50 ) ; //線分1の描画 g.drawLine(x0+100,y0-50,x0+150, y0-100 ); //線分2の描画 g.drawLine(x0+150,y0-100,x0+175, y0-150 ); //線分3の描画 } ① y0-100 ② y0-150

  3. グラフのy座標 (x0+100,y0-50) グラフのx座標 <コンピュータ上の座標> (0,0) x軸 50 線分3 y軸 y0 50 線分2 50 線分1 x0 (x0,y0) 100 50 25 基礎課題4-2 void DrawGraphics(Graphics g) { int x0,y0,lx,ly,x1,y1,x2,y2; lx=200; //x軸の長さ ・・・ g.setColor(Color.blue); //グラフの描画色を青色に指定 //グラフの描画 int wx=100;//x軸方向の移動幅の設定 x1=0;//最初の始点のx座標の設定 y1=0;//最初の始点のy座標の設定 for(int i=1;i<=3;i++) { x2=x1+wx;//終点のx座標の設定 y2= y1+50 ;//終点のy座標の設定 g.drawLine(x0+x1,y0-y1,x0+x2,y0-y2); x1=x2;//次の始点のx座標の設定 y1=y2;//次の始点のy座標の設定 wx=wx/2; //次のx軸方向の移動幅の設定 } } ① y1+50

  4. 基礎課題4-3 y=x2 (0≦x≦10) ・・・ //グラフの描画 intwx=1; x1=0; y1=0; for(int i=1; i<=10 ;i++) { x2=i*wx; y2=x2*x2; g.drawLine(x0+20*x1,y0-2*y1,x0+20*x2,y0-2*y2); x1=x2; y1=y2; } ・・・ ① i<=10

  5. 基礎課題4-4 void DrawGraphics(Graphics g) { int x0,y0,lx,ly; double x1,y1,x2,y2;//一般的には座標値は実数型で表す lx=200; //x軸の長さ ・・・ //グラフの描画 doublewx=0.1;//x軸方向の刻み幅も一般には実数型変数で表す。 x1=0; y1=0; for(int i=1; i<=10 ;i++) { x2=i*wx; y2=x2*x2; g.drawLine( x0+(int)(100*x1),y0-(int)(100*y1), x0+(int)(100*x2),y0-(int)(100*y2) ); x1=x2; y1=y2; } } y=x2 (0≦x≦1) ① i<=10

  6. (0,0) (コンピュータ上の)x軸 (コンピュータ上の)y軸 (10,10) x軸 ly (x0,y0) y軸 lx 応用課題4-A void DrawGraphics(Graphics g) { int x0,y0,lx,ly; double x1,y1,x2,y2; lx=200; //x軸の長さ ly=200; //y軸の長さ x0=10+lx/2;//グラフの原点のx座標 y0=10+ly/2;//グラフの原点のy座標 g.setColor(Color.black); //軸の描画色を黒色に指定 g.drawLine(10,y0, 10+lx ,y0); //x軸の描画 g.drawLine(x0,10,x0,10+ly); //y軸の描画 g.setColor(Color.blue); //グラフの描画色を青色に指定 //グラフの描画 ① 10+lx ② 10+ly

  7. 応用課題4-A (その2) y=x3 (-3≦x≦3) //グラフの描画 double wx=0.1; int Cx=20,Cy=3; x1=-3; y1=x1*x1*x1; for(int i=1;i<=60;i++) { x2=i*wx-3; y2=x2*x2*x2; g.drawLine( x0+(int)(Cx*x1),y0-(int)(Cy*y1), x0+(int)(Cx*x2),y0-(int)(Cy*y2) ); x1=x2; y1=y2; } ③ -3

  8. 応用課題4-B y=sin(x) (-3.14≦x≦3.14) ・・・ //グラフの描画 int Cx=30,Cy=60; int Num=100; double wx=3.14*2/Num; x1=-3.14; y1=Math.sin(x1); for(int i=1;i<=Num;i++) { x2=i*wx-3.14; y2=Math.sin(x2); g.drawLine( x0+(int)(Cx*x1),y0-(int)(Cy*y1), x0+(int)(Cx*x2),y0-(int)(Cy*y2)); x1=x2; y1=y2; } ① Math.sin(x1) ② Math.sin(x2)

  9. 本日の学習内容 円の描画 5-1 三角関数の初歩 P(x,y) 半径rの円周上の点P(x,y) r y y θ x=r×cosθ x x y=r×sinθ cosθ=x/r, sinθ=y/r 三角関数の定義

  10. 30° 45° 1 2 45° 60° 1 1 基礎課題5-1 ① cos(60°)=1/2 sin(60°)= ② sin(30°)= ③ 1/2 cos(30°)= sin(45°)= cos(45°)= ④

  11. 基礎課題5-1 θ(ラジアン)=(θ(角度)/180)×π 45° →         (ラジアン) ⑤ π/4 60° →         (ラジアン) ⑥ π/3

  12. 本日の学習内容 円の描画 • 提出課題 【基礎課題5-1】~【基礎課題5-5】および【応用課題5-A】の6題です。

  13. 演習課題の受け取りについて • 原則として講義時間内に提出してもらいます。提出が遅れた場合は以下のように減点とします。 基礎課題 応用課題 課題内容によっては、上の基準を緩和します。その際は講義時にアナウンスします。

More Related