Advertisement
FaisalAhemdBijoy

Graphics answer del

Mar 1st, 2021
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.46 KB | None | 0 0
  1. import hashlib
  2. import math
  3. from math import *
  4. from operator import *
  5. import numpy as np
  6. #roll=input("Enter your Roll : ")
  7. roll = "1607048"
  8. # initial কারিসমা
  9. hash = hashlib.md5(roll.encode())
  10. out = hash.hexdigest()
  11. print("Roll : "+"md5 hash is: ")
  12. print(roll, " : ", out)
  13. # check roll even or odd
  14. Roll = int(roll)
  15. if Roll % 2 == 0:
  16.     # print ("even")
  17.     d0 = int(out[-1], 16)
  18.     d1 = int(out[-2], 16)
  19.     d2 = int(out[-3], 16)
  20.     d3 = int(out[-4], 16)
  21.     d4 = int(out[-5], 16)
  22.     d5 = int(out[-6], 16)
  23. else:
  24.     # print("odd")
  25.     d0 = int(out[5], 16)
  26.     d1 = int(out[4], 16)
  27.     d2 = int(out[3], 16)
  28.     d3 = int(out[2], 16)
  29.     d4 = int(out[1], 16)
  30.     d5 = int(out[0], 16)
  31.  
  32. # # # solution of question no 1.
  33. print("d0 is :", d0)
  34. print("d1 is :", d1)
  35. print("d2 is :", d2)
  36. print("d3 is :", d3)
  37. print("d4 is :", d4)
  38. print("d5 is :", d5)
  39.  
  40. x1 = max((d0+d3) % (max(d0, d1, d2)), 2)
  41. y1=max((d1+d4)%(max(d2,d3)),2)
  42. z1 = max((d2+d5) % (max(d4, d5)), 2)
  43. x0 = x1+1
  44. y0 = y1+1
  45. z0 = min(3*z1, z1+9)
  46. x2 = x1+1
  47. y2 = 0
  48. z2 = z1+1
  49. x3 = x1-1
  50. y3 = 0
  51. z3 = z1+1
  52. x4=x1
  53. y4 = 0
  54. z4 = z1-1.4
  55. xr = math.ceil(.8*x1)
  56. yr = math.floor(.6*y1)
  57. zr = z1-1
  58. print("x0 : ",x0)
  59. print("y0 : ",y0)
  60. print("z0 : ",z0)
  61. print("x1 : ",x1)
  62. print("y1 : ",y1)
  63. print("z1 : ",z1)
  64. print("x2 : ",x2)
  65. print("y2 : ",y2)
  66. print("z2 : ",z2)
  67. print("x3 : ",x3)
  68. print("y3 : ",y3)
  69. print("z3 : ",z3)
  70. print("x4 : ",x4)
  71. print("y4 : ",y4)
  72. print("z4 : ",z4)
  73. print("xr : ",xr)
  74. print("yr : ",yr)
  75. print("zr : ",zr)
  76. # # # # IN WCS co-ordinate
  77. p1 = [x1, y1, z1]
  78. p2 = [x2, y2, z2]
  79. p3 = [x3, y3, z3]
  80. p4 = [x4, y4, z4]
  81.  
  82. # # # # IN VCS
  83. p0 = [x0, y0, z0]
  84. pr = [xr, yr, zr]
  85. V = [1, 2, 0]  ### given VCS point
  86. print("p0 : ",p0)
  87. print("pr : ",pr)
  88. print("V: ",V)
  89. N = [x1 - x2 for (x1, x2) in zip(p0, pr)]
  90. print("N : ",N)
  91. # # # unit vector of n
  92. n_hat = N / np.linalg.norm(N)
  93. print("n_hat : ",n_hat)
  94. # # # # calculate the value of U
  95. U = np.cross(np.array(V), np.array(N))
  96. print("U = VxN : ",U)
  97. # # # unit vector of U
  98. u_hat = U / np.linalg.norm(U)
  99. print("u_hat : ",u_hat)
  100.  
  101. # # # Calcuate the value of small v name as v_hat
  102. v_hat = np.cross(np.array(n_hat), np.array(u_hat))
  103. print("v_hat= n x u : ",v_hat)
  104. # # # Translation Matrix:
  105. T = [[1, 0, 0, -x0], [0, 1, 0, -y0], [0, 0, 1, -z0], [0, 0, 0, 1]]
  106. print("Translation Matrix T:\n",np.matrix(T))
  107. # # # # Composite Rotation Matrix:
  108. R = [[u_hat[0], u_hat[1], u_hat[2], 0], [v_hat[0], v_hat[1], v_hat[2], 0],
  109.      [n_hat[0], n_hat[1], n_hat[2], 0], [0, 0, 0, 1]]
  110. # Print R matrix
  111. # # print('\n'.join([''.join(['{:4}'.format(item) for item in row])for row in R]))
  112. print("Composite Rotation Matrix R :\n",np.matrix(R))
  113. # # # World co-ordinate to view co-ordinate transformation
  114. M_wc_vc = np.dot(np.array(R), np.array(T))
  115. print("WC_to_VC :\n",M_wc_vc)
  116.  
  117. # # # point for view co-ordinate
  118. print("Ans of question no 1. : \n")
  119. p1.append(1)
  120. p_1v = np.dot(M_wc_vc, p1)
  121. print("p_1v :",p_1v)
  122. p2.append(1)
  123. p_2v = np.dot(M_wc_vc, p2)
  124. print("p_2v :",p_2v)
  125. p3.append(1)
  126. p_3v = np.dot(M_wc_vc, p3)
  127. print("p_3v :",p_3v)
  128. p4.append(1)
  129. p_4v = np.dot(M_wc_vc, p4)
  130. print("p_4v :",p_4v)
  131.  
  132. # # # দুইনম্বর প্রশ্নের কাহিনী শুরু
  133. # # # solution of question no 2.
  134. # # # right
  135. r = math.ceil(max(p_1v[0], p_2v[0], p_3v[0], p_4v[0])+1)
  136. print("right r:", r)
  137. # # # left
  138. l = math.floor(min(p_1v[0], p_2v[0], p_3v[0], p_4v[0])-1)
  139. print("left l:", l)
  140. # # # top
  141. t=math.ceil(max(p_1v[1],p_2v[1],p_3v[1],p_4v[1])+1)
  142. print("top t:",t)
  143.  
  144. # ##bottom
  145. b=math.floor(min(p_1v[1],p_2v[1],p_3v[1],p_4v[1])-1)
  146. print("bottom b:",b)
  147. ###near
  148. n=math.floor(max(p_1v[2],p_2v[2],p_3v[2],p_4v[2])/2)
  149. print("near n:",n)
  150.  
  151. # ##far
  152. f=math.floor(min(p_1v[2],p_2v[2],p_3v[2],p_4v[2])-2)
  153. print("far f:",f)
  154.  
  155. ###perspective projection matrix
  156.  
  157. M=[
  158.     [
  159.         (2*abs(n))/(r-l),0,(r+l)/(r-l),0
  160.     ],[
  161.         0,(2*abs(n))/(t-b),(t+b)/(t-b),0
  162.     ],[
  163.         0,0,(abs(n)+abs(f))/(abs(n)-abs(f)),(2*abs(n)*abs(f))/(abs(n)-abs(f))
  164.     ],[
  165.         0,0,-1,0
  166.     ]
  167. ]
  168. print("perspective projection matrix M :\n",np.matrix(M))
  169. p_nv=[p_1v,p_2v,p_3v,p_4v]
  170. print("p_nv : ",np.matrix(p_nv))
  171. p_hat=np.dot(M,np.array(p_nv).T)
  172. print("p_hat :\n",p_hat)
  173.  
  174. p_1n=p_hat.T[0]/p_hat.T[0][-1]
  175. p_1n=p_1n[:-1]
  176. print("p_1n :",p_1n)
  177.  
  178. p_2n=p_hat.T[1]/p_hat.T[1][-1]
  179. p_2n = p_2n[:-1]
  180. print("p_2n :",p_2n)
  181.  
  182. p_3n=p_hat.T[2]/p_hat.T[2][-1]
  183. p_3n=p_3n[:-1]
  184. print("p_3n :",p_3n)
  185.  
  186. p_4n=p_hat.T[3]/p_hat.T[3][-1]
  187. p_4n=p_4n[:-1]
  188. print("p_4n :",p_4n)
  189.  
  190.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement