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!

