mesh on a triangle

  • Follow


Hi all,

is there an easy way in matlab to plot a function whose support is a
triangle ?

I just want to plot f(x,y)=2*(1-x-y)^2-(1-x-y) on (x,y) in [0,1]*[0,1-
x]

I know the trimesh function for instance, but it meshes a square, not
a triangle, with triangles
Otherwise, I know that I can use the patch function to draw whatever I
want, but I am just looking for an easy to use built-in function..

Thank you,

Pluton
0
Reply plutonesque (390) 11/13/2008 6:16:18 PM

pluton <plutonesque@gmail.com> wrote in message <90fa8900-fdb1-4215-b313-615c4e9793d6@t39g2000prh.googlegroups.com>...
> Hi all,
> 
> is there an easy way in matlab to plot a function whose support is a
> triangle ?
> 
> I just want to plot f(x,y)=2*(1-x-y)^2-(1-x-y) on (x,y) in [0,1]*[0,1-
> x]
> 
> I know the trimesh function for instance, but it meshes a square, not
> a triangle, with triangles
> Otherwise, I know that I can use the patch function to draw whatever I
> want, but I am just looking for an easy to use built-in function..
> 
> Thank you,
> 
> Pluton

There are probably heaps of ways to get MATLAB to do this, one way is to construct a mesh of the triangular domain. You could use "mesh2d", available on the FEX to build an unstructured triangular mesh.

As you've noted you could then use the "trisurf/trimesh" routines.

Darren
0
Reply d_engwirda.nospam (14) 11/13/2008 6:51:01 PM


pluton <plutonesque@gmail.com> wrote in message <90fa8900-fdb1-4215-b313-615c4e9793d6@t39g2000prh.googlegroups.com>...
> Hi all,
> 
> is there an easy way in matlab to plot a function whose support is a
> triangle ?
> 
> I just want to plot f(x,y)=2*(1-x-y)^2-(1-x-y) on (x,y) in [0,1]*[0,1-
> x]
> 
> I know the trimesh function for instance, but it meshes a square, not
> a triangle, with triangles
> Otherwise, I know that I can use the patch function to draw whatever I
> want, but I am just looking for an easy to use built-in function..
> 

I recall at least one code on the file exchange that will
triangulate a 2-d polygon. Look for mesh2d.

John
0
Reply woodchips (7921) 11/13/2008 6:53:01 PM

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gfht2d$ct2$1@fred.mathworks.com>...
> pluton <plutonesque@gmail.com> wrote in message <90fa8900-fdb1-4215-b313-615c4e9793d6@t39g2000prh.googlegroups.com>...
> > Hi all,
> > 
> > is there an easy way in matlab to plot a function whose support is a
> > triangle ?
> > 
> > I just want to plot f(x,y)=2*(1-x-y)^2-(1-x-y) on (x,y) in [0,1]*[0,1-
> > x]
> > 
> > I know the trimesh function for instance, but it meshes a square, not
> > a triangle, with triangles
> > Otherwise, I know that I can use the patch function to draw whatever I
> > want, but I am just looking for an easy to use built-in function..
> > 
> 
> I recall at least one code on the file exchange that will
> triangulate a 2-d polygon. Look for mesh2d.
> 

>> help mesh2d

mesh2d.m not found.
--

A sloppy way, if you could live with some edges in the figure:

clear all;clc;clf reset
n=20;
u=linspace(0,1,n);
v=linspace(0,1,n)/sin(pi/4);
[U,V]=meshgrid(u,v);
%map rect grid onto tri-grid by linear transform
x=U-V*cos(pi/4);
y=V*sin(pi/4);
y(x<-1/n)=NaN; %will be ignored in surf 
x(x<-1/n)=NaN;
fun=2*(1-x-y).^2-(1-x-y);
figure(1), clf;surf(x,y,fun);
shading interp;lighting phong;light;axis tight
%view(2)
%plot points in triangular mesh
plot(x,y,'.');axis equal;

/Per

0
Reply per.sundqvist1 (22) 11/13/2008 7:37:02 PM

ok, thank you all !
0
Reply plutonesque (390) 11/13/2008 7:48:35 PM

"Per Sundqvist" <per.sundqvist@live.com> wrote in message <gfhvku$ohc$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <gfht2d$ct2$1@fred.mathworks.com>...
> > pluton <plutonesque@gmail.com> wrote in message <90fa8900-fdb1-4215-b313-615c4e9793d6@t39g2000prh.googlegroups.com>...
> > > Hi all,
> > > 
> > > is there an easy way in matlab to plot a function whose support is a
> > > triangle ?
> > > 
> > > I just want to plot f(x,y)=2*(1-x-y)^2-(1-x-y) on (x,y) in [0,1]*[0,1-
> > > x]
> > > 
> > > I know the trimesh function for instance, but it meshes a square, not
> > > a triangle, with triangles
> > > Otherwise, I know that I can use the patch function to draw whatever I
> > > want, but I am just looking for an easy to use built-in function..
> > > 
> > 
> > I recall at least one code on the file exchange that will
> > triangulate a 2-d polygon. Look for mesh2d.
> > 
> 
> >> help mesh2d
> 
> mesh2d.m not found.

Read my lips. I said to look on the file exchange.

John
0
Reply woodchips (7921) 11/13/2008 8:37:02 PM

5 Replies
47 Views

(page loaded in 0.036 seconds)

Similiar Articles:













7/17/2012 3:54:28 PM


Reply: