Clip a 3D ray with a box and return a 3D edge.
EDGE = clipRay3d(RAY, BOX)
Clips the ray RAY with the bounds given in BOX, and returns the
corresponding edge.
RAY is given as origin + direction vector: [X0 Y0 Z0 DX DY DZ]
BOX is given as [XMIN XMAX YMIN YMAX ZMIN ZMAX].
The result EDGE is given as [X1 Y1 Z1 X2 Y2 Z2].
Example
% generate 50 random 3D rays
origin = [29 28 27];
v = rand(50, 3);
v = v - centroid(v);
ray = [repmat(origin, size(v,1),1) v];
% clip the rays with a 3D box
box = [10 40 10 40 10 40];
edges = clipRay3d(ray, box);
% draw the resulting 3D edges
figure; axis equal; axis([0 50 0 50 0 50]); hold on; view(3);
drawBox3d(box);
drawEdge3d(edges, 'g');
See also
clipLine3d
Package: matgeom