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:
Inscribed triangle in delaunay trianglation mesh

Subject: Inscribed triangle in delaunay trianglation mesh

From: ZEESHAN MOHIUDDIN

Date: 19 May, 2010 07:53:50

Message: 1 of 9

Dear All

I need your help in MATLAB for constructing a shape.

First I need to draw the set of triangular mesh . Inside the each triangle of the mesh, I need to draw an inscribed triangle. The boundary of the inscribed triangle is placed at certain distance with that of the triangluar mesh triangle.

I used the following program to create the triangular mesh :

x=rand(1,12);
y=rand(1,12);
tri=delaunay(x,y);
trimesh(tri,x,y)

Now I would like to generate an inscribed triangle in this mesh in such a way that the distance between the inscribed and mesh triangle lies between 0-1 ( using normal or lognormal distribution). Can you please provide some help in this matter.

BR

Subject: Inscribed triangle in delaunay trianglation mesh

From: Roger Stafford

Date: 19 May, 2010 15:09:04

Message: 2 of 9

ZEESHAN MOHIUDDIN <zeeextra@yahoo.com> wrote in message <2030930001.184872.1274255660644.JavaMail.root@gallium.mathforum.org>...
> Dear All
>
> I need your help in MATLAB for constructing a shape.
>
> First I need to draw the set of triangular mesh . Inside the each triangle of the mesh, I need to draw an inscribed triangle. The boundary of the inscribed triangle is placed at certain distance with that of the triangluar mesh triangle.
>
> I used the following program to create the triangular mesh :
>
> x=rand(1,12);
> y=rand(1,12);
> tri=delaunay(x,y);
> trimesh(tri,x,y)
>
> Now I would like to generate an inscribed triangle in this mesh in such a way that the distance between the inscribed and mesh triangle lies between 0-1 ( using normal or lognormal distribution). Can you please provide some help in this matter.
>
> BR

  If the vertices of a triangle are three-element vectors P1, P2, P3, then with t a number between 0 and 1 do this:

 P0 = (P1+P2+P3)/3;
 Q1 = t*P1+(1-t)*P0;
 Q2 = t*P2+(1-t)*P0;
 Q3 = t*P3+(1-t)*P0;

These give the vertices of a triangle within the above triangle and sides parallel to its sides. Choose t according the desired relative spacing. With t = 1, the triangles coincide. With t = 0 the second triangle shrinks to a point. You want it spaced somewhere in between randomly, so let t be a random number according to whatever distribution you wish.

Roger Stafford

Subject: Inscribed triangle in delaunay trianglation mesh

From: ZEESHAN MOHIUDDIN

Date: 21 May, 2010 02:20:38

Message: 3 of 9

Thanks Roger for the reply

Actually I couldnt able to find a logic so that I can determine the vertices of the triangles generated by the delaunay triangulation mesh. Can you help me to find it?

Subject: Inscribed triangle in delaunay trianglation mesh

From: Roger Stafford

Date: 21 May, 2010 03:06:05

Message: 4 of 9

ZEESHAN MOHIUDDIN <zeeextra@yahoo.com> wrote in message <1354626748.198425.1274408468681.JavaMail.root@gallium.mathforum.org>...
> Thanks Roger for the reply
>
> Actually I couldnt able to find a logic so that I can determine the vertices of the triangles generated by the delaunay triangulation mesh. Can you help me to find it?
- - - - - - - - -
  In your function call tri=delaunay(w,y), tri is an m x 3 array for m triangles in which each row contains three indices which determine which three of the x,y pairs are a set of triangle vertices. Each of the m rows therefore represents one of the triangles of your triangulaton.

  For the k-th triangle, the three vertices would (in my previous notation) therefore be

 P1 = [x(tri(k,1)),y(tri(k,1))];
 P2 = [x(tri(k,2)),y(tri(k,2))];
 P3 = [x(tri(k,3)),y(tri(k,3))];

So then you would draw the corresponding Q1, Q2, Q3 triangle within this triangle. And then onto the k+1-st triangle, ...

Roger Stafford

Subject: Inscribed triangle in delaunay trianglation mesh

From: ZEESHAN MOHIUDDIN

Date: 1 Jun, 2010 07:10:18

Message: 5 of 9

Thanks Roger,

Actually I try to run this code:
x = randn(1,12);
y = randn(1,12);
tri = delaunay(x,y);

t=randn(1,1)

for k=1:12
p1=[x(tri(k,1)),y(tri(k,1))]
p2=[x(tri(k,2)),y(tri(k,2))]
p3=[x(tri(k,3)),y(tri(k,3))]

P0 = (P1 +P2+P3(k))/3;
Q1 = t*P1(k)+(1-t)*P0;
Q2(k) = t*P2(k)+(1-t)*P0;
Q3(k) = t*P3(k)+(1-t)*P0;

end

but it returns the following error :

In an assignment A(I) = B, the number of elements in B and I must be the same.

I think it might be due to the fact that I am trying to save in P1, the array of 2 variables. However what I think is that I have to store the co-ordinates of each vertice of the triangle in some form.

Please guide me to solve this problem.

Once Again, Many Thanks
Zeeshan

Subject: Inscribed triangle in delaunay trianglation mesh

From: Walter Roberson

Date: 1 Jun, 2010 12:42:02

Message: 6 of 9

ZEESHAN MOHIUDDIN wrote:

> Actually I try to run this code:
> x = randn(1,12);
> y = randn(1,12);
> tri = delaunay(x,y);
>
> t=randn(1,1)
>
> for k=1:12
> p1=[x(tri(k,1)),y(tri(k,1))]
> p2=[x(tri(k,2)),y(tri(k,2))]
> p3=[x(tri(k,3)),y(tri(k,3))]

Those are lower-case P's, and the assignments are perfectly valid


> P0 = (P1 +P2+P3(k))/3;

Those are upper-case P's and that's a vector-valued expression.

> Q1 = t*P1(k)+(1-t)*P0;

Is there a reason that Q1 is not indexed?

> Q2(k) = t*P2(k)+(1-t)*P0;

There, Q2 is indexed and so must be a single value, but P0 is a vector
and so the result is a vector.

> Q3(k) = t*P3(k)+(1-t)*P0;
>
> end
>
> but it returns the following error :
>
> In an assignment A(I) = B, the number of elements in B and I must be the same.

Subject: Inscribed triangle in delaunay trianglation mesh

From: ZEESHAN MOHIUDDIN

Date: 2 Jun, 2010 09:12:13

Message: 7 of 9

Thanks Walter for correcting me and showing the errors.
I now change my methodology for getting the co ordinates of the triangle generated by delaunay. I wrote program something like this :

x = randn(1,12);
y = randn(1,12);
tri = delaunay(x,y);

for i=1:length(tri)
    for j=1:3
    X(i,j)=x(tri(i,j));
    Y(i,j)=y(tri(i,j));
end
end

it gives me two different matrices of x and y co ordinates of each triangle of delaunay. Now I want to apply the methodology proposed by Roger. Can you help me to write this.

His methodology is as follows:

" If the vertices of a triangle are three-element vectors P1, P2, P3, then with t a number between 0 and 1 do this:"

P0 = (P1+P2+P3)/3;
Q1 = t*P1+(1-t)*P0;
Q2 = t*P2+(1-t)*P0;
Q3 = t*P3+(1-t)*P0;

many Thanks,
Zeeshan

Subject: Inscribed triangle in delaunay trianglation mesh

From: Roger Stafford

Date: 2 Jun, 2010 19:10:21

Message: 8 of 9

ZEESHAN MOHIUDDIN <zeeextra@yahoo.com> wrote in message <430339163.264618.1275469964116.JavaMail.root@gallium.mathforum.org>...
>
> for i=1:length(tri)
> for j=1:3
> X(i,j)=x(tri(i,j));
> Y(i,j)=y(tri(i,j));
> end
> end
>
> it gives me two different matrices of x and y co ordinates of each triangle of delaunay. Now I want to apply the methodology proposed by Roger. Can you help me to write this.
>
> His methodology is as follows:
>
> " If the vertices of a triangle are three-element vectors P1, P2, P3, then with t a number between 0 and 1 do this:"
>
> P0 = (P1+P2+P3)/3;
> Q1 = t*P1+(1-t)*P0;
> Q2 = t*P2+(1-t)*P0;
> Q3 = t*P3+(1-t)*P0;
>
> many Thanks,
> Zeeshan

  Starting with your X and Y arrays above, it could go like this:

 t = rand; % <-- Or however you want to make a random no. between 0 and 1
 P0 = [sum(X,2),sum(Y,2)]/3;
 Q1 = t*[X(:,1),Y(:,1)]+(1-t)*P0;
 Q2 = t*[X(:,2),Y(:,2)]+(1-t)*P0;
 Q3 = t*[X(:,3),Y(:,3)]+(1-t)*P0;

Each row of the arrays Q1, Q2, and Q3 has the x, y coordinates in their two columns for the three vertices, respectively, of the corresponding inner triangle. You can therefore use these directly to draw those triangles.

  By the way, earlier you used randn to generate random t's. That doesn't work because the output of randn is not restricted to lie between 0 and 1. You could get wild triangles that no longer lie inside the delaunay triangles.

Roger Stafford

Subject: Inscribed triangle in delaunay trianglation mesh

From: ZEESHAN MOHIUDDIN

Date: 3 Jun, 2010 03:19:26

Message: 9 of 9

Thank you so much Roger and Walter for your help. I really aprreciate help from both of you especially Roger.

Tags for this Thread

No tags are associated with 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