Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I plot a 3D lemniscate ? #1100

Closed
BETAPANDERETA opened this issue May 23, 2020 · 6 comments
Closed

How can I plot a 3D lemniscate ? #1100

BETAPANDERETA opened this issue May 23, 2020 · 6 comments

Comments

@BETAPANDERETA
Copy link

BETAPANDERETA commented May 23, 2020

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

@Level-314
Copy link

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. :)

@BETAPANDERETA
Copy link
Author

Thanks so much! I'll stay tuned 👍

@Level-314
Copy link

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

@BETAPANDERETA
Copy link
Author

BETAPANDERETA commented May 27, 2020

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!

@Level-314
Copy link

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

@BETAPANDERETA
Copy link
Author

Marvelous!

ezgif com-video-to-gif

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

eulertour pushed a commit to eulertour/manim-3b1b that referenced this issue Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants