Reputation: 1102
I first created a figure with the background as a .png image. Then I created a 3D axes on top of the figure so that the 3D axes is placed on top of the .png image. Note that the .png image is not set inside of the 3D axes but is set outside of the axes in the figure itself.
I have a 3D .stl file of an apple set inside of the 3D axes (you can't see the apple by the way). When I move the apple around inside the 3D axes, using the option from the builtin Matlab figure toolbar, it works fine. But the problem here is that when I move the apple outside of the borders of the 3D axes, it disappears.
To tackle this problem, I want to set the size of the 3D axes so that its limits go outside of the figure, so that I can move my apple around anywhere in the figure without being limited to the size of the 3D axes. Note: I didn't make the 3D axes invisible, so that it is easier for people to understand my question. But when this problem is solved I will use axis off
to make the 3D axes invisible, while retaining and displaying the apple.
pearImage = 'pears.png';
appleModel = 'apple.stl';
backgroundImage = imread(pearImage);
[vertices,faces,~] = stlRead(appleModel);
axesHandle = axes('unit','normalized','position',[0 0 1 1]);
imagesc(backgroundImage)
set(axesHandle,'handlevisibility','off','visible','off')
uistack(axesHandle,'bottom')
stlPlot(vertices,faces)
Here is the function for stlPlot()
function stlPlot(vertices,faces)
object.vertices = vertices;
object.faces = faces;
patch(object,'FaceColor',[0.1 1.0 1.0],'EdgeColor','none')
camlight('headlight')
material('dull')
axis('image')
view([-135 35])
axis off % used to make the 3D axes invisible
I got the stlRead()
and stlPlot()
functions from here: https://kr.mathworks.com/matlabcentral/fileexchange/22409-stl-file-reader?focused=5193625&tab=function. Note that I edited the stlPlot()
function to fit my purpose.
Upvotes: 2
Views: 172
Reputation: 125854
I believe you can solve this problem by changing the 'Clipping'
property of the patch objects you create:
hPatch = patch(object, 'FaceColor', [0.1 1.0 1.0], 'EdgeColor', 'none', 'Clipping', 'off');
Or, more simply, you could probably just set the 'Clipping'
property of the parent axes object itself (which controls clipping behavior for all of its children):
set(get(hPatch, 'Parent'), 'Clipping', 'off');
Upvotes: 1