質問編集履歴

1

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

2019/01/13 11:16

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -17,3 +17,95 @@
17
17
  boolean型の変数にprivateをつけ、外部から変更できないようにし、trueかfalseの判別はゲッターを用いて行った。
18
18
 
19
19
  また、イテレータではなく、拡張for文で行った。
20
+
21
+
22
+
23
+ ```java
24
+
25
+ class Figure3D{
26
+
27
+ static ArrayList<Point3D> list = new ArrayList<Point3D>();
28
+
29
+ static void prim(double r, double th, double phi, boolean draw){
30
+
31
+ double D2R = Math.PI/180.0;
32
+
33
+ double x, y, z;
34
+
35
+ x = r*Math.sin(th*D2R)*Math.sin(phi*D2R);
36
+
37
+ y = r*Math.cos(th*D2R);
38
+
39
+ z = r*Math.sin(th*D2R)*Math.cos(phi*D2R);
40
+
41
+ list.add(new Point3D(x, y, z, draw));
42
+
43
+ }
44
+
45
+ static void display(double alpha, double beta, int px, int py, Graphics g){
46
+
47
+ int _dx = 0, _dy = 0, dx = 0, dy = 0;
48
+
49
+ Point p2d;
50
+
51
+ int N = list.size();
52
+
53
+ int i = 0;
54
+
55
+ for(Point3D p: list){
56
+
57
+ p2d = p.get2D(alpha, beta, px, py);
58
+
59
+ dx = (int)p2d.getX();
60
+
61
+ dy = (int)p2d.getY();
62
+
63
+ if(i++ > 0){ //ここで、trueかfalseを判別し以下の動作を行いたい
64
+
65
+ g.setColor(Color.getHSBColor((float)i/N, 1.0f, 1.0f));
66
+
67
+ g.drawLine(_dx, _dy, dx, dy);
68
+
69
+ }
70
+
71
+ _dx = dx;
72
+
73
+ _dy = dy;
74
+
75
+ }
76
+
77
+ }
78
+
79
+ }
80
+
81
+
82
+
83
+ class Point3D{
84
+
85
+ private double x, y, z;
86
+
87
+ boolean d;
88
+
89
+ Point3D(double _x, double _y, double _z, boolean _d){
90
+
91
+ x = _x;
92
+
93
+ y = _y;
94
+
95
+ z = _z;
96
+
97
+ d = _d;
98
+
99
+ }
100
+
101
+ Point get2D(double alpha, double beta, int px, int py){
102
+
103
+
104
+
105
+ }
106
+
107
+ }
108
+
109
+
110
+
111
+ ```