Bonjour,
j'ai un souci pour tracer les rayons d'un cercle : le premier point sur le centre ne pose pas de probleme, le second n'atteint pas le cercle, ou le dépasse.
Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
 
import pygame
from pygame.locals import *
import time
import random
import math
 
pygame.init()
fenetre = pygame.display.set_mode((1800, 1000))
 
BLACK = (  0,   0,   0)
WHITE = (255, 255, 255)
RED   = (255,   0,   0)
GREEN = (  0, 255,   0)
BLUE  = (  0,   0, 255)
 
 
couleur_cercle = WHITE
centreX = 900
centreY = 500
rayon = 500
epaisseur = 4
 
cadran = pygame.draw.circle(fenetre, couleur_cercle, (centreX,centreY),rayon, epaisseur)
 
pi = math.pi
alpha  = random.uniform(0, 6.28) # 2 * pi arrondi
 
crazy = -1 # coefficient : le sens des axes de pygame est different des axes O-i-j en math
 
if alpha > 0 and alpha < pi:
    if alpha < (0.5*pi):
        bx = math.cos(alpha)
        by = math.sin(alpha)
    else:
        bx = -math.cos(alpha)
        by = math.sin(alpha)    
elif alpha > pi and alpha < (1.5*pi):
    bx = -math.cos(alpha)
    by = -math.sin(alpha)
else:
    bx = math.cos(alpha)
    by = -math.sin(alpha)
 
if alpha > 0 and alpha < pi:
    BX = bx * rayon
    BY = (by * rayon) * crazy
else:
    BX = bx * rayon
    BY = by * rayon
 
ligne_zero  = pygame.draw.line(fenetre, GREEN, (centreX,centreY),(centreX + rayon, centreY), 5)
rayon_alpha = pygame.draw.line(fenetre, RED, (centreX,centreY),(BX + rayon, BY + rayon), 5)
 
myfont = pygame.font.SysFont("monospace", 15)
 
label_alpha = myfont.render("angle alpha (rad) : "+str(alpha), 1, (255,255,0))
label_bx = myfont.render("bx : "+str(bx), 1, (255,255,0))
label_by = myfont.render("bx : "+str(by), 1, (255,255,0))
 
fenetre.blit(label_alpha, (1500, 700))
fenetre.blit(label_bx, (1500, 720))
fenetre.blit(label_by, (1500, 740))
 
pygame.display.flip()
time.sleep(2)
 
"""
https://www.google.fr/#q=coordonn%C3%A9e+cercle+angle+pi+radian+degr%C3%A9    RAPPEL TRIGO
 
1 radian = 180/pi = env 57°
 
(deg) 30    45    60    90
(rad) pi/6  pi/4  pi/3  pi/2
 
x en degres = (x*pi)/180  en radians
 
2 pi = tour complet
pi = 180°
 
math.degrees(angle_en_radians) # Convertit en degrés
math.radians(angle_en_degrés) # Convertit en radians
"""