From: Zhen on
Hi,

This is probably a very simple question for most people but I am having trouble doing this:

I created a 3D sphere using the "sphere/surf" command and a 3D rectangle using the "patch" command. I am trying to show the two figures on the same plot using the "hold on" command but it's not working.

Is there another way to do this?

Thanks!
From: Walter Roberson on
Zhen wrote:

> This is probably a very simple question for most people but I am having
> trouble doing this:
>
> I created a 3D sphere using the "sphere/surf" command and a 3D rectangle
> using the "patch" command. I am trying to show the two figures on the
> same plot using the "hold on" command but it's not working.
>
> Is there another way to do this?

If you are using patch() _after_ surf() then you do not need to use
"hold on", as patch() is a low-level routine that always adds to the
current axis rather than defaulting to removing the current contents.

Is it possible that you have a scaling problem? If you do not specify
the x and y coordinates for surf() then they would default to be data
coordinates in the range 1 : length(x) and 1 : length(y); if you were
not expecting that then you might hypothetically have created your patch
with a coordinate system small enough that it comes out as a single pixel.

I would also double-check the axis XLim and YLim after the plotting to
ensure that both objects would be within the visible plotting surface.

When you say "it's not working" are you getting an error?
From: Zhen on
Hi Walter,

That portion of my code is:

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
%Create a spherical model
Earth_diameter = 2*6378;
[x,y,z] = sphere(25);
h1 = surf(Earth_diameter*x,Earth_diameter*y,Earth_diameter*z);
set(gca,'Color','w','XColor','b','YColor','r','ZColor','g')
set(h1,'EdgeColor',[0.5 0.5 0.5],'FaceColor','interp', 'FaceAlpha','interp');
alpha('color');
alphamap('rampdown');
camlight right;
lighting phong
hidden off
axis equal

%Create a 3D rectangular model
vert = [7128.14 7128.14 0; %1
7138.14 7128.14 0; %2
7138.14 7138.14 0; %3
7128.14 7138.14 0; %4
7128.14 7128.14 15; %5
7138.14 7128.14 15; %6
7138.14 7138.14 15; %7
7128.14 7138.14 15]; %8
fac = [1 2 3 4;
2 6 7 3;
4 3 7 8;
1 5 8 4;
1 2 6 5;
5 6 7 8];

h2 = patch('Faces',fac,'Vertices',vert,'FaceColor','r');

view(-48,26)
rotate3d on
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I am not getting an error, it's just that only the spherical earth model shows up and I can't see the 3D rectangle. I am not quite sure what you mean by a scaling error?


Walter Roberson <roberson(a)hushmail.com> wrote in message <dIlZn.6703$OU6.932(a)newsfe20.iad>...
> Zhen wrote:
>
> > This is probably a very simple question for most people but I am having
> > trouble doing this:
> >
> > I created a 3D sphere using the "sphere/surf" command and a 3D rectangle
> > using the "patch" command. I am trying to show the two figures on the
> > same plot using the "hold on" command but it's not working.
> >
> > Is there another way to do this?
>
> If you are using patch() _after_ surf() then you do not need to use
> "hold on", as patch() is a low-level routine that always adds to the
> current axis rather than defaulting to removing the current contents.
>
> Is it possible that you have a scaling problem? If you do not specify
> the x and y coordinates for surf() then they would default to be data
> coordinates in the range 1 : length(x) and 1 : length(y); if you were
> not expecting that then you might hypothetically have created your patch
> with a coordinate system small enough that it comes out as a single pixel.
>
> I would also double-check the axis XLim and YLim after the plotting to
> ensure that both objects would be within the visible plotting surface.
>
> When you say "it's not working" are you getting an error?
From: Zhen on
Ah nevermind, you're right...I found the pixel. Well it makes sense I guess since I grew the rectangle with such small dimensions.

"Zhen " <zhen.zhao6(a)gmail.com> wrote in message <i14qup$cam$1(a)fred.mathworks.com>...
> Hi Walter,
>
> That portion of my code is:
>
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
> %Create a spherical model
> Earth_diameter = 2*6378;
> [x,y,z] = sphere(25);
> h1 = surf(Earth_diameter*x,Earth_diameter*y,Earth_diameter*z);
> set(gca,'Color','w','XColor','b','YColor','r','ZColor','g')
> set(h1,'EdgeColor',[0.5 0.5 0.5],'FaceColor','interp', 'FaceAlpha','interp');
> alpha('color');
> alphamap('rampdown');
> camlight right;
> lighting phong
> hidden off
> axis equal
>
> %Create a 3D rectangular model
> vert = [7128.14 7128.14 0; %1
> 7138.14 7128.14 0; %2
> 7138.14 7138.14 0; %3
> 7128.14 7138.14 0; %4
> 7128.14 7128.14 15; %5
> 7138.14 7128.14 15; %6
> 7138.14 7138.14 15; %7
> 7128.14 7138.14 15]; %8
> fac = [1 2 3 4;
> 2 6 7 3;
> 4 3 7 8;
> 1 5 8 4;
> 1 2 6 5;
> 5 6 7 8];
>
> h2 = patch('Faces',fac,'Vertices',vert,'FaceColor','r');
>
> view(-48,26)
> rotate3d on
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
>
> I am not getting an error, it's just that only the spherical earth model shows up and I can't see the 3D rectangle. I am not quite sure what you mean by a scaling error?
>
>
> Walter Roberson <roberson(a)hushmail.com> wrote in message <dIlZn.6703$OU6.932(a)newsfe20.iad>...
> > Zhen wrote:
> >
> > > This is probably a very simple question for most people but I am having
> > > trouble doing this:
> > >
> > > I created a 3D sphere using the "sphere/surf" command and a 3D rectangle
> > > using the "patch" command. I am trying to show the two figures on the
> > > same plot using the "hold on" command but it's not working.
> > >
> > > Is there another way to do this?
> >
> > If you are using patch() _after_ surf() then you do not need to use
> > "hold on", as patch() is a low-level routine that always adds to the
> > current axis rather than defaulting to removing the current contents.
> >
> > Is it possible that you have a scaling problem? If you do not specify
> > the x and y coordinates for surf() then they would default to be data
> > coordinates in the range 1 : length(x) and 1 : length(y); if you were
> > not expecting that then you might hypothetically have created your patch
> > with a coordinate system small enough that it comes out as a single pixel.
> >
> > I would also double-check the axis XLim and YLim after the plotting to
> > ensure that both objects would be within the visible plotting surface.
> >
> > When you say "it's not working" are you getting an error?