teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

ソースコードを記載しました。

2019/01/13 11:16

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -7,4 +7,50 @@
7
7
  ### 試したこと
8
8
 
9
9
  boolean型の変数にprivateをつけ、外部から変更できないようにし、trueかfalseの判別はゲッターを用いて行った。
10
- また、イテレータではなく、拡張for文で行った。
10
+ また、イテレータではなく、拡張for文で行った。
11
+
12
+ ```java
13
+ class Figure3D{
14
+ static ArrayList<Point3D> list = new ArrayList<Point3D>();
15
+ static void prim(double r, double th, double phi, boolean draw){
16
+ double D2R = Math.PI/180.0;
17
+ double x, y, z;
18
+ x = r*Math.sin(th*D2R)*Math.sin(phi*D2R);
19
+ y = r*Math.cos(th*D2R);
20
+ z = r*Math.sin(th*D2R)*Math.cos(phi*D2R);
21
+ list.add(new Point3D(x, y, z, draw));
22
+ }
23
+ static void display(double alpha, double beta, int px, int py, Graphics g){
24
+ int _dx = 0, _dy = 0, dx = 0, dy = 0;
25
+ Point p2d;
26
+ int N = list.size();
27
+ int i = 0;
28
+ for(Point3D p: list){
29
+ p2d = p.get2D(alpha, beta, px, py);
30
+ dx = (int)p2d.getX();
31
+ dy = (int)p2d.getY();
32
+ if(i++ > 0){ //ここで、trueかfalseを判別し以下の動作を行いたい
33
+ g.setColor(Color.getHSBColor((float)i/N, 1.0f, 1.0f));
34
+ g.drawLine(_dx, _dy, dx, dy);
35
+ }
36
+ _dx = dx;
37
+ _dy = dy;
38
+ }
39
+ }
40
+ }
41
+
42
+ class Point3D{
43
+ private double x, y, z;
44
+ boolean d;
45
+ Point3D(double _x, double _y, double _z, boolean _d){
46
+ x = _x;
47
+ y = _y;
48
+ z = _z;
49
+ d = _d;
50
+ }
51
+ Point get2D(double alpha, double beta, int px, int py){
52
+
53
+ }
54
+ }
55
+
56
+ ```