-
Notifications
You must be signed in to change notification settings - Fork 233
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
Comments
Can you link to the textured klein bottle example? I can't get image textures working with |
Hi, @deeplook this would be great to put in one of the examples as well. cheers, MAarten |
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 |
@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... |
@deeplook I'd like to do it. Which changes are you suggesting? |
It could simply go into 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() |
After #299 is in, an example notebook with a screenshot would be nice. |
@deeplook I do agree möbius will be nicer but I'm not sure it's a good idea to use accents. |
@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... ;) |
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. |
@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 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... |
I guess we cab close this, although it would be nice to have a GIF screenshot in the example notebook, too, maybe. |
Solved by #301 which is included in https://ipyvolume.readthedocs.io/en/latest/examples.html |
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.
The text was updated successfully, but these errors were encountered: