Adding a circle in a 3D surface plot, viewed in 2D
6 ビュー (過去 30 日間)
古いコメントを表示
In the given code section, I am plotting some values as Z-coordinates in a surface plot, and then viewing it in 2D. I want to mark a circle on the same plot, given by the equation (x-13.125e-3)*(x-13.125e-3)+(y-5e-3)*(y-5e-3)=1.25e-3*1.25e-3. 'fplot' did not work, as I had assumed. How do I do it then?
figure(1)
[X,Y]=meshgrid(unique(CORD(:,1)),unique(CORD(:,2)));
surf(X,Y,damageFactorForAllNodesAtEndTimeStepReversed)
shading flat
colorbar("eastoutside")
xlabel("Length of sample")
ylabel("Width of sample")
title("Crack path at end time-step for homogeneous plate with soft inclusion")
view(2)
hold on
fplot(@(t) 1.25e-3*sin(t)+13.125e-3, @(t) 1.25e-3*cos(t)+5e-3)
If any other information is needed, do ask.
1 件のコメント
Mathieu NOE
2025 年 5 月 13 日
hello
seems the code itself should work as in this example below
we cannot run exactly your code as you don't provide the data along , but the idea in itself is fine : just be aware that your circle may be hidden partially of completely depending of it's z values vs the surf z values : demo below
surf(peaks)
shading flat
colorbar("eastoutside")
xlabel("Length of sample")
ylabel("Width of sample")
title("Crack path at end time-step for homogeneous plate with soft inclusion")
view(2)
hold on
% fplot(@(t) 5*sin(t)+13, @(t) 5*cos(t)+25,'r'); % works , full circle is visible
fplot(@(t) 5*sin(t)+18, @(t) 5*cos(t)+25,'r'); % works , but only a fraction of the circle is visible
% fplot(@(t) 5*sin(t)+25, @(t) 5*cos(t)+25,'r'); % doesn't work !! the
% circle is "below" in Z dir vs the surf object
hold off
%axis equal
採用された回答
Walter Roberson
2025 年 5 月 13 日
編集済み: Walter Roberson
2025 年 5 月 13 日
If you are using fplot() then you need to ensure that some of your Z values are below 0 in the region you are drawing the circle in, as fplot() with two function parameters draws the resulting shape all at Z = 0 but surf() draws the Z values at the Z coordinate you pass in. If the Z coordinates you pass in are above 0 then the surface completely hides the fplot() drawn lines.
[X,Y,Z] = peaks();
surf(X*0.005, Y*0.005, (Z-1)*0.001, 'edgecolor', 'none');
view(2);
hold on
fplot(@(t) 1.25e-3*sin(t)+13.125e-3, @(t) 1.25e-3*cos(t)+5e-3)
axis equal
hold off
2 件のコメント
Walter Roberson
2025 年 5 月 13 日
If you want to draw a circle "on top" of the surf() then you need to calculate the maximum Z coordinate drawn with surf(), and calculate specific X and Y coordinates for the circle and use plot3() specifying those X and Y together with a constant Z that is the maximum Z of the surf()
Walter Roberson
2025 年 5 月 13 日
Of course there is the factor that the X and Y you are providing to surf() might happen to be a fairly different scale from the coordinates calculated for the circle in fplot(), so the circle might potentially be nearly invisible compared to the surf()
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

