Intersection of a surface generated by scattered points and a line
44 views (last 30 days)
Actually i am new to MatLab and i am trying to figure out if there is a way of finding the intersection of a 3d surface (coordinates of the surface are read from excel and does not follow a specific formula, therefore i cant calculate the equation of the surface) and a line? I am using below code to generate my surface.
dt = DelaunayTri(X1,Y1,Z1);
[tri Xb]= freeBoundary(dt);
trisurf(tri,Xb(:,1),Xb(:,2),Xb(:,3), 'FaceColor', 'cyan', 'faceAlpha', 0.8);
Any help will be much apperacitated.
Roger Stafford on 7 May 2013
Edited: Roger Stafford on 7 May 2013
The intersection of a triangle and a line in three dimensional space can be found as follows. Using three cartesian coordinates, let vectors P1, P2, and P3 be the triangle's three vertices, and let vectors Q1 and Q2 be any two points along the given line. Then do this in matlab:
N = cross(P2-P1,P3-P1); % Normal to the plane of the triangle
P0 = Q1 + dot(P1-Q1,N)/dot(Q2-Q1,N)*(Q2-Q1); % The point of intersection
P0 will be the intersection of the line and the infinite plane of the triangle. To see if P0 lies within the triangle's perimeter, the following must hold true:
dot(cross(P2-P1,P0-P1),N)>=0 & ...
dot(cross(P3-P2,P0-P2),N)>=0 & ...
To solve your problem as posed you can test the given line against each of the triangles in your triangulation in this way to see which, if any, triangles it intersects. This will require extracting each of the triangles' set of three vertices from the triangulation object output by DelaunayTri.