[13730] | 1 | function node_in_element=NodeInElement(newx,newy,elements,x,y,nodeconnectivity)
|
---|
[13012] | 2 | % NODEINELEMENT - find for a list of nodes (in newx,newy), which elements in the mesh (elements,x,y) they belong to.
|
---|
[2110] | 3 | %
|
---|
[13012] | 4 | % Usage:
|
---|
| 5 | % node_in_element=NodeInElement(newx,newy,elements,x,y,md.mesh.vertexconnectivity);
|
---|
[2110] | 6 | %
|
---|
| 7 | % See also Nodeconnectivity
|
---|
| 8 | %
|
---|
| 9 | epsilon=10^-10;
|
---|
| 10 |
|
---|
| 11 | %compute some quantities that will speed up the process
|
---|
| 12 | x3x1=x(elements(:,1))-x(elements(:,3));
|
---|
| 13 | y3y1=y(elements(:,1))-y(elements(:,3));
|
---|
| 14 | x3x2=x(elements(:,2))-x(elements(:,3));
|
---|
| 15 | y3y2=y(elements(:,2))-y(elements(:,3));
|
---|
| 16 | x3=x(elements(:,3));
|
---|
| 17 | y3=y(elements(:,3));
|
---|
| 18 | delta=x(elements(:,2)).*y(elements(:,3))-y(elements(:,2)).*x(elements(:,3))-x(elements(:,1)).*y(elements(:,3))+y(elements(:,1)).*x(elements(:,3))+x(elements(:,1)).*y(elements(:,2))-y(elements(:,1)).*x(elements(:,2));
|
---|
| 19 |
|
---|
| 20 | %max connectivity:
|
---|
| 21 | max_connectivity=max(nodeconnectivity(:,end));
|
---|
| 22 | node_in_element=zeros(length(newx),max_connectivity+1); %last column is the number of elements to which the row node is connected.
|
---|
| 23 |
|
---|
| 24 | for i=1:length(newx),
|
---|
| 25 | x0=newx(i);
|
---|
| 26 | y0=newy(i);
|
---|
[13646] | 27 |
|
---|
[2110] | 28 | %first area coordinate
|
---|
| 29 | area_1=(y3y2.*(x0-x3)-x3x2.*(y0-y3))./delta;
|
---|
| 30 | %second area coordinate
|
---|
| 31 | area_2=(x3x1.*(y0-y3)-y3y1.*(x0-x3))./delta;
|
---|
| 32 | %third area coordinate
|
---|
| 33 | area_3=1-area_1-area_2;
|
---|
[13646] | 34 |
|
---|
[2110] | 35 | %get elements for which all area coordinates are positive (meaning (x0,y0) belongs to these elements
|
---|
| 36 | pos=find((area_1>=0-epsilon) & (area_2>=0-epsilon) & (area_3>=0-epsilon));
|
---|
| 37 |
|
---|
| 38 | num_elements=length(pos);
|
---|
| 39 |
|
---|
| 40 | node_in_element(i,1:num_elements)=pos;
|
---|
| 41 | node_in_element(i,end)=num_elements;
|
---|
| 42 | end
|
---|