IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Calcul scientifique Python Discussion :

Spirale tournante et math


Sujet :

Calcul scientifique Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Avatar de Luke spywoker
    Homme Profil pro
    Etudiant informatique autodidacte
    Inscrit en
    Juin 2010
    Messages
    1 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Etudiant informatique autodidacte

    Informations forums :
    Inscription : Juin 2010
    Messages : 1 077
    Par défaut Spirale tournante et math
    Salut les pythons scientifiques,
    Je suis arriver a dessiner une spirale grâce a une formule qu'on trouve dans tous les bouquins de programmation de jeux ou scientifique qui permet de donner une longueur de rayon, et un nombre de points symbolisant le nombre de coin d'un polygone et qui renvoie les coordonnées.
    Et j'ai adapter cette méthode afin de dessiner une spirale que j'arrive a faire tourner comme vous le verrai si vous exécuter le code qui suit.
    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
     
    # -*- coding: utf-8 -*-
     
    import pygame
    from pygame.locals import *
    from sys import exit
    import math
    from time import sleep
     
    pygame.init()
    screen=pygame.display.set_mode((800,600))
     
    def get_angle(pos,scale,start_pos) :
      offset=start_pos #décalage
      degrees=360/scale * pos + offset
      return degrees
     
    def return_coords(pos,scale,length,x,y,start_pos) :
      degrees=get_angle(pos,scale,start_pos)
      rad_value=degrees/180.0*math.pi #conversion en radians
      x_pos=round(math.cos(rad_value)*length+x)
      y_pos=round(math.sin(rad_value)*length+y)
      return (x_pos,y_pos)
     
     
    angle_list_positiv=[6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 144, 150, 156, 162, 168, 174, 180, 186, 192, 198, 204, 210, 216, 222, 228, 234, 240, 246, 252, 258, 264, 270, 276, 282, 288, 294, 300, 306, 312, 318, 324, 330, 336, 342, 348, 354, 360]
    angle_list_negativ=[-6, -12, -18, -24, -30, -36, -42, -48, -54, -60, -66, -72, -78, -84, -90, -96, -102, -108, -114, -120, -126, -132, -138, -144, -150, -156, -162, -168, -174, -180, -186, -192, -198, -204, -210, -216, -222, -228, -234, -240, -246, -252, -258, -264, -270, -276, -282, -288, -294, -300, -306, -312, -318, -324, -330, -336, -342, -348, -354, -360]
    angle_list_negativ.reverse()
     
     
    control=0 
    ii=0 
    while True :
     
     
      if control == 0 :
        from_center=1
        spiral_coords=[]
     
     
        i=0
        while i < 60 :
          spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_positiv[i]))
          i += 1
     
          from_center +=1
        i=0  
        while i < 60 :
          spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_positiv[i]))
          i += 1
          from_center +=1 
     
        i=0  
        while i < 60 :
          spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_positiv[i]))
          i += 1
          from_center +=1  
     
        to_change=angle_list_positiv.pop(0)
        angle_list_positiv.append(to_change)
        ii += 1
        if ii == 60 :
          ii=0
          control=1
     
      elif control == 1 :
        from_center=1
        spiral_coords=[]
     
     
        i=59
        while i >= 0 :
          spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_negativ[i]))
     
          i -= 1
          from_center +=1
     
        i=59  
        while i >= 0 :
          spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_negativ[i]))
     
          i -= 1
          from_center +=1 
     
        i=59  
        while i >= 0 :
          spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_negativ[i]))
     
          i -= 1
          from_center +=1  
     
     
        to_change=angle_list_negativ.pop(0)
     
        angle_list_negativ.append(to_change)
        ii += 1
        if ii == 60 :
          ii=0
          control=0
     
      screen.fill((0))
      pygame.draw.lines(screen,(255,255,255),False,spiral_coords,2)
      sleep(0.1)
     
     
     
      for event in pygame.event.get() :
        if event.type == QUIT :
          exit()
     
      pygame.display.update()
    Et j'aimerai quand la valeur de la variable control est a 1 de faire tourner la spirale dans le sens contraire des aiguille d'une montre et donc inversement au tour avec valeur de control=0... Seulement je n'y arrive pas c'est pourquoi je m'adresse a vous qui pouvait m'aider si vous avez de l'adresse en math, j'ai mis plusieurs variable en place dans ce but (angle_list_negativ, itération inverse...) et j'ai essayer de jouer avec ces paramètres afin de faire tourner la spirale dans l'autre sens sans succès.
    Je ne suis pas fort en math et je vous serai reconnaissant de bien vouloir m'aider si vous le pouvez ( il faut prendre un peu de temps ).
    Merci pour vos réponses éclairées.

  2. #2
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 068
    Par défaut
    y a un code bien sympa ici: http://www.pasteall.org/15524/python

    tu peux peut-être t'en inspirer.

  3. #3
    Rédacteur

    Avatar de Matthieu Brucher
    Profil pro
    Développeur HPC
    Inscrit en
    Juillet 2005
    Messages
    9 810
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Développeur HPC
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2005
    Messages : 9 810
    Par défaut
    En fait, tu dois transformer ton 0 et ton 1 en respectivement -1 et 1, c'est ça ?

  4. #4
    Membre éprouvé
    Avatar de Luke spywoker
    Homme Profil pro
    Etudiant informatique autodidacte
    Inscrit en
    Juin 2010
    Messages
    1 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Etudiant informatique autodidacte

    Informations forums :
    Inscription : Juin 2010
    Messages : 1 077
    Par défaut
    Merci pour vos réponses et pour le liens.
    J'ai modifier mon code mais je n'obtiens pas le résultat souhaiter: j'arrive a faire tourner la spirale dans l'autre sens mais celle-ci est dans l'orientation inverse de la spirale de départ ce qui n'est pas le but j'aimerai garder la même orientation mais faire tourner la spirale l'envers sans changer l'orientation de celle-ci.
    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
     
    # -*- coding: utf-8 -*-
     
    import pygame
    from pygame.locals import *
    from sys import exit
    import math
    import datetime
    from pygame import gfxdraw
    from time import sleep
    from random import choice
     
    pygame.init()
    screen=pygame.display.set_mode((800,600))
     
    def get_angle(pos,scale,start_pos) :
      offset=start_pos #décalage
      degrees=360/scale * pos + offset
      return degrees
     
    def return_coords(pos,scale,length,x,y,start_pos) :
      degrees=get_angle(pos,scale,start_pos)
      rad_value=degrees/180.0*math.pi #conversion en radians
      x_pos=round(math.cos(rad_value)*length+x)
      y_pos=round(math.sin(rad_value)*length+y)
      return (x_pos,y_pos)
     
     
    def get_angle_inverse(pos,scale,start_pos) :
      offset=start_pos #décalage
      degrees=360/scale * pos + offset
      return -degrees
     
    def return_coords_inverses(pos,scale,length,x,y,start_pos) :
      degrees=get_angle_inverse(pos,scale,start_pos)
      rad_value=degrees/180.0*math.pi #conversion en radians
      x_pos=round(math.cos(rad_value)*length+x)
      y_pos=round(math.sin(rad_value)*length+y)
      return (x_pos,y_pos)  
     
    angle_list_positiv=[6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 144, 150, 156, 162, 168, 174, 180, 186, 192, 198, 204, 210, 216, 222, 228, 234, 240, 246, 252, 258, 264, 270, 276, 282, 288, 294, 300, 306, 312, 318, 324, 330, 336, 342, 348, 354, 360]
    angle_list_negativ=[-6, -12, -18, -24, -30, -36, -42, -48, -54, -60, -66, -72, -78, -84, -90, -96, -102, -108, -114, -120, -126, -132, -138, -144, -150, -156, -162, -168, -174, -180, -186, -192, -198, -204, -210, -216, -222, -228, -234, -240, -246, -252, -258, -264, -270, -276, -282, -288, -294, -300, -306, -312, -318, -324, -330, -336, -342, -348, -354, -360]
    angle_list_negativ.reverse()
     
     
    control=0 
    ii=0 
    while True :
     
     
      if control == 0 :
        from_center=1
        spiral_coords=[]
     
     
        i=0
        while i < 60 :
          spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_positiv[i]))
          i += 1
     
          from_center +=1
        i=0  
        while i < 60 :
          spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_positiv[i]))
          i += 1
          from_center +=1 
     
        i=0  
        while i < 60 :
          spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_positiv[i]))
          i += 1
          from_center +=1  
     
        to_change=angle_list_positiv.pop(0)
        angle_list_positiv.append(to_change)
        ii += 1
        if ii == 60 :
          ii=0
          control=1
     
      elif control == 1 :
        from_center=1
        spiral_coords=[]
     
     
        i=0
        while i < 60 :
          spiral_coords.append(return_coords_inverses(i,60,from_center,400,300,angle_list_positiv[i]))
          i += 1
     
          from_center +=1
        i=0  
        while i < 60 :
          spiral_coords.append(return_coords_inverses(i,60,from_center,400,300,angle_list_positiv[i]))
          i += 1
          from_center +=1 
     
        i=0  
        while i < 60 :
          spiral_coords.append(return_coords_inverses(i,60,from_center,400,300,angle_list_positiv[i]))
          i += 1
          from_center +=1  
     
        to_change=angle_list_positiv.pop(0)
        angle_list_positiv.append(to_change)
        ii += 1
        if ii == 60 :
          ii=0
          control=0
     
      screen.fill((0))
      pygame.draw.lines(screen,(255,255,255),False,spiral_coords,2)
      sleep(0.1)
     
     
     
      for event in pygame.event.get() :
        if event.type == QUIT :
          exit()
     
      pygame.display.update()
    Merci pour vos réponses.

  5. #5
    Membre éprouvé
    Avatar de Luke spywoker
    Homme Profil pro
    Etudiant informatique autodidacte
    Inscrit en
    Juin 2010
    Messages
    1 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Etudiant informatique autodidacte

    Informations forums :
    Inscription : Juin 2010
    Messages : 1 077
    Par défaut Réponse trouver
    Merci pour vos réponses,
    je poste simplement car j'ai trouver réponse a ce que je voulais faire tous seul et la solution se trouve dans le changement de position dans la liste d'angles, bref je vous laisse admirez le résultat:
    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
    86
     
     
    # -*- coding: utf-8 -*-
     
    import pygame
    from pygame.locals import *
    from sys import exit
    import math
    import datetime
    from pygame import gfxdraw
    from time import sleep
    from random import choice
     
    pygame.init()
    screen=pygame.display.set_mode((800,600))
     
    def get_angle(pos,scale,start_pos) :
      offset=start_pos #décalage
      degrees=360/scale * pos + offset
      return degrees
     
    def return_coords(pos,scale,length,x,y,start_pos) :
      degrees=get_angle(pos,scale,start_pos)
      rad_value=degrees/180.0*math.pi #conversion en radians
      x_pos=round(math.cos(rad_value)*length+x)
      y_pos=round(math.sin(rad_value)*length+y)
      return (x_pos,y_pos)
     
    angle_list_positiv=[6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 144, 150, 156, 162, 168, 174, 180, 186, 192, 198, 204, 210, 216, 222, 228, 234, 240, 246, 252, 258, 264, 270, 276, 282, 288, 294, 300, 306, 312, 318, 324, 330, 336, 342, 348, 354, 360]
     
    control=0 
    ii=0 
    sens=0
    while True :
     
     
     
      from_center=1
      spiral_coords=[]
     
     
      i=0
      while i < 60 :
        spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_positiv[i]))
        i += 1
     
        from_center +=1
      i=0  
      while i < 60 :
        spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_positiv[i]))
        i += 1
        from_center +=1 
     
      i=0  
      while i < 60 :
        spiral_coords.append(return_coords(i,60,from_center,400,300,angle_list_positiv[i]))
        i += 1
        from_center +=1  
     
      if control == 0 :
        to_change=angle_list_positiv.pop(0)
        angle_list_positiv.append(to_change)
      elif control == 1 :
        to_change=angle_list_positiv.pop(-1)
        angle_list_positiv.insert(0,to_change)
     
      ii += 1
      if ii == 60 and control == 0 :
        ii=0
        control=1
      elif ii == 60 and control == 1 :
        ii=0
        control=0
     
     
      screen.fill((0))
      pygame.draw.lines(screen,(255,255,255),False,spiral_coords,2)
      sleep(0.1)
     
     
     
      for event in pygame.event.get() :
        if event.type == QUIT :
          exit()
     
      pygame.display.update()
    Merci pour vos réponses et le liens m'a beaucoup inspirer.
    Sur ce bon python a vous.

  6. #6
    Expert confirmé
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    4 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 4 062
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    angle_list_positiv=[i for i in range(6, 360, 6)]

  7. #7
    Membre Expert
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 068
    Par défaut
    Citation Envoyé par fred1599 Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    angle_list_positiv=[i for i in range(6, 360, 6)]
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    angle_list_positiv=[i for i in range(6, 361, 6)]

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [math] somme de plusieurs vecteurs à 3 dimensions
    Par teska dans le forum Mathématiques
    Réponses: 5
    Dernier message: 04/06/2003, 21h40
  2. [MATH] Point par rapport à une droite
    Par teska dans le forum Mathématiques
    Réponses: 6
    Dernier message: 14/05/2003, 16h11
  3. #include "math.h" et #include <math.h>
    Par pounka dans le forum C
    Réponses: 4
    Dernier message: 01/05/2003, 21h06
  4. Problème de math....
    Par zdra dans le forum Mathématiques
    Réponses: 6
    Dernier message: 11/11/2002, 10h59
  5. Maths : équations
    Par Anonymous dans le forum Mathématiques
    Réponses: 5
    Dernier message: 02/05/2002, 16h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo