Path: news.mathworks.com!not-for-mail
From: "Kenneth Eaton" <Kenneth.dot.Eaton@cchmc.dot.org>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to get the intersection point coordinate between polygon and segment
Date: Sat, 13 Dec 2008 16:01:05 +0000 (UTC)
Organization: Cincinnati Children's Hospital Research Center
Lines: 23
Message-ID: <gi0m81$2up$1@fred.mathworks.com>
References: <gi0epq$lk3$1@fred.mathworks.com>
Reply-To: "Kenneth Eaton" <Kenneth.dot.Eaton@cchmc.dot.org>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1229184065 3033 172.30.248.38 (13 Dec 2008 16:01:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 13 Dec 2008 16:01:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1165924
Xref: news.mathworks.com comp.soft-sys.matlab:506742


"zedong 
" <zdongwu@gmail.com> wrote in message <gi0epq$lk3$1@fred.mathworks.com>...
> How to get the intersection point coordinate between polygon and segment;
> for example(a is a triangle a(i,:) is the ith coordinate of the triangle.b is an segment,b(i,:) is the side point coordinate):
> a=[0 0;1 0;0 1]; b=[0.4 0.4;1 1];
> I want to return c=[0.5 0.5;0.4 0.4]
> example2:
> a=[0 0;1 0;0 1]; b=[0.4 0;2 0];
> I want to return c=[0.4 0;1 0]
> example 3
> a=[0 0;1 0;0 1]; b=[0.4 0;0.5 0];
> I want to return c=[0.4 0;0.5 0];
> Thank you for your attention.Is there any mex implementation.and stable.I also write one but I think because of the eps I can't implement it well.
> thank you for another time.

I worked on this recently. If you want the equations for computing intersections between line segments and triangles, you can first google "ray triangle intersection" and check out some of the links. Alternatively, you can peek into one of my FEX submissions:

http://www.mathworks.com/matlabcentral/fileexchange/20637

This submission is specifically designed to work with RENDERED surfaces, but if you have triangle vertices stored in variables then you can look at how my code handles multiple ray-triangle intersections to figure out how to do it for yourself in an efficient way (I tried to use matrix operations over for loops wherever possible).

hth,
Ken