Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: path along surf plot

Subject: path along surf plot

From: maurizio

Date: 4 Jul, 2008 12:23:03

Message: 1 of 2

Hi everybody,

starting from many (x,y,z) points, I've built a 3d surface
plot with the following code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xlin = linspace(min(x),max(x),35);
ylin = linspace(min(y),max(y),35);
[X,Y] = meshgrid(xlin,ylin);

Z = griddata(x,y,z,X,Y,'cubic');

mesh(X,Y,Z) %interpolated
axis tight; hold on
plot3(x,y,z,'.','MarkerSize',15)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

What I would like to do now is to plot a certain line laying
on this surface, connecting some points, in order to
highligh a certain path on the surface itself.
The surface is not regular, so if I just fit the points I
wanna connect the line intersect the surface, it doesn't
follow its shape.
Any ideas?
If I need to change the code for plotting the surface, no
problem, I'm more interested in the "line" than in the surface.

Many thanks in advance



Subject: path along surf plot

From: Kenneth Eaton

Date: 4 Jul, 2008 17:40:04

Message: 2 of 2

> What I would like to do now is to plot a certain line
laying
> on this surface, connecting some points, in order to
> highligh a certain path on the surface itself.
> The surface is not regular, so if I just fit the points I
> wanna connect the line intersect the surface, it doesn't
> follow its shape.
> Any ideas?
> If I need to change the code for plotting the surface, no
> problem, I'm more interested in the "line" than in the
surface.
>
> Many thanks in advance

It sounds like you want to plot a line that follows along a
plotted surface without intersecting it. There is one
problem in doing this that I believe you may have run into.

When you plot a surface using either the "surf"
or "surface" command, the surface is graphically rendered
as a bunch of triangular sections. Therefore, the rendered
surface will graphically appear to be faceted. When you
use, for example, "interp2" to find the surface height at
any given point(s) of the data-defined surface, these height
(s) may lie above or below a facet of the graphically-
defined surface, since the interpolation will generally
represent a smoother contour than the graphical surface
would.

So you see, if you want to find a line that exactly tracks
along a rendered surface, you will have to use a different
algorithm than interp. You will likely have to write your
own ray-triangle intersection algorithm. I just finished
working on something like this for a newer version of a
game I have on the FEX: Staker. In the first version, I
used "interp2" to determine if a bomb had hit the surface
of a terrain. Because the interpolated surface doesn't
exactly match the graphical surface, the bomb sometimes
appeared to explode above or below the surface.

If you would like any help, or a sample of my surface
intersection code, let me know. I think it could help you,
and I was considering posting on the FEX anyway.

Ken

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
raytriangle intersection Kenneth Eaton 4 Jul, 2008 13:40:54
line maurizio 4 Jul, 2008 08:25:06
surf plot maurizio 4 Jul, 2008 08:25:05
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
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 Disclaimer prior to use.
Related Topics