Understanding implicit surface plot behavior

3 次查看(过去 30 天)
Here is some code that plots an implicit infinite, tilted cylinder.
Q=diag([0,1,1]./3^2);
axis([-5 5 -5 5 -5 5])
h1=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,'EdgeColor','none','FaceAlpha',0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform('axisrotate',[0 1 0],pi/4);
h1.Parent=hgtransform('Matrix',T);
My first question is, why doesn't the cylinder, which is infinite, extend to the axis limits?
My second question is, below is the same code again, except at the very end, we double the extent of the axes. Why does the cylinder become invisible when this is done?
figure;
axis([-5 5 -5 5 -5 5])
h2=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,'EdgeColor','none','FaceAlpha',0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform('axisrotate',[0 1 0],pi/4);
h2.Parent=hgtransform('Matrix',T);
axis([-5 5 -5 5 -5 5]*2) %<----makes the cylinder disappear!
function d=quadform(x,y,z, Q)
xyz=[x(:).'; y(:).'; z(:).'];
d=reshape( (sum((Q*xyz).*xyz)-1), size(x));
end

采纳的回答

Matt J
Matt J 2024-5-15
移动:Matt J 2024-5-15
Re-running the code in the latest release, R2024a, it appears the problem has been fixed.
Q=diag([0,1,1]./3^2);
axis([-5 5 -5 5 -5 5])
h1=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,'EdgeColor','none','FaceAlpha',0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform('axisrotate',[0 1 0],pi/4);
h1.Parent=hgtransform('Matrix',T);
figure;
axis([-5 5 -5 5 -5 5])
h2=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,'EdgeColor','none','FaceAlpha',0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform('axisrotate',[0 1 0],pi/4);
h2.Parent=hgtransform('Matrix',T);
axis([-5 5 -5 5 -5 5]*2) %<----makes the cylinder disappear!
function d=quadform(x,y,z, Q)
xyz=[x(:).'; y(:).'; z(:).'];
d=reshape( (sum((Q*xyz).*xyz)-1), size(x));
end

更多回答(1 个)

Nipun
Nipun 2024-5-14
Hi Matt,
Your observations touch on how MATLAB handles the rendering of implicit functions and the effects of axis scaling on graphical objects, particularly those transformed with hierarchical transformations like hgtransform.
The two sections below highlight the questions asked:
1. Finite Rendering of Infinite Shapes
The cylinder doesn't extend to the axis limits because fimplicit3 renders shapes within a finite bounding box based on the current axis limits for visualization, despite the theoretical shape being infinite.
2. Cylinder Becomes Invisible After Doubling Axis Limits
The cylinder becomes invisible because fimplicit3 generates a mesh based on the axis limits at the time of plotting. Expanding the axis limits afterwards doesn't recalculate this mesh. The transformation applied (hgtransform) affects the object's position and orientation but doesn't adjust the mesh to fit the new axis limits, causing the object to potentially fall outside the visible rendering area.
Below, I recommend a potential solution to address the issue.
Solution: To ensure visibility after changing axis limits, re-plot the cylinder with the new axis limits set beforehand. This approach makes MATLAB generate the mesh according to the updated viewport, ensuring the object remains visible.
Hope this helps.
Regards,
Nipun
  1 个评论
Matt J
Matt J 2024-5-15
编辑:Matt J 2024-5-15
The cylinder doesn't extend to the axis limits because fimplicit3 renders shapes within a finite bounding box based on the current axis limits for visualization
Yes, but shouldn't it at least extend to the limits of that box? It doesn't seem to in my OP.
The cylinder becomes invisible because fimplicit3 generates a mesh based on the axis limits at the time of plotting. Expanding the axis limits afterwards doesn't recalculate this mesh.
I think it must recalculate the mesh. The fact that the surface can redraw itself is the whole point of it being an ImplicitSurface object instead of a run-of-the-mill meshplot. In the modified example below ,(with no rotation of the cylinder) changing the axis limits does indeed redraw the cylinder to fill the larger bounding box:
Q=diag([0,1,1]./3^2);
figure;
axis([-5 5 -5 5 -5 5])
h2=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,'EdgeColor','none','FaceAlpha',0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform('axisrotate',[0 1 0],0);
h2.Parent=hgtransform('Matrix',T);
axis([-5 5 -5 5 -5 5]*2) %<----makes the cylinder disappear!
function d=quadform(x,y,z, Q)
xyz=[x(:).'; y(:).'; z(:).'];
d=reshape( (sum((Q*xyz).*xyz)-1), size(x));
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by