Effacer les filtres
Effacer les filtres

Problem plotting Möbius strip

9 vues (au cours des 30 derniers jours)
John Klint
John Klint le 6 Mar 2017
Modifié(e) : Neil le 8 Avr 2023
Hi, I am playing around with Möbius strips in Matlab and had a strange problem I cannot resolve. I am only interested in vectorized solutions, not for- or while-loops, please. The graph almost looks like a Möbius strip, but the edges are not joined. Can anyone see what the problem is?
Code below:
%Begin
clf
clear all
u = linspace(0,2*pi,100);
v = linspace(-0.5,0.5,100);
%Parametrization, vectorized
x=cos(u)'+diag((diag(v)*cos(u/2)'))*cos(u)';
y=sin(u)'+diag((diag(v)*cos(u/2)'))*sin(u)';
z=v'*sin(u/2);
%Plotting: figure 1 and 2 are quite a lot off. figure 3 almost looks like a
%Moebius strip except the edges are not joined.
figure(1)
surf(x,y,z)
figure(2)
mesh(x,y,z)
figure(3)
plot3(x,y,z)
%Code that works and actually produce a Moebius strip
syms e r;
s = cos(e)+r*cos(e/2)*cos(e);
d = sin(e)+r*cos(e/2)*sin(e);
f = r*sin(e/2);
figure(4)
ezsurf(s,d,f, [0, 2*pi, -0.5, 0.5])

Réponse acceptée

Rahul Kalampattel
Rahul Kalampattel le 7 Mar 2017
Use meshgrid to generate matrices for both your parameters, rather than using vectors.
u = linspace(0,2*pi,100);
v = linspace(-0.5,0.5,100);
[u,v] = meshgrid(u,v);
Now that u and v are matrices, you don't have to worry about transposing or using diag etc. Leave the parametric equations in their explicit form (i.e. don't expand the brackets), remember to use element-wise multiplication, and everything works out.
x = (1+v.*cos(u/2)).*cos(u);
y = (1+v.*cos(u/2)).*sin(u);
z = v.*sin(u/2);
  2 commentaires
John Klint
John Klint le 7 Mar 2017
Thanks, great answer :)
Neil
Neil le 8 Avr 2023
Modifié(e) : Neil le 8 Avr 2023
Thank you for this example. I was trying to work out how to plot my version of a Klein Strip (which is a 4D equivalent of a Mobius Strip and similar to a Klein Bottle though more symmetric). Your example simplified the whole process for me. Very much appreciated.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Data Plots dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by