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

Möbius strip example #249

Closed
deeplook opened this issue May 2, 2019 · 14 comments
Closed

Möbius strip example #249

deeplook opened this issue May 2, 2019 · 14 comments

Comments

@deeplook
Copy link

deeplook commented May 2, 2019

I wanted to play more with meshes and triangulations and found the included Klein bottle example to be slightly overwhelming, so I've made one for the Möbius strip, see this gist: https://gist.github.com/deeplook/9c76c4fde7f13c52580ac824e86c5c5e.

So I wouldn't mind contributing this to ipyvolume if it is considered useful. What I'm still struggling though is to make the Möbius strip render texture images like the Klein bottle example does so nicely. If anybody can help with that I'd appreciate very much.

Screenshot 2019-05-02 at 11 44 14

@GenevieveBuckley
Copy link
Contributor

Can you link to the textured klein bottle example?

I can't get image textures working with plot_trisurf() either. I am able to run the example for image textures with plot_mesh() here. Both plot_mesh and plot_trisurf rely on the ipyvolume Mesh class, so the difference in behaviour is odd. I'm wondering if there is actually a bug here, or if better documentation is needed?

@maartenbreddels
Copy link
Collaborator

Hi,

@deeplook this would be great to put in one of the examples as well.
@GenevieveBuckley you cannot get that sample code I provided to work, could you open an issue for that?

cheers,

MAarten

@rpanai
Copy link
Contributor

rpanai commented Jun 23, 2019

Maybe I'm doing something wrong but it seems to me this renders pretty well

def moebius(draw=True, show=True, figure8=False, endpoint=True,
                     uv=True, wireframe=False, texture=None):
    import ipyvolume.pylab as p3
    # http://paulbourke.net/geometry/klein/
    u = np.linspace(0, 2 * pi, num=40, endpoint=endpoint)
    v = np.linspace(-0.4, 0.4, num=40, endpoint=endpoint)
    u, v = np.meshgrid(u, v)
    x = cos(u) + v * cos(u/2) * cos(u)
    y = sin(u) + v * cos(u/2) * sin(u)
    z = v * sin(u/2)
    if draw:
        if texture:
            uv = True
        if uv:
            mesh = p3.plot_mesh(x, y, z, wrapx=not endpoint, wrapy=not endpoint, u=u/(2*np.pi), v=v/(2*np.pi), wireframe=wireframe, texture=texture)
        else:
            mesh = p3.plot_mesh(x, y, z, wrapx=not endpoint, wrapy=not endpoint, wireframe=wireframe, texture=texture)
        if show:
            p3.squarelim()
            p3.show()
        return mesh
    else:
        return x, y, z, u, v

@deeplook
Copy link
Author

@rpanai I'm going to take this code with microscopic changes and create a PR to add it to the existing examples, after having spoken to @maartenbreddels. If you prefer doing it yourself, please let me know...

@rpanai
Copy link
Contributor

rpanai commented Mar 30, 2020

@deeplook I'd like to do it. Which changes are you suggesting?

@deeplook
Copy link
Author

It could simply go into ipyvolume/examples.py, but @maartenbreddels suggested on gitter to add it to the documentation, too, which would make sense, but it uses nbsphinx which I haven't used yet. I guess you could add it to ipyvolume/examples.py in a first step, which I hope is ok with @maartenbreddels?

ATM I have something like this, notice the "ö" ;)

from numpy import pi, cos, sin, linspace, meshgrid
import ipyvolume.pylab as p3

def möbius(draw=True, show=True, num=40, endpoint=True,
           uv=True, wireframe=False, texture=None):
    # http://paulbourke.net/geometry/toroidal
    u = linspace(0, 2 * pi, num=num, endpoint=endpoint)
    v = linspace(-0.4, 0.4, num=num, endpoint=endpoint)
    u, v = meshgrid(u, v)
    x = cos(u) + v * cos(u / 2) * cos(u)
    y = sin(u) + v * cos(u / 2) * sin(u)
    z = v * sin(u / 2)
    if draw:
        if texture:
            uv = True
        kwargs = dict(wrapx=not endpoint, wrapy=not endpoint,
                      wireframe=wireframe, texture=texture)
        if uv:
            kwargs.update(dict(u=u/(2*pi), v=v/(2*pi)))
        mesh = p3.plot_mesh(x, y, z, **kwargs)
        if show:
            p3.squarelim()
            p3.show()
        return mesh
    else:
        return x, y, z, u, v
    
mesh = möbius()

@maartenbreddels
Copy link
Collaborator

After #299 is in, an example notebook with a screenshot would be nice.

@rpanai
Copy link
Contributor

rpanai commented Mar 30, 2020

@deeplook I do agree möbius will be nicer but I'm not sure it's a good idea to use accents.

@deeplook
Copy link
Author

@rpanai If it's considered an example in the sense that it only illustrates how to use the core, but does not expect anybody to use it as-is, it might be an ok way to help Python 2 die a little faster (oh I see ipyvolume specifies 2.7 explicitly...).

One might argue not enough people have these characters ready on their keybords, but then the name can also be tab-completed in any decent IDE... ;)

@maartenbreddels
Copy link
Collaborator

I think this example would go better in a notebook, since the code is a bit more visible, I've added some instructions https://ipyvolume.readthedocs.io/en/latest/examples.html how to add an example.
I'll soon add one as well.

@deeplook
Copy link
Author

@maartenbreddels I agree it's more visible, but at the same time it's also less reusable because it cannot be imported from the code base. If we want that, too, we have to import very clean code (like single functions) inside the notebooks from some example collection, maybe using %load cell magics, but could still add additional prose/code.

As an aside I've just created #302, where this reuse aspect might not be as dominant. Maybe for the Möbius example that's a bit different, because there's not much to configure for it...

@deeplook
Copy link
Author

deeplook commented Apr 6, 2020

I guess we cab close this, although it would be nice to have a GIF screenshot in the example notebook, too, maybe.

@maartenbreddels
Copy link
Collaborator

Solved by #301 which is included in https://ipyvolume.readthedocs.io/en/latest/examples.html

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

4 participants