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

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
vertex normals Andres 12 Jun, 2009 15:49:08
lighting Andres 12 Jun, 2009 15:49:08
surface Andres 12 Jun, 2009 15:49:08
surf Andres 12 Jun, 2009 15:49:08
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com