1 |
function [Xo,Yo,c,w]=boundcross(xl,yl,m) |
---|
2 |
|
---|
3 |
% [X,Y,NODELIST,WEIGHT]=boundcross(XL,YL,M) |
---|
4 |
% |
---|
5 |
% XL and YL are two points defining a line |
---|
6 |
% M is a mesh structure loaded with MESHSTR |
---|
7 |
% |
---|
8 |
% X and Y are all boundary crossings. |
---|
9 |
|
---|
10 |
% ROTATE MESH UNTIL LINE IS Y AXIS |
---|
11 |
|
---|
12 |
b=atan(diff(xl)/(diff(yl)+eps)); |
---|
13 |
tm=[ cos(b) sin(b) |
---|
14 |
cos(b+pi/2) sin(b+pi/2)]; |
---|
15 |
Xr=reshape([m.x(m.bnd(:)) m.y(m.bnd(:))]*tm(:,1),size(m.bnd))-... |
---|
16 |
[xl(1) yl(1)]*tm(:,1); |
---|
17 |
|
---|
18 |
% CHECK FOR NODES ON AXIS |
---|
19 |
|
---|
20 |
c=[]; |
---|
21 |
w=[]; |
---|
22 |
if any(Xr(:)==0) |
---|
23 |
c=sort(m.bnd(find(Xr(:)==0))); |
---|
24 |
c=reshape(c,2,length(c)/2); |
---|
25 |
w=ones(size(c))/2; |
---|
26 |
end |
---|
27 |
|
---|
28 |
% CHECK FOR LINE CROSSINGS |
---|
29 |
|
---|
30 |
if any(abs(diff(sign(Xr')))==2); |
---|
31 |
ct=find(abs(diff(sign(Xr')))==2); |
---|
32 |
c=[c m.bnd(ct,:)']; |
---|
33 |
w=[w 1-abs(Xr(ct,:)'./([1;1]*diff(Xr(ct,:)')))]; |
---|
34 |
end |
---|
35 |
|
---|
36 |
% FIND XY POINTS AND REORDER FROM LOWEST TO HIGHEST |
---|
37 |
|
---|
38 |
Xo=sum(w.*m.x(c)); |
---|
39 |
Yo=sum(w.*m.y(c)); |
---|
40 |
[Xo,in]=sort(Xo);Yo=Yo(in); |
---|
41 |
[Yo,in]=sort(Yo);Xo=Xo(in); |
---|