<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/253495</link>
    <title>MATLAB Central Newsreader - surface/lighting problem</title>
    <description>Feed for thread: surface/lighting problem</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 11 Jun 2009 23:29:31 -0400</pubDate>
      <title>surface/lighting problem</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/253495#656587</link>
      <author>pouncingmoose@gmail.com</author>
      <description>I'm hoping that someone more knowledgeable than myself on MATLAB's 3D&lt;br&gt;
graphics might be able to help overcome the following problem:&lt;br&gt;
&lt;br&gt;
I have some data for a spheroid that I need to apply a texture to,&lt;br&gt;
however when I visualize it the sphere it has an ugly &quot;seam&quot; down the&lt;br&gt;
side that I can't find a way to remove.&lt;br&gt;
The following code generates a sphere that when rotated (manually)&lt;br&gt;
looks fine:&lt;br&gt;
&lt;br&gt;
close all&lt;br&gt;
[X,Y,Z] = sphere(10);&lt;br&gt;
he = surface(X,Y,Z,'LineStyle','none');&lt;br&gt;
shading interp&lt;br&gt;
rotate3d on&lt;br&gt;
view(3);&lt;br&gt;
axis equal&lt;br&gt;
grid on&lt;br&gt;
box on&lt;br&gt;
xlabel('x');ylabel('y');zlabel('z');&lt;br&gt;
set(gca,'Color',get(gcf,'Color'));&lt;br&gt;
&lt;br&gt;
However if I then add some lighting with the following 2 lines:&lt;br&gt;
&lt;br&gt;
light('Position',[-0.05 -0.7 1.6],'Style','infinite');&lt;br&gt;
lighting phong&lt;br&gt;
&lt;br&gt;
then the image has an ugly seam down the y-axis where the data wraps.&lt;br&gt;
How can I get rid of this seam?&lt;br&gt;
&lt;br&gt;
I've tried generating the sphere using (a single call to) patch, and&lt;br&gt;
that works (i.e. the seam doesn't show), but unfortunately patch&lt;br&gt;
doesn't allow for a texture map to be applied.&lt;br&gt;
&lt;br&gt;
Any suggestions would be appreciated.</description>
    </item>
    <item>
      <pubDate>Fri, 12 Jun 2009 19:46:02 -0400</pubDate>
      <title>Re: surface/lighting problem</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/253495#656849</link>
      <author>Andres </author>
      <description>&quot;pouncingmoose@gmail.com&quot; &amp;lt;pouncingmoose@gmail.com&amp;gt; wrote in message &amp;lt;7565cf0d-4f8b-44f8-8121-9daa9bb6e7f5@p5g2000pre.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; I'm hoping that someone more knowledgeable than myself on MATLAB's 3D&lt;br&gt;
&amp;gt; graphics might be able to help overcome the following problem:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have some data for a spheroid that I need to apply a texture to,&lt;br&gt;
&amp;gt; however when I visualize it the sphere it has an ugly &quot;seam&quot; down the&lt;br&gt;
&amp;gt; side that I can't find a way to remove.&lt;br&gt;
&amp;gt; The following code generates a sphere that when rotated (manually)&lt;br&gt;
&amp;gt; looks fine:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; close all&lt;br&gt;
&amp;gt; [X,Y,Z] = sphere(10);&lt;br&gt;
&amp;gt; he = surface(X,Y,Z,'LineStyle','none');&lt;br&gt;
&amp;gt; shading interp&lt;br&gt;
&amp;gt; rotate3d on&lt;br&gt;
&amp;gt; view(3);&lt;br&gt;
&amp;gt; axis equal&lt;br&gt;
&amp;gt; grid on&lt;br&gt;
&amp;gt; box on&lt;br&gt;
&amp;gt; xlabel('x');ylabel('y');zlabel('z');&lt;br&gt;
&amp;gt; set(gca,'Color',get(gcf,'Color'));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However if I then add some lighting with the following 2 lines:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; light('Position',[-0.05 -0.7 1.6],'Style','infinite');&lt;br&gt;
&amp;gt; lighting phong&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; then the image has an ugly seam down the y-axis where the data wraps.&lt;br&gt;
&amp;gt; How can I get rid of this seam?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I've tried generating the sphere using (a single call to) patch, and&lt;br&gt;
&amp;gt; that works (i.e. the seam doesn't show), but unfortunately patch&lt;br&gt;
&amp;gt; doesn't allow for a texture map to be applied.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any suggestions would be appreciated.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
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:&lt;br&gt;
&lt;br&gt;
vn = get(he,'VertexNormals');&lt;br&gt;
vnSeam = mean(vn(:,[1,end],:),2);&lt;br&gt;
vnNew = vn;&lt;br&gt;
vnNew(:,[1,end],:) = repmat(vnSeam,[1 2 1]);&lt;br&gt;
set(he,'VertexNormals',vnNew);</description>
    </item>
    <item>
      <pubDate>Fri, 12 Jun 2009 21:32:27 -0400</pubDate>
      <title>Re: surface/lighting problem</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/253495#656889</link>
      <author>pouncingmoose@gmail.com</author>
      <description>&lt;br&gt;
Perfect.&lt;br&gt;
Thanks.</description>
    </item>
  </channel>
</rss>

