Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
surface/lighting problem

Subject: surface/lighting problem

From: pouncingmoose@gmail.com

Date: 11 Jun, 2009 23:29:31

Message: 1 of 3

I'm hoping that someone more knowledgeable than myself on MATLAB's 3D
graphics might be able to help overcome the following problem:

I have some data for a spheroid that I need to apply a texture to,
however when I visualize it the sphere it has an ugly "seam" down the
side that I can't find a way to remove.
The following code generates a sphere that when rotated (manually)
looks fine:

close all
[X,Y,Z] = sphere(10);
he = surface(X,Y,Z,'LineStyle','none');
shading interp
rotate3d on
view(3);
axis equal
grid on
box on
xlabel('x');ylabel('y');zlabel('z');
set(gca,'Color',get(gcf,'Color'));

However if I then add some lighting with the following 2 lines:

light('Position',[-0.05 -0.7 1.6],'Style','infinite');
lighting phong

then the image has an ugly seam down the y-axis where the data wraps.
How can I get rid of this seam?

I've tried generating the sphere using (a single call to) patch, and
that works (i.e. the seam doesn't show), but unfortunately patch
doesn't allow for a texture map to be applied.

Any suggestions would be appreciated.

Subject: surface/lighting problem

From: Andres

Date: 12 Jun, 2009 19:46:02

Message: 2 of 3

"pouncingmoose@gmail.com" <pouncingmoose@gmail.com> wrote in message <7565cf0d-4f8b-44f8-8121-9daa9bb6e7f5@p5g2000pre.googlegroups.com>...
> I'm hoping that someone more knowledgeable than myself on MATLAB's 3D
> graphics might be able to help overcome the following problem:
>
> I have some data for a spheroid that I need to apply a texture to,
> however when I visualize it the sphere it has an ugly "seam" down the
> side that I can't find a way to remove.
> The following code generates a sphere that when rotated (manually)
> looks fine:
>
> close all
> [X,Y,Z] = sphere(10);
> he = surface(X,Y,Z,'LineStyle','none');
> shading interp
> rotate3d on
> view(3);
> axis equal
> grid on
> box on
> xlabel('x');ylabel('y');zlabel('z');
> set(gca,'Color',get(gcf,'Color'));
>
> However if I then add some lighting with the following 2 lines:
>
> light('Position',[-0.05 -0.7 1.6],'Style','infinite');
> lighting phong
>
> then the image has an ugly seam down the y-axis where the data wraps.
> How can I get rid of this seam?
>
> I've tried generating the sphere using (a single call to) patch, and
> that works (i.e. the seam doesn't show), but unfortunately patch
> doesn't allow for a texture map to be applied.
>
> Any suggestions would be appreciated.


When calculating the vertex normals of your sphere, matlab does not consider it could be closed. To get rid of the seam you could average the vertex normals of both sides of the seam. In order to do so, add the following lines to your code:

vn = get(he,'VertexNormals');
vnSeam = mean(vn(:,[1,end],:),2);
vnNew = vn;
vnNew(:,[1,end],:) = repmat(vnSeam,[1 2 1]);
set(he,'VertexNormals',vnNew);

Subject: surface/lighting problem

From: pouncingmoose@gmail.com

Date: 12 Jun, 2009 21:32:27

Message: 3 of 3


Perfect.
Thanks.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us