Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Delaunay Triangulation: How to color specific triangles in a triplot?

Subject: Delaunay Triangulation: How to color specific triangles in a triplot?

From: Liana

Date: 21 Mar, 2011 05:01:05

Message: 1 of 7

Hello All,

dt = DelaunayTri(X, Y, C);

I have a column vector 'tri', where each number corresponds to triangle ID in dt.Triangulation, e.g.:
tri(:,1) = [1; 12; 14; 16]; % corresponds to dt.Triangulation(1,:), dt.Triangulation(12,:), dt.Triangulation(14,:), etc.

Now I'd like to create a triplot, where only triangles specified in 'tri' would have a blue background. How could I do that?

Thank you for all your help!

Subject: Delaunay Triangulation: How to color specific triangles in a triplot?

From: Bruno Luong

Date: 21 Mar, 2011 08:16:04

Message: 2 of 7

"Liana" wrote in message <im6m2h$msa$1@fred.mathworks.com>...
> Hello All,
>
> dt = DelaunayTri(X, Y, C);
>
> I have a column vector 'tri', where each number corresponds to triangle ID in dt.Triangulation, e.g.:
> tri(:,1) = [1; 12; 14; 16]; % corresponds to dt.Triangulation(1,:), dt.Triangulation(12,:), dt.Triangulation(14,:), etc.
>
> Now I'd like to create a triplot, where only triangles specified in 'tri' would have a blue background. How could I do that?
>
> Thank you for all your help!

help patch
help fill

Bruno

Subject: Delaunay Triangulation: How to color specific triangles in a triplot?

From: Liana

Date: 21 Mar, 2011 17:55:05

Message: 3 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <im71g4$sq5$1@fred.mathworks.com>...
> "Liana" wrote in message <im6m2h$msa$1@fred.mathworks.com>...
> > Hello All,
> >
> > dt = DelaunayTri(X, Y, C);
> >
> > I have a column vector 'tri', where each number corresponds to triangle ID in dt.Triangulation, e.g.:
> > tri(:,1) = [1; 12; 14; 16]; % corresponds to dt.Triangulation(1,:), dt.Triangulation(12,:), dt.Triangulation(14,:), etc.
> >
> > Now I'd like to create a triplot, where only triangles specified in 'tri' would have a blue background. How could I do that?
> >
> > Thank you for all your help!
>
> help patch
> help fill
>
> Bruno

Hi Bruno!

Thank you. I'm trying the following:

% Get vertices of each triangle in 'tri', where k is total number of triangles in 'tri'
V1t = x(handles.dt(tri(1:k,1),1),:);
V2t = x(handles.dt(tri(1:k,1),2),:);
V3t = x(handles.dt(tri(1:k,1),3),:);
Vertices = V1t + V2t + V3t;

fill(Vertices(1:k,1), Vertices(1:k,2), 'b')

However, this code does not provide a correct result. Thanks for any help.

Subject: Delaunay Triangulation: How to color specific triangles in a triplot?

From: Bruno Luong

Date: 21 Mar, 2011 18:17:05

Message: 4 of 7

Here is an example:

x =randn(100,1);
y =randn(100,1);
dt = DelaunayTri(x,y)
T = dt.Triangulation;
patch(x(T)',y(T)','b','EdgeColor','w');

Please adapt it to you need.

Bruno

Subject: Delaunay Triangulation: How to color specific triangles in a triplot?

From: Liana

Date: 21 Mar, 2011 19:13:08

Message: 5 of 7

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <im84n1$cgo$1@fred.mathworks.com>...
> Here is an example:
>
> x =randn(100,1);
> y =randn(100,1);
> dt = DelaunayTri(x,y)
> T = dt.Triangulation;
> patch(x(T)',y(T)','b','EdgeColor','w');
>
> Please adapt it to you need.
>
> Bruno

Thanks a lot! One more question just to be sure that I am on the right way. I have a constrained Delaunay Triangulation specified as follows:
dt = DelaunayTri(vertices,edges);
isInside = inOutStatus(dt);
faces = dt(isInside,:);
Do I understand correctly that the logic of 'patch' will remain the same?

Subject: Delaunay Triangulation: How to color specific triangles in a triplot?

From: Liana

Date: 21 Mar, 2011 19:43:05

Message: 6 of 7

"Liana" wrote in message <im8804$bgg$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <im84n1$cgo$1@fred.mathworks.com>...
> > Here is an example:
> >
> > x =randn(100,1);
> > y =randn(100,1);
> > dt = DelaunayTri(x,y)
> > T = dt.Triangulation;
> > patch(x(T)',y(T)','b','EdgeColor','w');
> >
> > Please adapt it to you need.
> >
> > Bruno
>
> Thanks a lot! One more question just to be sure that I am on the right way. I have a constrained Delaunay Triangulation specified as follows:
> dt = DelaunayTri(vertices,edges);
> isInside = inOutStatus(dt);
> faces = dt(isInside,:);
> Do I understand correctly that the logic of 'patch' will remain the same?

Your code does exactly what I need, if Delaunay Triangulation is specified by x & y:
x =randn(100,1); y =randn(100,1); dt = DelaunayTri(x,y);
However, I still can't figure it out for a constrained DT...

Subject: Delaunay Triangulation: How to color specific triangles in a triplot?

From: Liana

Date: 22 Mar, 2011 01:50:05

Message: 7 of 7

"Liana" wrote in message <im89o9$cs0$1@fred.mathworks.com>...
> "Liana" wrote in message <im8804$bgg$1@fred.mathworks.com>...
> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <im84n1$cgo$1@fred.mathworks.com>...
> > > Here is an example:
> > >
> > > x =randn(100,1);
> > > y =randn(100,1);
> > > dt = DelaunayTri(x,y)
> > > T = dt.Triangulation;
> > > patch(x(T)',y(T)','b','EdgeColor','w');
> > >
> > > Please adapt it to you need.
> > >
> > > Bruno
> >
> > Thanks a lot! One more question just to be sure that I am on the right way. I have a constrained Delaunay Triangulation specified as follows:
> > dt = DelaunayTri(vertices,edges);
> > isInside = inOutStatus(dt);
> > faces = dt(isInside,:);
> > Do I understand correctly that the logic of 'patch' will remain the same?
>
> Your code does exactly what I need, if Delaunay Triangulation is specified by x & y:
> x =randn(100,1); y =randn(100,1); dt = DelaunayTri(x,y);
> However, I still can't figure it out for a constrained DT...

I solved this problem. It was quite simple. It seems that I just had incomplete understanding of 'dt' structure.

Tags for this Thread

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.

Contact us