How can I write the coordinates of this geometry?
5 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
Les Beckham
2022-12-30
编辑:Les Beckham
2022-12-30
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])
更多回答(1 个)
John D'Errico
2022-12-30
编辑:John D'Errico
2022-12-30
Simplest? Use a polyshape.
H = 10;
Ps0 = polyshape([0 0;0 H;H H;H 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
Easy peasy. No loops. Just few calls to polyshape to do all the hard work.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!