I am trying to draw a squircle with a given height and width as I need to approximate a rounded rectangle using a function. I have tried to use both equations for a squircle that wikipedia has recomended and while I think I would prefer the Fernández-Guasti squircle I have gotten further with the ellipse based squircle (which I can also get to work on Mathematica) but the best plot I have gotten so far resembles an exponential decay. The input I'm using at this point is below...
Make appropriate changes to the ‘r’ and ‘s’ parameters to get the result you want.
See the documentation on contour to understand why it works here. Specifically see M — Contour matrix for an explanation of the ‘x_squircle’ and ‘y_squircle’ vectors.
Awesome! I've got this working and drawing my shape, but you could help me understand this more, I'd appreciate it. Just so that you know, I particularly need to know the (x,y) cordinates of the points around the shape so that I can for lack of my vocabulary put the shape through various transfrormations and replot it along the way, so....
From what I understand when reading about the contour funtion, obviously the first few steps define variable and setup vectors with the range of variable for the x,y axis, then the ngrid step defines the area that we are working in. Now you setup a function (not very familiar with this I'll be honest, as in I've never used an @ in MATLAB). Figure prepares MATLAB for a figure. then we define matrix 'c' which is filled in by the contour feature.
I understand that this creates a matrix, but I think I fully understand what the values filling the matric mean. As in what are/why are the different levels, and if the susequent numbers are the (x,y) cordinates for my shape, could I create a vector each for just my x's and y's? Really I think that's what you've done with the x,y_squircle comands, but I want to make sure, especially as those come before we add the scaling and really I need the values for the target shape.
Thank you for your patience, and of course all the help.
I am not certain that I can elaborate further than I already have with the comment-documentation.
The ndgrid call forms matrices from the previously-defined vectors. That is necessary for the contour function. See the contour documentation (that I already linked to) to understand what they mean.
The ‘squircle_fcn’ is an anonymous function. See the documentation on Anonymous Functions for details. The documentation explains them better than I could. It uses vectorised operations, so see the documentation on Array vs. Matrix Operations for those details.
The ‘x_squircle’ and ‘y_squircle’ vectors are the x- and y-coordinates (respectively) returned by the contour function for the [0 0] contour. This essentially evaluates an implicit function (a multivariate function that equals zero) at the [0 0] contour.
The ‘x_squircle’ and ‘y_squircle’ vectors are evaluated for the ‘X’ and ‘Y’ matrices and the previously defined ‘s’ and ’r’ values. The Wikipedia article indicates that the ‘squircle’ is symmetric about the origin, so the scaling simply multiplies the x- and y-dimensions to create the desired shape.
If my Answer helped you solve your problem, please Accept it!
Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.
Translated by
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.