質問編集履歴

2

質問の真意を間違えていた

2017/10/23 03:57

投稿

bell12
bell12

スコア6

test CHANGED
@@ -1 +1 @@
1
- pythonによる2次元座標の計算について(共円の判定プログラム)
1
+ pythonによる2次元座標の計算について
test CHANGED
@@ -1,207 +1,5 @@
1
- ###前提・実現したいこと
1
+ Numpy初心者です。
2
2
 
3
- pygameをつかい、共円というゲームを作成中です。現在クリックした座標をmousepos1というリストにいれ、(例 mousepos1 = [(234,432)] )
3
+ element = (array([640, 250]), array([60, 350]), array([469, 70]), array([260, 1000]))
4
4
 
5
- mousepos2というリストにクリックした座標から一番近いベクトルを順にリストに格納することができました。(例 mousepos2 = [array([150, 100]), array([150, 150]), array([200, 100]), array([200, 150])]
6
-
7
- そこで実現したいことは、このmousepos2というリストの中の要素を使い、同一円周上にある点かどうかを判定し、共円であれば
8
-
9
- pygame.quit()
10
-
11
- sys.exit()
12
-
13
- で終了するプログラムが作りたいです。
14
-
15
- pygameをインポートされていないのであれば、mousepos2 = [array([150, 100]), array([150, 150]), array([200, 100]), array([200, 150])] を使い、共円かどうかを調べるプログラムのみでお願いします。
16
-
17
-
18
-
19
- ###ソースコード
20
-
21
- ```
22
-
23
- # -*- coding:utf-8 -*-
24
-
25
- import pygame
26
-
27
- import numpy as np
28
-
29
- from pygame.locals import *
30
-
31
- import sys
32
-
33
-
34
-
35
- # 点p0に一番近い点を点群psから抽出
36
-
37
- def search_points(p0, ps):
38
-
39
- L = np.array([])
40
-
41
- for i in range(ps.shape[0]):
42
-
43
- L = np.append(L,np.linalg.norm(ps[i]-p0))
44
-
45
- return ps[np.argmin(L)]
46
-
47
-
48
-
49
-
50
-
51
- def main():
52
-
53
- pygame.init() # Pygameの初期化
54
-
55
- screen = pygame.display.set_mode((600,600)) # 大きさ600*500の画面を生成
56
-
57
- pygame.display.set_caption("共円ゲーム") # タイトルバーに表示する文字
58
-
59
- mousepos1 = []
60
-
61
- mousepos2 = []
62
-
63
-
64
-
65
-
66
-
67
- while (1):
68
-
69
- screen.fill((255,255,255)) # 画面を黒色に塗りつぶし
70
-
71
- pygame.draw.line(screen, (0,0,0), (50,50), (550,50), 1) # 直線の描画
72
-
73
- pygame.draw.line(screen, (0,0,0), (50,100), (550,100), 1)
74
-
75
- pygame.draw.line(screen, (0,0,0), (50,150), (550,150), 1)
76
-
77
- pygame.draw.line(screen, (0,0,0), (50,200), (550,200), 1)
78
-
79
- pygame.draw.line(screen, (0,0,0), (50,250), (550,250), 1)
80
-
81
- pygame.draw.line(screen, (0,0,0), (50,300), (550,300), 1)
82
-
83
- pygame.draw.line(screen, (0,0,0), (50,350), (550,350), 1)
84
-
85
- pygame.draw.line(screen, (0,0,0), (50,400), (550,400), 1)
86
-
87
- pygame.draw.line(screen, (0,0,0), (50,450), (550,450), 1)
88
-
89
- pygame.draw.line(screen, (0,0,0), (50,500), (550,500), 1)
90
-
91
- pygame.draw.line(screen, (0,0,0), (50,550), (550,550), 1)
92
-
93
- pygame.draw.line(screen, (0,0,0), (50,50), (50,550), 1) # 直線の描画
94
-
95
- pygame.draw.line(screen, (0,0,0), (100,50), (100,550), 1)
96
-
97
- pygame.draw.line(screen, (0,0,0), (150,50), (150,550), 1)
98
-
99
- pygame.draw.line(screen, (0,0,0), (200,50), (200,550), 1)
100
-
101
- pygame.draw.line(screen, (0,0,0), (250,50), (250,550), 1)
102
-
103
- pygame.draw.line(screen, (0,0,0), (300,50), (300,550), 1)
104
-
105
- pygame.draw.line(screen, (0,0,0), (350,50), (350,550), 1)
106
-
107
- pygame.draw.line(screen, (0,0,0), (400,50), (400,550), 1)
108
-
109
- pygame.draw.line(screen, (0,0,0), (450,50), (450,550), 1)
110
-
111
- pygame.draw.line(screen, (0,0,0), (500,50), (500,550), 1)
112
-
113
- pygame.draw.line(screen, (0,0,0), (550,50), (550,550), 1)
114
-
115
- ps = np.array([[50,50],[50,100],[50,150],[50,200],[50,250],[50,300],[50,350],[50,400],[50,450],[50,500],[50,550],[50,600],
116
-
117
- [100,50],[100,100],[100,150],[100,200],[100,250],[100,300],[100,350],[100,400],[100,450],[100,500],[100,550],
118
-
119
- [150,50],[150,100],[150,150],[150,200],[150,250],[150,300],[150,350],[150,400],[150,450],[150,500],[150,550],
120
-
121
- [200,50],[200,100],[200,150],[200,200],[200,250],[200,300],[200,350],[200,400],[200,450],[200,500],[200,550],
122
-
123
- [250,50],[250,100],[250,150],[250,200],[250,250],[250,300],[250,350],[250,400],[250,450],[250,500],[250,550],
124
-
125
- [300,50],[300,100],[300,150],[300,200],[300,250],[300,300],[300,350],[300,400],[300,450],[300,500],[300,550],
126
-
127
- [350,50],[350,100],[350,150],[350,200],[350,250],[350,300],[350,350],[350,400],[350,450],[350,500],[350,550],
128
-
129
- [400,50],[400,100],[400,150],[400,200],[400,250],[400,300],[400,350],[400,400],[400,450],[400,500],[400,550],
130
-
131
- [450,50],[450,100],[450,150],[450,200],[450,250],[450,300],[450,350],[450,400],[450,450],[450,500],[450,550],
132
-
133
- [500,50],[500,100],[500,150],[500,200],[500,250],[500,300],[500,350],[500,400],[500,450],[500,500],[500,550],
134
-
135
- [550,50],[550,100],[550,150],[550,200],[550,250],[550,300],[550,350],[550,400],[550,450],[550,500],[550,550]])
136
-
137
- for event in pygame.event.get():
138
-
139
- if event.type == QUIT: # 閉じるボタンが押されたら終了
140
-
141
- pygame.quit() # Pygameの終了(画面閉じられる)
142
-
143
- sys.exit()
144
-
145
-
146
-
147
- if event.type == MOUSEBUTTONDOWN:
148
-
149
- mousepos1.append(event.pos)
150
-
151
- print(mousepos1)
152
-
153
- mousepos2.append(search_points(event.pos,ps))
154
-
155
- print(mousepos2)
156
-
157
-
158
-
159
- if len(mousepos2) == 10:
160
-
161
- pygame.quit()
162
-
163
- sys.exit()
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
- for i,j in mousepos1:
172
-
173
- p0 = np.array([i,j])
174
-
175
- pygame.draw.circle(screen, (0,0,255),(search_points(p0, ps)), 10)
176
-
177
- pygame.display.update()
178
-
179
-
180
-
181
- if __name__ == "__main__":
182
-
183
- main()
184
-
185
-
186
-
187
- ```
188
-
189
-
190
-
191
-
192
-
193
- ###試したこと
194
-
195
- これを実現するためにはもちろん4つの点の座標が必要なので、
196
-
197
- if len(mousepos2) == 4:
198
-
199
- という条件があってから演算をしていくのだろうと思いますが、この先にどのようにすればよいかわかりません。
200
-
201
- レミー定理使えばぐできそうだと思っているのでが。。。
5
+ このようなリスがあり、640値だけ取りだ方法ありまか?
202
-
203
-
204
-
205
- ###補足情報(言語/FW/ツール等のバージョンなど)
206
-
207
- python3.4 pygame

1

インデントが間違っていた

2017/10/23 03:57

投稿

bell12
bell12

スコア6

test CHANGED
File without changes
test CHANGED
@@ -16,9 +16,11 @@
16
16
 
17
17
 
18
18
 
19
-
20
-
21
- ###該当のソースコード
19
+ ###ソースコード
20
+
21
+ ```
22
+
23
+ # -*- coding:utf-8 -*-
22
24
 
23
25
  import pygame
24
26
 
@@ -30,6 +32,8 @@
30
32
 
31
33
 
32
34
 
35
+ # 点p0に一番近い点を点群psから抽出
36
+
33
37
  def search_points(p0, ps):
34
38
 
35
39
  L = np.array([])
@@ -180,6 +184,10 @@
180
184
 
181
185
 
182
186
 
187
+ ```
188
+
189
+
190
+
183
191
 
184
192
 
185
193
  ###試したこと