I want to mesh a square element with a circular hole in the middle

19 ビュー (過去 30 日間)
Rawaha Nakhuda
Rawaha Nakhuda 2019 年 3 月 24 日
コメント済み: John D'Errico 2020 年 1 月 23 日
I want to discretize a unit square with a circulae hole in the middle, something similar to the picture below:
I'm having problems using the mesh function to actually create something like this. The mesh I need to create should be changable, like large meshes or small meshes for different results. Any help in creating this structure for my code would be greatly appreciated!
Capture.JPG

回答 (1 件)

John D'Errico
John D'Errico 2019 年 3 月 24 日
編集済み: John D'Errico 2019 年 3 月 24 日
Use polar coordinates.
Surely you know the equation of a circle in polar coordinates.
r = r0
What is the equation of a unit square in polar form? I think this trick may be less commonly known.
r = min(1/abs(sin(theta)), 1/abs(cos(theta)))
Scale it up for a non-unit square. So just take a linear combination of the two, at any value for theta. That will give you your mesh. Do I need to write it out?
theta = linspace(0,2*pi,17);
u = linspace(0,1,5)';
r0 = 0.5;
R = r0.*u + (1-u).*min(1./abs(sin(theta)), 1./abs(cos(theta)));
X = R.*cos(theta);
Y = R.*sin(theta);
plot(X,Y,'k-',X',Y','k-')
axis([-1.2,1.2,-1.2,1.2])
untitled.jpg
And, yes, the above code will require at least R2016b to run properly. Still fixable using an older release via bsxfun, but much cleaner this way.
(My use of plot to create the meshed grid there was kind of cute, I think.)
  3 件のコメント
Hukum Dewangan
Hukum Dewangan 2020 年 1 月 23 日
Can you help me to plot surface using the same meshgrid? As of now, I could not get the hole in the final surface plot.
John D'Errico
John D'Errico 2020 年 1 月 23 日
@Hukum Dewangan - that is a different problem, but still not difficult. If you have a problem, ask the questoin separately. Otherwise, this turns into an extended consulting session in the comments, leading to all sorts of followup questions, and I will not participate in that.
If you do ask a question, then show what you tried, explain why you think it failed for you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by