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:
points inside triangle

Subject: points inside triangle

From: Marios Karaoulis

Date: 20 Dec, 2012 06:08:06

Message: 1 of 2

Hi all,

I have created a triangulation, and I need giving a set of points, to find in which triangle they belong.
In other words I am searching for an alternative of pointLocation.

I cannot use the delaunayn class, since the triangles are created with an external program.
How can I do this?

Subject: points inside triangle

From: Marios Karaoulis

Date: 20 Dec, 2012 07:06:07

Message: 2 of 2

This is what I come up with.

m the number of triangles
inv_mesh_tri the triangluation index (mx3)
inv_mesh_coords a matrix with the coordinates of each node (2xn)

x_centers, y_centers the points I need to test.

SI should be identical with the output of pointLocation

SI=zeros(length(inv_mesh_tri),1);
for i=1:length(inv_mesh_tri)
    
    xv=[inv_mesh_coords(inv_mesh_tri(i,1),1) inv_mesh_coords(inv_mesh_tri(i,2),1) inv_mesh_coords(inv_mesh_tri(i,3),1) inv_mesh_coords(inv_mesh_tri(i,1),1)];
    yv=[inv_mesh_coords(inv_mesh_tri(i,1),2) inv_mesh_coords(inv_mesh_tri(i,2),2) inv_mesh_coords(inv_mesh_tri(i,3),2) inv_mesh_coords(inv_mesh_tri(i,1),2)];
    
    t=inpolygon(x_centers,y_centers,xv,yv);
    SI(t==1)=i;
% plot(xv,yv,'r');
% hold on
% plot(x_centers,y_centers,'x');
% hold on
% plot(x_centers(SI==1),y_centers(SI==1),'gx');
% hold off;
end



What do you think?

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