Equations or code that can generate shapes

I have x and y coordinates of a n*2n grid fixed grid. I have generated circular shape (circle.JPG) with
sqrt((x-cx).^2 +(y-cy).^2)-r, where (cx, cy) are the centre and r is the radius of the circle
I have generated elliptical shape (ellipse.JPG) with
((x-cx)/a).^2 +((y-cy)/b).^2)-1, where (cx, cy) are the centre and a is the horizontal radius and b is the vertical radius of the ellipse
I need a code that can generate each of the following shapes in the picture (Picture_1.jpg).
Thank you so much.

6 comentarios

jonas
jonas el 13 de Oct. de 2018
Editada: jonas el 13 de Oct. de 2018
It seems you already know how polyshapes work, so what's the problem?
SAMUEL AYINDE
SAMUEL AYINDE el 13 de Oct. de 2018
Editada: SAMUEL AYINDE el 13 de Oct. de 2018
@jonas,I do not know how to generate the shapes in Picture_1.Thank you so much.
jonas
jonas el 13 de Oct. de 2018
Well do you have coordinates for the corner points?
SAMUEL AYINDE
SAMUEL AYINDE el 13 de Oct. de 2018
The domain is 2*1. The height is 2 and the width is 1. So, by discretizing with 8*4 fixed grid in the picture, the coordinate of the corners are ((0,0.5), (0,0.75), (2,0.5), (2,0.75))It is a signed distance function.
Image Analyst
Image Analyst el 13 de Oct. de 2018
And you were not able to adapt the code I gave below???
SAMUEL AYINDE
SAMUEL AYINDE el 13 de Oct. de 2018
Editada: SAMUEL AYINDE el 13 de Oct. de 2018
No, I do not know how to adapt it. For convenience, find the attached signeddistance.m file for you to get a better understanding of what I am talking about. The attached code can generate the shape for rectangle, ellipse and circle using signed distance if you run the portion corresponding to each shape. I need a code that can give the shapes in the picture above using signed distance. Thank you so much.
I have posed the question in a better way here:
https://www.mathworks.com/matlabcentral/answers/423827-matlab-code-for-generating-some-shapes-using-signed-distance

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 13 de Oct. de 2018
Try this:
period = 10;
amplitude = 4;
offset = 6;
x = linspace(0, 40, 700);
y = amplitude * cos(2 * pi * x / period) + offset;
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
ylim([0, amplitude + offset]);
For the triangle wave, use sawtooth() or repmat(). I'm sure you can figure it out because you're a smart engineer.

Categorías

Más información sobre Interpolation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 13 de Oct. de 2018

Editada:

el 13 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by