Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Oct 12 13:42:08 2017
  4.  
  5. @author: Louis
  6. """
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9. from mpl_toolkits.mplot3d import Axes3D
  10.  
  11. #==============================================================================
  12. # Définition de plusieurs variables et d'exemples
  13. #==============================================================================
  14. p = 0.01 #Précision pour les dérivées
  15. preci = 5 #Nombre de décimales de précision pour la comparaison dans verification_surface_reglee()
  16. Lu = np.linspace(-10,10,40) #Discrétisation d'un intervalle des u
  17. Lv = np.linspace(-10,10,40) #Discrétisation d'un intervalle des v
  18.  
  19. #Définition de plusieurs surfaces connues :
  20. def f1(u,v): #Hélice
  21. x=1*v*np.cos(u)
  22. y=1*v*np.sin(u)
  23. z=1*u
  24. return np.array([x,y,z])
  25. def f2(u,v): #Sphère
  26. x=np.cos(u)*np.cos(v)
  27. y=np.sin(u)*np.cos(v)
  28. z=np.sin(v)
  29. return np.array([x,y,z])
  30. def f3(u,v): #Cône
  31. x=v*np.cos(u)
  32. y=v*np.sin(u)
  33. z=v
  34. return np.array([x,y,z])
  35. def f4(u,v): #Hyperboloïde
  36. a,b,c,d = 1,1,1,1
  37. x=a*np.sqrt(u**2 + d)*np.cos(v)
  38. y=b*np.sqrt(u**2 + d)*np.sin(v)
  39. z=c*u
  40. return np.array([x,y,z])
  41.  
  42. #==============================================================================
  43. # Mise en place de la méthode
  44. #==============================================================================
  45.  
  46. #Définition des fonctions de dérivation partielles et de la fonction d'intrégration de Gp pour obtenir G et K
  47. def derive_u(f,u,v,pas=p):
  48. return (f(u+pas,v)-f(u,v))/pas
  49. def derive_v(f,u,v,pas=p):
  50. return (f(u,v+pas)-f(u,v))/pas
  51. def derive_u_u(f,u,v,pas=p):
  52. return (derive_u(f,u+pas,v,pas)-derive_u(f,u,v,pas))/pas
  53. def derive_v_v(f,u,v,pas=p):
  54. return (derive_v(f,u,v+pas,pas)-derive_v(f,u,v,pas))/pas
  55. def derive_u_v(f,u,v,pas=p):
  56. return (derive_v(f,u+pas,v,pas)-derive_v(f,u,v,pas))/pas
  57. def derive_v_u(f,u,v,pas=p):
  58. return (derive_u(f,u,v+pas,pas)-derive_u(f,u,v,pas))/pas
  59. def primitive_u(Gp,f,u,v,pas=p):
  60. S=0
  61. P = np.arange(0,u+pas,pas)
  62. for p in P:
  63. S += pas * Gp(f,p,v)[0]
  64. return np.array([S,Gp(f,u,v)[1],Gp(f,u,v)[2]])
  65.  
  66. #Obtention de K et de G
  67. def K(f,u,v):
  68. return derive_v(f,u,v)
  69.  
  70. def Gp(f,u,v):
  71. return derive_u(f,u,v) - v*derive_u_v(f,u,v)
  72.  
  73. def G(f,u,v):
  74. return primitive_u(Gp,f,u,v)
  75.  
  76. def fonct_surf_reglee(f,u,v): #Recomposition de l'hypothétique surface reglée sous forme f(u,v)=G(u)+v.K(u)
  77. return G(f,u,v) + v*K(f,u,v)
  78.  
  79. def verification_surface_reglee(f,Lu,Lv): #Vérification de l'égalité de la fonction réelle et de la fonction recomposée pour tout u et tout v
  80. b=True
  81. for u in Lu:
  82. for v in Lv:
  83. if not(np.array_equal(np.around(f(u,v),preci),np.around(fonct_surf_reglee(f,u,v),preci))):
  84. b=False
  85. # print("Pas égalité pour u={} et v={}".format(u,v))
  86. # print(f(u,v))
  87. # print(fonct_surf_reglee(f,u,v))
  88. else:
  89. # print("OK pour {} ; {}".format(u,v))
  90. pass
  91. return b
  92.  
  93.  
  94. #==============================================================================
  95. # Essais
  96. #==============================================================================
  97. f = lambda u,v : f4(v,u) #Fonction à utiliser, renommée f()
  98.  
  99. #Affichage de la surface réelle et de la surface recomposée
  100. #ax1 = Axes3D(plt.figure())
  101. #ax2 = Axes3D(plt.figure())
  102. #Lx = [[f(u,v)[0] for u in Lu] for v in Lv]
  103. #Ly = [[f(u,v)[1] for u in Lu] for v in Lv]
  104. #Lz = [[f(u,v)[2] for u in Lu] for v in Lv]
  105. #ax1.plot_surface(Lx, Ly, Lz, rstride=1, cstride=1,cmap=cm.jet)
  106. #
  107. #fsurf = lambda u,v : fonct_surf_reglee(f,u,v)
  108. #Lx = [[fsurf(u,v)[0] for u in Lu] for v in Lv]
  109. #Ly = [[fsurf(u,v)[1] for u in Lu] for v in Lv]
  110. #Lz = [[fsurf(u,v)[2] for u in Lu] for v in Lv]
  111. #ax2.plot_surface(Lx, Ly, Lz, rstride=1, cstride=1,cmap=cm.jet)
  112. #
  113. #ax1.set_xlim(-5,5);ax1.set_ylim(-5,5);ax1.set_zlim(-5,5)
  114. #ax2.set_xlim(-5,5);ax2.set_ylim(-5,5);ax2.set_zlim(-5,5)
  115. #
  116. #plt.show()
  117.  
  118. print(verification_surface_reglee(f,Lu,Lv)) #Affiche si la surface est réglée ou non
  119.  
  120. #==============================================================================
  121. # Recherche du rayon de courbure principal
  122. #==============================================================================
  123.  
  124. def deriveeUnSurRn(f,u,v,mu): #Renvoi la dérivée de 1/Rn
  125. d1 = derive_u(f,u,v)
  126. d2 = derive_v(f,u,v)
  127. d3 = derive_u_u(f,u,v)
  128. d4 = derive_v_v(f,u,v)
  129. d5 = derive_u_v(f,u,v)
  130. H = np.array([d1[1]*d2[2]-d1[2]*d2[1],d1[2]*d2[0]-d1[0]*d2[2],d1[0]*d2[1]-d1[1]*d2[0]]) #produit vectoriel
  131. h = H/(np.sqrt(H[0]**2 + H[1]**2 + H[2]**2))
  132. L = h[0]*d3[0] + h[1]*d3[1] + h[2]*d3[2]
  133. M = h[0]*d5[0] + h[1]*d5[1] + h[2]*d5[2]
  134. N = h[0]*d4[0] + h[1]*d4[1] + h[2]*d4[2]
  135. E = d1[0]**2 + d1[1]**2 + d1[2]**2
  136. F = d1[0]*d2[0] + d1[1]*d2[1] + d1[2]*d2[2]
  137. G = d2[0]**2 + d2[1]**2 + d2[2]**2
  138. return ((2*M+2*N*mu)*(E+2*F+G*mu*mu)-(L+2*M*mu+N*mu*mu)*(2*F+2*G*mu))/((E+2*F*mu+G*mu*mu)**2)
  139.  
  140. def recherche_zero(Lx,Ly): #Renvoie l'abscisse auquel s'annule la fonction
  141. for p in range(len(Lx)-1):
  142. if Ly[p]*Ly[p+1]<0:
  143. return Lx[p]
  144.  
  145. Lmu = np.linspace(-100,100,10000) #Intervalle de recherche du zéro
  146. Ly=[deriveeUnSurRn(f,3,-8,mu) for mu in Lmu]
  147.  
  148. def rayon_courbure_mini(f,Lu,Lv): #Renvoie le rayon de courbure minimal de la surface pour tout u et tout v
  149. mini=100
  150. for u in Lu:
  151. for v in Lv:
  152. Ly=[deriveeUnSurRn(f,u,v,mu) for mu in Lmu]
  153. mu=recherche_zero(Lmu,Ly)
  154. if(mu<mini):
  155. mini=mu
  156. return mu
  157.  
  158. def usinable(f,Lu,Lv,d):
  159. mu=rayon_courbure_mini(f,Lu,Lv)
  160. if mu>=d:
  161. return("La surface est usinable par une fraise de {}".format(d))
  162. else:
  163. return("La surface n'est pas usinable par une fraise de {}".format(d))
  164.  
  165. print(usinable(f,Lu,Lv,4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement