Find all the points inside a triangulation
조회 수: 8 (최근 30일)
이전 댓글 표시
I am currently working on problem in which I am using delanauy triangles to warp and morph two images.
Say i have
%These are the points marked on two different images that are to be morphed....
im2_pts = [y2(:) x2(:)];
im1_pts = [y1(:) x1(:)];
%calculating the average shape...
avg_pts=[x_avg(:) y_avg(:)];
%Triangulation...
tri = delaunay(x_avg,y_avg);
%For each triangle in tri i will perform the action below...
%First Triangle's co-ordinates
t1_x = [ 2736 1882 2736];
t1_y = [ 2736 1060 1];
%Second Triangle's co-ordinates
t2_x = [ 2736 1933 2736 ];
t2_y = [ 2736 991 2736 ];
tri1 = [t1_x(:) t1_y(:)];
tri2 = [t2_x(:) t2_y(:)];
%calculating the affine transformation...
t_affine = cp2tform(tri1,tri2,'affine');
now to apply the transformation, i need to find out all points in the triangle tri1. I know i need to use tsearch for the same. But i am not sure how to use it.
Please do let me know how do i perform this action. Thanks !!!! :D
댓글 수: 0
답변 (1개)
Florin Neacsu
2011년 10월 17일
Hi,
Given any triangle, defined by the coordinates of its vertices you can "easily" find the interior points. Have a look at barycentric coordinates. Define a barycentric coordinate system with the triangle's vertices. Then any point will have 3 coordinates say a,b,c. If they all are positive then the point is inside the triangle. If not, the point is outside.
Hope this helps. Regards, Florin
참고 항목
카테고리
Help Center 및 File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!