How can I write the coordinates of this geometry?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Maram
am 30 Dez. 2022
Kommentiert: Maram
am 15 Jan. 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);
0 Kommentare
Akzeptierte Antwort
Les Beckham
am 30 Dez. 2022
Bearbeitet: Les Beckham
am 30 Dez. 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 Kommentare
Weitere Antworten (1)
John D'Errico
am 30 Dez. 2022
Bearbeitet: John D'Errico
am 30 Dez. 2022
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.
Siehe auch
Kategorien
Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!