How can I write the coordinates of this geometry?

12 visualizaciones (últimos 30 días)
Maram
Maram el 30 de Dic. de 2022
Comentada: Maram el 15 de En. de 2023
Hello there,
I have to input the coordinates of this shape in a matlab code as an array of one row, to be used later in solving a BEM problem. I have managed to get the points of the curved parts, but I am not sure how to compile the points all togther (the 4 corner points and the curved points in a counter clockwise direction).
last value before the last value
(0,h) (h,h)
(0,0) (h,0)
first value second value
This is the code I tried to formulate,
h= 10;
xc=zeros;
yc=zeros;
%the left side
th = linspace( pi/2, -pi/2, 100);
R = (h/4); %or whatever radius you want
x1 = R*cos(th) ;
y1=(h/4);
y1 = y1+ R*sin(th) + (h/4) ;
% plot(x1,y1); axis equal;
%the right side
x2 = - R*cos(th)+ h;
y2=(h/4);
y2= y2+ R*sin(th) + (h/4);
% plot(x2,y2); axis equal;
j=0;
k=0;
for i=1:204
if i==1
yc(i)= 0;
xc(i)= 0;
elseif i==2
yc(i)= 0;
xc(i)= h;
elseif i> 2 && i<104
xc(i) = xc(i) + x2(j);
yc(i) = yc(i) + y2(j);
j= j+1
elseif i ==104
yc(i)= h;
xc(i)= h;
elseif i==105
yc(i)= h;
xc(i)= 0;
else
xc(i) = xc(i) + x1(k);
yc(i) = yc(i) + y1(k);
k= k+1
end
end
I am getting this error,
Index exceeds the number of array elements (2).
Error in checkingGeometry (line 29)
xc(i) = xc(i) + x2(j);

Respuesta aceptada

Les Beckham
Les Beckham el 30 de Dic. de 2022
Editada: Les Beckham el 30 de Dic. de 2022
You don't need a loop.
h = 10;
th = linspace(pi/2, -pi/2, 100);
R = (h/4); %or whatever radius you want
x1 = R*cos(th) ;
y1=(h/4);
y1 = y1+ R*sin(th) + (h/4) ;
% plot(x1,y1); axis equal;
%the right side
x2 = - R*cos(th)+ h;
y2=(h/4);
y2= y2+ R*sin(th) + (h/4);
% plot(x2,y2); axis equal;
% add the corners
y = [0 0 flip(y2) h h y1 0];
x = [0 h flip(x2) h 0 x1 0];
plot(x,y)
axis equal
grid on
xlim([-1 11])
ylim([-1 11])
  2 comentarios
Maram
Maram el 30 de Dic. de 2022
Thank you!
Les Beckham
Les Beckham el 30 de Dic. de 2022
You are quite welcome. Glad I could help.

Iniciar sesión para comentar.

Más respuestas (1)

John D'Errico
John D'Errico el 30 de Dic. de 2022
Editada: John D'Errico el 30 de Dic. de 2022
Simplest? Use a polyshape.
H = 10;
Ps0 = polyshape([0 0;0 H;H H;H 0])
Ps0 =
polyshape with properties: Vertices: [4×2 double] NumRegions: 1 NumHoles: 0
plot(Ps0)
Next, create a pair of circles.
t = linspace(0,2*pi,250)';
t(end) = [];
p = 2; % radius of the semi-circular cutout
C = p*[cos(t),sin(t)];
PsC1 = polyshape(C + [0,H/2]); % semi-circle, centered along each edge
PsC2 = polyshape(C + [H,H/2]);
Psfinal = subtract(subtract(Ps0,PsC1),PsC2);
plot(Psfinal)
axis equal
You can extract the points trivially.
XYpoly = Psfinal.Vertices
XYpoly = 257×2
0 0 0.0000 3.0001 0.0126 3.0000 0.0631 3.0010 0.1135 3.0032 0.1638 3.0067 0.2141 3.0115 0.2642 3.0175 0.3141 3.0248 0.3639 3.0334
Easy peasy. No loops. Just few calls to polyshape to do all the hard work.

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by