Introduction à python et aux mvts. 3d

publicité
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Courbes paramétriques dans R3
Introduction à python
Valse à 2 temps
Y. Delhaye
21 février 2016
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
1 Langage
L’ original
EDI
Valse à 2 temps
2 Exemples
L’ original
EDI
Valse à 2 temps
Python ?
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
Python ?
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
Langage de programmation
Python ?
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
Langage de programmation
L’ original
EDI
Valse à 2 temps
Interprété
Python ?
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
Langage de programmation
L’ original
EDI
Valse à 2 temps
Interprété
A colonne
Python ?
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
Langage de programmation
L’ original
EDI
Valse à 2 temps
Interprété
A colonne
Orienté objet
Python ?
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
Langage de programmation
L’ original
EDI
Valse à 2 temps
Interprété
A colonne
Orienté objet
Facile
Python ?
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
Langage de programmation
L’ original
EDI
Valse à 2 temps
Interprété
A colonne
Orienté objet
Facile Vrai de vrai !
Premier exemple
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
Exemples
L’ original
EDI
Valse à 2 temps
mpl.rcParams[’legend.fontsize’] = 10
fig = plt.figure()
ax = fig.gca(projection=’3d’)
theta = np.linspace(-4 * np.pi, 4 * np.pi, 200)
z = np.linspace(-0.5, 2, 200)
r = z**2 + 1
x = r * np.sin(2*theta)
y = r * np.cos(2*theta)
ax.plot(x, y, z, label=’Courbe parametrique: tornade’)
ax.legend()
Plus clair
Courbes
paramétriques
dans R3
1
Y. Delhaye
3
2
4
Langage
Exemples
i m p o r t m a t p l o t l i b a s mpl
from m p l _ t o o l k i t s . mplot3d i m p o r t Axes3D
i m p o r t numpy a s np
import m a t p l o t l i b . pyplot as p l t
5
6
mpl . r c P a r a m s [ ’ l e g e n d . f o n t s i z e ’ ] = 10
L’ original
EDI
Valse à 2 temps
7
8
9
10
11
12
13
14
15
16
f i g = plt . figure ()
ax = f i g . gca ( p r o j e c t i o n= ’ 3d ’ )
t h e t a = np . l i n s p a c e (−4 ∗ np . p i , 4 ∗ np . p i , 1 0 0 )
z = np . l i n s p a c e ( −2 , 2 , 1 0 0 )
r = z ∗∗2 + 1
x = r ∗ np . s i n ( t h e t a )
y = r ∗ np . c o s ( t h e t a )
ax . p l o t ( x , y , z , l a b e l= ’ p a r a m e t r i c c u r v e ’ )
ax . l e g e n d ( )
17
18
p l t . show ( )
Docs/lines3d_demo.py
Ce qui donne :
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
Ce qui donne :
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
En rouge
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
En rouge
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
En rouge : le code
Courbes
paramétriques
dans R3
1
Y. Delhaye
3
2
4
Langage
Exemples
5
6
L’ original
EDI
Valse à 2 temps
# −∗− c o d i n g : u t f −8 −∗−
"""
En r o u g e
"""
7
8
9
10
i m p o r t m a t p l o t l i b a s mpl
#from m p l _ t o o l k i t s . mplot3d i m p o r t Axes3D
i m p o r t numpy a s np
import m a t p l o t l i b . pyplot as p l t
#from m a t p l o t l i b . c o l o r s i m p o r t ∗
11
12
mpl . r c P a r a m s [ ’ l e g e n d . f o n t s i z e ’ ] = 10
13
14
15
16
17
18
19
20
f i g = plt . figure ()
ax = f i g . gca ( p r o j e c t i o n= ’ 3d ’ )
t = np . l i n s p a c e (−4 , 4 , 1 0 0 )
t h e t a = t ∗ np . p i
z = t /2
r = z ∗∗2 + 1
#r = s q r t ( z ∗ ∗ 2 )
Tornade
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
Tornade
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
Tornade : le code
Courbes
paramétriques
dans R3
1
Y. Delhaye
3
2
4
Langage
Exemples
i m p o r t m a t p l o t l i b a s mpl
from m p l _ t o o l k i t s . mplot3d i m p o r t Axes3D
i m p o r t numpy a s np
import m a t p l o t l i b . pyplot as p l t
5
6
mpl . r c P a r a m s [ ’ l e g e n d . f o n t s i z e ’ ] = 10
L’ original
EDI
Valse à 2 temps
7
8
9
10
11
12
13
14
15
16
f i g = plt . figure ()
ax = f i g . gca ( p r o j e c t i o n= ’ 3d ’ )
t h e t a = np . l i n s p a c e (−4 ∗ np . p i , 4 ∗ np . p i , 2 0 0 )
z = np . l i n s p a c e ( − 0.5 , 2 , 2 0 0 )
r = z ∗∗2 + 1
x = r ∗ np . s i n ( 2 ∗ t h e t a )
y = r ∗ np . c o s ( 2 ∗ t h e t a )
ax . p l o t ( x , y , z , l a b e l= ’ Courbe p a r a m e t r i q u e : t o r n a d e
’)
ax . l e g e n d ( )
17
18
p l t . show ( )
Ressort
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
Ressort
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
Ressort : le code
Courbes
paramétriques
dans R3
1
Y. Delhaye
3
2
4
Langage
Exemples
5
6
L’ original
EDI
Valse à 2 temps
# −∗− c o d i n g : u t f −8 −∗−
"""
Ressort
"""
7
8
9
i m p o r t m a t p l o t l i b a s mpl
#from m p l _ t o o l k i t s . mplot3d i m p o r t Axes3D
i m p o r t numpy a s np
import m a t p l o t l i b . pyplot as p l t
10
11
mpl . r c P a r a m s [ ’ l e g e n d . f o n t s i z e ’ ] = 10
12
13
14
15
16
17
18
19
20
f i g = plt . figure ()
ax = f i g . gca ( p r o j e c t i o n= ’ 3d ’ )
t h e t a = np . l i n s p a c e (−4 ∗ np . p i , 4 ∗ np . p i , 1 0 0 )
z = np . l i n s p a c e ( −2 , 2 , 1 0 0 )
r = 2
#r = s q r t ( z ∗ ∗ 2 )
x = r ∗ np . s i n ( t h e t a )
y = r ∗ np . c o s ( t h e t a )
Sphère
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
Sphère
Courbes
paramétriques
dans R3
Y. Delhaye
Langage
Exemples
L’ original
EDI
Valse à 2 temps
Sphère : le code
Courbes
paramétriques
dans R3
1
Y. Delhaye
3
2
4
Langage
Exemples
5
6
L’ original
EDI
Valse à 2 temps
# −∗− c o d i n g : u t f −8 −∗−
"""
Sphere
"""
7
8
9
10
i m p o r t m a t p l o t l i b a s mpl
from m p l _ t o o l k i t s . mplot3d i m p o r t Axes3D
i m p o r t numpy a s np
import m a t p l o t l i b . pyplot as p l t
#from m a t p l o t l i b . c o l o r s i m p o r t ∗
11
12
mpl . r c P a r a m s [ ’ l e g e n d . f o n t s i z e ’ ] = 10
13
14
15
16
17
18
19
20
f i g = plt . figure ()
ax = f i g . gca ( p r o j e c t i o n= ’ 3d ’ )
t = np . l i n s p a c e ( 0 , 1 , 5 0 0 )
t h e t a = t ∗ np . p i
r = 1
r_xy = np . s i n ( t h e t a )
Téléchargement