3b1b / manim

Animation engine for explanatory math videos
MIT License
60.28k stars 5.7k forks source link

3D rotations of a function about an axis #973

Open nakulkhambhati opened 4 years ago

nakulkhambhati commented 4 years ago

I recently installed Manim and am using it to visualise solids of revolution. I figured out how to construct 3D parametric surfaces, but am still struggling to rotate a function. I saw the code from a few of 3b1b's videos and could rotate 3D objects about points. Can someone help me out with the code to animate the rotation of the function y=x^2 about the x axis?

`class RotationsIn3d(ThreeDScene): def construct(self): self.set_camera_orientation(phi=80 DEGREES,theta=-60DEGREES) self.begin_ambient_camera_rotation(rate=0.02) curve1=ParametricFunction( lambda u : np.array([ 2*u*2, 4u, 0 ]),color=RED,t_min=0,t_max=1, ) axes = ThreeDAxes()

    self.add(axes)
    self.play(Write(curve1))
    angle_axis_pairs = [
        (90 * DEGREES, RIGHT),
        (90 * DEGREES, UP),
        (90 * DEGREES, IN),
    ]

    self.play(Rotate(curve1,90*DEGREES, about_edge = Y_AXIS))

    self.wait()`

This is what I have as of now. I thought that the "about_edge" method would work but it didn't.

kolibril13 commented 4 years ago

Hii, this is how you can do it:

class RotationsIn3d(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=80 * DEGREES, theta=-60 * DEGREES)

        def func():
            param = ParametricFunction(
                lambda u: np.array([
                    2 * u ** 2,
                    4 * u,
                    0
                ]), color=RED, t_min=0, t_max=1)
            return param
        curve1 = func()
        curve2 = curve1.copy()
        def update_curve(d,dt):
            d.rotate_about_origin(dt, RIGHT)
        curve2.add_updater(update_curve)
        axes = ThreeDAxes()
        self.add(curve1,curve2)
        self.add(axes)
        self.wait(2*PI)

output