MATLAB Newsgroup

Hi, I have a function which plots two surfaces at different elevations and 'closes' the gaps between their edges using patch, to create a closed 3D surface. (see the function Surf3D).

I now realise a problem in that my algorithm for finding the boundary edges and plotting the faces is not entirely correct - specifically south facing faces are not plotted. Logically, the algorithm here should be the reverse of that for the north faces (which works fine), and it is....however it does not work. I wondered if anyone could spot the problem.

This is the code, running it will produce the faulty image:

[Xn,Yn,Ztop] = peaks(100);

Zbot=Ztop-5;

% Get a subset of the area (originally created with ginput command)

x=[-1.0023 -0.2281 0.8088 1.8594 1.7627 0.6982 -0.7120];

y=[-0.7807 -1.5351 -1.9737 -1.0263 0.7982 1.9386 1.5000];

% replace all values outside the subset with nan

isinpolygon=inpolygon(Xn,Yn,x,y);

newZtop=Ztop; newZtop(find(isinpolygon==0))=nan;

newZbot=Zbot; newZbot(find(isinpolygon==0))=nan;

R=newZtop;

%plot the two surfaces

scrsz = get(0,'ScreenSize');

figure('Position',[scrsz(3)/4 scrsz(4)/4 scrsz(3)/2 scrsz(4)/2],'Renderer','opengl'); surf(Xn,Yn,newZtop,R); hold on; surf(Xn,Yn,newZbot,R);

[I,J]=size(Ztop);

%Now follows the alogrithm to get the vertices of boundary faces and plot them.

for i=1:I

for j=1:J

if isnan(R(i,j))

else

if ~isnan(R(i+1,j)) && isnan(R(i,j-1))%west

xt1=Xn(i,j); xt2=Xn(i+1,j); xb1=Xn(i,j); xb2=Xn(i+1,j);

yt1=Yn(i,j); yt2=Yn(i+1,j); yb1=Yn(i,j); yb2=Yn(i+1,j);

zt1=newZtop(i,j); zt2=newZtop(i+1,j); zb1=newZbot(i,j); zb2=newZbot(i+1,j);

patch([xt1 xt2 xb2 xb1],[yt1 yt2 yb2 yb1],[zt1 zt2 zb2 zb1],R(i,j))

end

if ~isnan(R(i-1,j)) && isnan(R(i,j-1)) %west

xt1=Xn(i,j); xt2=Xn(i-1,j); xb1=Xn(i,j); xb2=Xn(i-1,j);

yt1=Yn(i,j); yt2=Yn(i-1,j); yb1=Yn(i,j); yb2=Yn(i-1,j);

zt1=newZtop(i,j); zt2=newZtop(i-1,j); zb1=newZbot(i,j); zb2=newZbot(i-1,j);

patch([xt1 xt2 xb2 xb1],[yt1 yt2 yb2 yb1],[zt1 zt2 zb2 zb1],R(i,j))

end

if ~isnan(R(i,j+1)) && isnan(R(i+1,j)) %south - this causes the problems

xt3=Xn(i,j); xt4=Xn(i,j+1); xb3=Xn(i,j); xb4=Xn(i,j+1);

yt3=Yn(i,j); yt4=Yn(i,j+1); yb3=Yn(i,j); yb4=Yn(i,j+1);

zt3=newZtop(i,j); zt4=newZtop(i,j+1); zb3=newZbot(i,j); zb4=newZbot(i,j+1);

patch([xt3 xt4 xb4 xb3],[yt3 yt4 yb4 yb3],[zt3 zt4 zb4 zb3],R(i,j))

end

if ~isnan(R(i,j-1)) && isnan(R(i+1,j)) %south - causes problems

xt3=Xn(i,j); xt4=Xn(i,j-1); xb3=Xn(i,j); xb4=Xn(i,j-1);

yt3=Yn(i,j); yt4=Yn(i,j-1); yb3=Yn(i,j); yb4=Yn(i,j-1);

zt3=newZtop(i,j); zt4=newZtop(i,j-1); zb3=newZbot(i,j); zb4=newZbot(i,j-1);

patch([xt3 xt4 xb4 xb3],[yt3 yt4 yb4 yb3],[zt3 zt4 zb4 zb3],R(i,j))

end

if ~isnan(R(i+1,j)) && isnan(R(i,j+1))%east

xt1=Xn(i,j); xt2=Xn(i+1,j); xb1=Xn(i,j); xb2=Xn(i+1,j);

yt1=Yn(i,j); yt2=Yn(i+1,j); yb1=Yn(i,j); yb2=Yn(i+1,j);

zt1=newZtop(i,j); zt2=newZtop(i+1,j); zb1=newZbot(i,j); zb2=newZbot(i+1,j);

patch([xt1 xt2 xb2 xb1],[yt1 yt2 yb2 yb1],[zt1 zt2 zb2 zb1],R(i,j-1))

end

if ~isnan(R(i-1,j)) && isnan(R(i,j+1))%east

xt1=Xn(i,j); xt2=Xn(i-1,j); xb1=Xn(i,j); xb2=Xn(i-1,j);

yt1=Yn(i,j); yt2=Yn(i-1,j); yb1=Yn(i,j); yb2=Yn(i-1,j);

zt1=newZtop(i,j); zt2=newZtop(i-1,j); zb1=newZbot(i,j); zb2=newZbot(i-1,j);

patch([xt1 xt2 xb2 xb1],[yt1 yt2 yb2 yb1],[zt1 zt2 zb2 zb1],R(i,j-1))

end

if ~isnan(R(i,j+1))&& isnan(R(i-1,j)) %north

xt3=Xn(i,j); xt4=Xn(i,j+1); xb3=Xn(i,j); xb4=Xn(i,j+1);

yt3=Yn(i,j); yt4=Yn(i,j+1); yb3=Yn(i,j); yb4=Yn(i,j+1);

zt3=newZtop(i,j); zt4=newZtop(i,j+1); zb3=newZtop(i,j); zb4=newZtop(i,j+1);

patch([xt3 xt4 xb4 xb3],[yt3 yt4 yb4 yb3],[zt3 zt4 zb4 zb3],R(i,j))

end

if ~isnan(R(i,j-1))&& isnan(R(i-1,j)) %north

xt3=Xn(i,j); xt4=Xn(i,j-1); xb3=Xn(i,j); xb4=Xn(i,j-1);

yt3=Yn(i,j); yt4=Yn(i,j-1); yb3=Yn(i,j); yb4=Yn(i,j-1);

zt3=newZtop(i,j); zt4=newZtop(i,j-1); zb3=newZbot(i,j); zb4=newZbot(i,j-1);

patch([xt3 xt4 xb4 xb3],[yt3 yt4 yb4 yb3],[zt3 zt4 zb4 zb3],R(i,j))

end

end

end

end

set(findobj(gca,'type','surface'),'EdgeColor','none');

set(findobj(gca,'type','patch'),'EdgeColor','none');

view(350,40)

You can think of your watch list as threads that you have bookmarked.

You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.

To add items to your watch list, click the "add to watch list" link at the bottom of any page.

To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.

You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.

To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.

To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.

The newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.

Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.

Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.

There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.

**MATLAB Central**

You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.

Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.

**One Account**

Your MATLAB Central account is tied to your MathWorks Account for easy access.

**Use the Email Address of Your Choice**

The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.

**Spam Control**

Most newsgroup spam is filtered out by the MATLAB Central Newsreader.

**Tagging**

Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.

**Watch lists**

Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.

- Use a newsreader through your school, employer, or internet service provider
- Pay for newsgroup access from a commercial provider
- Use Google Groups
- Mathforum.org provides a newsreader with access to the comp.soft sys.matlab newsgroup
- Run your own server. For typical instructions, see: http://www.slyck.com/ng.php?page=2