Guest User

Untitled

a guest
Jan 28th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. from manim import *
  2. import numpy as np
  3. import random
  4.  
  5. class newVectorScene(ThreeDScene):
  6. def construct(self):
  7.  
  8. self.camera.set_focal_distance(50)
  9. amplitudeAxes = ThreeDAxes(
  10. x_range = [-1,1,1],
  11. y_range = [-1,1,1],
  12. z_range = [-1,1,1],
  13. x_length = 3.5,
  14. y_length = 3.5,
  15. z_length = 3.5,
  16. tips=False,
  17. ).shift(LEFT*5)
  18.  
  19. amplitudeLabels = VGroup(
  20. MathTex(r'\uparrow').scale(1.2).next_to(amplitudeAxes[1], UP),
  21. MathTex(r'\downarrow').scale(1.2).next_to(amplitudeAxes[0], RIGHT),
  22. )
  23.  
  24. shadeIn3D = False
  25. amplitudeVectorUp = Arrow(amplitudeAxes.c2p(0, 0, 0), amplitudeAxes.c2p(0, 1, 0), buff=0,
  26. color=BLUE, shade_in_3d=shadeIn3D)
  27. amplitudeVectorDown = Arrow(amplitudeAxes.c2p(0, 0, 0), amplitudeAxes.c2p(1, 0, 0), buff=0,
  28. color=ORANGE, shade_in_3d=shadeIn3D)
  29.  
  30. amplitudeGroup = VGroup(amplitudeAxes,amplitudeLabels,amplitudeVectorUp,amplitudeVectorDown)
  31. amplitudeGroup.rotate(-TAU / 8, axis=np.array([0, np.cos(TAU / 12), np.sin(TAU / 12)])).scale(1.3)
  32.  
  33. conceptualArrow = Arrow(start=LEFT, end=RIGHT).next_to(amplitudeGroup).next_to(amplitudeGroup).shift(DOWN*0.7)
  34.  
  35. upText = MathTex(r'Up =').next_to(conceptualArrow).shift(UP*1.5).set_color(BLUE)
  36.  
  37. upColumn = Matrix(
  38. [[1],[0]],
  39. left_bracket='(',
  40. right_bracket=')',
  41. bracket_h_buff=0.1
  42. ).next_to(upText).shift(UP*0.095).set_color(BLUE)
  43.  
  44. downText = MathTex(r'Down =').next_to(upColumn).shift(RIGHT*1.5).set_color(ORANGE)
  45.  
  46. downColum = Matrix(
  47. [[0],[1]],
  48. left_bracket='(',
  49. right_bracket=')',
  50. bracket_h_buff=0.1
  51. ).next_to(downText).shift(UP*0.095).set_color(ORANGE)
  52.  
  53. newText = MathTex(r'New \; vector? =').next_to(conceptualArrow).shift(DOWN*1.5+RIGHT*1.2).set_color('#4E9843')
  54.  
  55. newColumn = Matrix(
  56. [['a'],['b']],
  57. left_bracket='(',
  58. right_bracket=')',
  59. bracket_h_buff=0.1
  60. ).next_to(newText).shift(UP*0.095).set_color('#4E9843')
  61.  
  62. mathGroup = VGroup(upText,upColumn,downText,downColum,newText,newColumn)
  63.  
  64. self.add(amplitudeGroup,conceptualArrow)
  65. self.wait()
  66.  
  67. self.play(
  68. ReplacementTransform(amplitudeVectorUp.copy(),mathGroup[0:2]),
  69. ReplacementTransform(amplitudeVectorDown.copy(), mathGroup[2:4]),
  70. )
  71. self.wait()
  72.  
  73. amplitudeVectorI = Arrow(amplitudeAxes.c2p(0, 0, 0), amplitudeAxes.c2p(0, 0, 1), buff=0,
  74. color='#4E9843', shade_in_3d=shadeIn3D)
  75.  
  76. self.play(
  77. Indicate(mathGroup[4:6],color='#4E9843',scale_factor=1.5),
  78. Indicate(amplitudeVectorI,color='#4E9843',scale_factor=1.5)
  79. )
  80. self.wait()
  81.  
  82. self.play( Rotate( amplitudeVectorI,-PI/2, about_point=amplitudeAxes.c2p(0, 0, 0), axis=amplitudeVectorDown.get_end() ) )
  83. self.wait()
  84.  
Advertisement
Add Comment
Please, Sign In to add comment