Manim: How can I plot a 3D lemniscate ?

Created on 24 May 2020  路  6Comments  路  Source: 3b1b/manim

Please, I want to know how can I plot that parametric surface

I mean something like this:
cassini4b
I saw that post http://lemur.cmp.uea.ac.uk/Research/ivis/backup/PhD/Latest/Paul%20Bourke%20Screenshots/Eggs,%20melons,%20and%20peanuts%20-%20Cassini%20Oval.htm to guide me, but I can麓t understand how can I use that info. to create the parametric surface using ParametricSurface(lambda u, v: np.array([ # The parameters of that surface]))

I'll be very greatful if you can help me

I was trying with:

        lemnisBer = ParametricSurface(
                lambda u, v: np.array([
                   np.sin(u)/(1+np.cos(u)**2),
                   v,
                   (np.sin(u)*np.cos(u))/(1+np.cos(u)**2)
                ]), v_min=0, v_max=TAU, u_min=TAU, u_max=TAU, checkerboard_colors=[YELLOW_E, YELLOW_E],
                resolution=(15, 32)).scale(1.5)

But that doesn麓t graph a peanut. If you can provide me a guide or something else I麓ll be gratefull

All 6 comments

Great question BETAPANDERETA!

I'm familiar with the math so I should be able to do it. Let me give it a shot and, assuming I work it out I'll post a guide later this evening.

Stay tuned. :)

Thanks so much! I'll stay tuned 馃憤

Hi BETAPANDERETA, so there were two problems I saw with your code when I finally got back to looking at it. 1- The parametric equation you were using to try to generate the surface seemed off. 2- the u_min and u_max seemed to be set strangely.

I created a short video explanation with more details, if you're interested:

https://youtu.be/zReqQ8NMsI0

Here's source code that will work more effectively:

from manimlib.imports import *

# "foci" A controls the shape of the oval
# 0 <= foci_A <= 1.0
foci_A = .97
foci_B = 1.0

class S04_3D_Cassini_Oval(ThreeDScene):
    def parametric_CO(self, u,v):
        # equation for 2d Cassini Oval
        M = (foci_A ** 2) * np.cos(2 * u)\
        + (np.sqrt( (foci_B ** 4)-(foci_A ** 4) + ((foci_A ** 4) * (np.cos(2 * u) ** 2)) ))
        x = np.cos(u) * np.sqrt(M)
        y = np.sin(u) * np.sqrt(M)

        # 3d rotation around X axes
        z = y * np.sin(v) # be sure to calculate Z first size we modify Y
        y = y * np.cos(v)

        return np.array([x, y, z])

    def construct(self):
        # controls how many squares the approximation grid is broken into
        parametric_resolution = 24
        r_scale = 0.35

        boundaries = { "u_min": 0, "u_max": TAU,"v_min": 0, "v_max": PI}

        cassini_oval = ParametricSurface(
                self.parametric_CO, **boundaries
                , checkerboard_colors=[BLUE_C, BLUE_B], fill_opacity=0.65,
                resolution=(parametric_resolution, math.floor(parametric_resolution * r_scale))).scale(1.5)
        axes = ThreeDAxes()


        # self.set_camera_orientation(gamma = 80 * DEGREES, phi = 15 * DEGREES)
        # self.add(cassini_oval, axes)
        self.play(ShowCreation(axes))
        self.play(ShowCreation(cassini_oval))

        self.begin_ambient_camera_rotation(rate=0.6)
        # use custom camera rotation for multiple angles instead of manim standard
        # self.begin_ambient_camera_rotation_multi(rate_theta=0.8, rate_gamma=0.04, rate_phi=0.4)
        self.wait(5)

https://www.youtube.com/channel/UCgfJSRv4F86RDx8mDR-rK4Q/

https://level314.com

Oh I'm gonna prove your code! Can I use that to my project ? I give you the credits at last of my proyect of course, if you give me permission to use that.

Thanks so much for you explanation , I really appreciate!

Yes, you have my permission to use the code. Good luck with your project!

Marvelous!

ezgif com-video-to-gif

I'll close the issue. I hope that help more people

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kolibril13 picture kolibril13  路  4Comments

OGALI picture OGALI  路  3Comments

ZQiu233 picture ZQiu233  路  3Comments

purusharths picture purusharths  路  4Comments

WeiruLin picture WeiruLin  路  5Comments