# How can I find intersection points between vectors normal to a plane and a trisurf sphere?

6 views (last 30 days)
Robin Hartley on 31 Jul 2020
Hi all,
I am trying to find intersection points between vectors normal to a plane and a trisurf sphere using triangle/ray intersection from the file exchange:
I am getting the following error:
"The logical indices in position 1 contain a true value outside of the array bounds."
I am finding it hard to debug the error as the arrays involved are too large to be displayed.
Here is a rough approximation of the code I am trying to run that displays the same error:
%Create sphere
Center_LSE = [25 5 1]; %centre
[x,y,z] = sphere(20);
spherez = Radius_LSE*z+Center_LSE(3); %coordinates of sphere surface
tri = delaunay(spherex,spherey);
vertices = [spherex(:) spherey(:) spherez(:)];
vert1 = vertices(tri(:,1),:);
vert2 = vertices(tri(:,2),:);
vert3 = vertices(tri(:,3),:);
%Make xy plane
[xq,yq] = meshgrid( linspace(0,50,200), linspace(0,10,40));
zq = zeros(40,200);
[U, V, W] = surfnorm(xq,yq,zq); %Normals to plane
xqrshp = reshape(xq,[],1);
yqrshp = reshape(yq,[],1);
zqrshp = reshape(zq,[],1);
Urshp = reshape(U,[],1);
Vrshp = reshape(V,[],1);
Wrshp = reshape(W,[],1);
orig = [xqrshp yqrshp zqrshp]; %Vector origins
dir = [Urshp Vrshp Wrshp]; %Vector directions
for i = 1:length(orig)
[intersect(:,:,i),~,~,~,xcoor(:,:,i)] = TriangleRayIntersection(orig(i,:), dir(i,:), ...
vert1, vert2, vert3, 'lineType' , 'line');
end
scatter3(xcoor(intersect,1), xcoor(intersect,2), xcoor(intersect,3), 100, 'b', 'o', 'filled')
for i = 1:length(orig)
xintersect(i) = xcoor(intersect(:,:,i),1,i);
yintersect(i) = xcoor(intersect(:,:,i),2,i);
zintersect(i) = xcoor(intersect(:,:,i),3,i);
end
xintersect = xintersect';
yintersect = yintersect';
zintersect = zintersect';