How can I write the coordinates of this geometry?

4 views (last 30 days)
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);

Accepted Answer

Les Beckham
Les Beckham on 30 Dec 2022
Edited: Les Beckham on 30 Dec 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])

More Answers (1)

John D'Errico
John D'Errico on 30 Dec 2022
Edited: John D'Errico on 30 Dec 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.

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!