-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAula12_2_2.py
44 lines (34 loc) · 1.14 KB
/
Aula12_2_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from p5 import *
v_direcao_blue=[10,100]#Mudar aqui
v_direcao_red=[0,200]
resultado=0
def normaliza(v_input):
return v_input/np.linalg.norm(v_input)
def setup():
global resultado
size(400, 400)
def draw():
background(0)
stroke_weight(10)
stroke(0,0,255)
line((width/2,height/2), (mouse_x, mouse_y))
v_direcao_blue=[width/2-mouse_x,height/2-mouse_y]
stroke(255,0,0)
line((width/2,height/2), (width/2+v_direcao_red[0], height/2+v_direcao_red[1]))
v_normalized1=normaliza(v_direcao_blue)
v_normalized2=normaliza(v_direcao_red)
resultado = np.dot(v_normalized2, v_normalized1)
if(resultado==1):
print("Same Direction")
#Se o dot product for 0,
#significa que são perpendiculares um ao outro
elif(resultado==0):
print("Perpendicular")
#Finalmente se o dot.product for -1,
#significa que ambos os vetores estão a ir em direções opostas
elif(resultado==-1):
print("Opposite directions")
#pygame.draw.circle( screen, RED, pygame.mouse.get_pos(), 1)
else :print("Non orthogonal nor paralell")
if __name__ == '__main__':
run()