Home > matGeom > geom3d > drawRay3d.m

drawRay3d

PURPOSE ^

Draw a 3D ray on the current axis.

SYNOPSIS ^

function h = drawRay3d(ray, varargin)

DESCRIPTION ^

 Draw a 3D ray on the current axis.

   drawRay3d(RAY)
   With RAY having the syntax: [x0 y0 z0 dx dy dz], draws the ray starting
   from point (x0 y0 z0) and going to direction (dx dy dz), clipped with
   the current window axis.

   drawRay3d(RAY, PARAMS, VALUE)
   Can specify parameter name-value pairs to change draw style.

   H = drawRay3d(...)
   Returns handle on line object

   See also:
   rays2d, drawLine

   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];
     % draw the rays in the current axis
     figure; axis equal; axis([0 50 0 50 0 50]); hold on; view(3);
     drawRay3d(ray);

   See also
     drawLine3d, clipRay3d

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h = drawRay3d(ray, varargin)
0002 % Draw a 3D ray on the current axis.
0003 %
0004 %   drawRay3d(RAY)
0005 %   With RAY having the syntax: [x0 y0 z0 dx dy dz], draws the ray starting
0006 %   from point (x0 y0 z0) and going to direction (dx dy dz), clipped with
0007 %   the current window axis.
0008 %
0009 %   drawRay3d(RAY, PARAMS, VALUE)
0010 %   Can specify parameter name-value pairs to change draw style.
0011 %
0012 %   H = drawRay3d(...)
0013 %   Returns handle on line object
0014 %
0015 %   See also:
0016 %   rays2d, drawLine
0017 %
0018 %   Example
0019 %     % generate 50 random 3D rays
0020 %     origin = [29 28 27];
0021 %     v = rand(50, 3);
0022 %     v = v - centroid(v);
0023 %     ray = [repmat(origin, size(v,1),1) v];
0024 %     % draw the rays in the current axis
0025 %     figure; axis equal; axis([0 50 0 50 0 50]); hold on; view(3);
0026 %     drawRay3d(ray);
0027 %
0028 %   See also
0029 %     drawLine3d, clipRay3d
0030  
0031 % ------
0032 % Author: David Legland
0033 % e-mail: david.legland@inrae.fr
0034 % INRAE - BIA Research Unit - BIBS Platform (Nantes)
0035 % Created: 2020-05-25,    using Matlab 9.8.0.1323502 (R2020a)
0036 % Copyright 2020 INRAE.
0037 
0038 % extract handle of axis to draw in
0039 if isAxisHandle(ray)
0040     hAx = ray;
0041     ray = varargin{1};
0042     varargin(1) = [];
0043 else
0044     hAx = gca;
0045 end
0046 
0047 % get bounding box limits
0048 box = axis(hAx);
0049 
0050 % clip the ray(s) with the limits of the current axis
0051 edge = clipLine3d(ray, box);
0052 
0053 % identify valid edges
0054 inds = sum(isnan(edge), 2) == 0;
0055 
0056 % draw the clipped line
0057 hh = [];
0058 if any(inds)
0059     edge = edge(inds, :);
0060     hh = drawEdge3d(hAx, edge);
0061     if ~isempty(varargin)
0062         set(hh, varargin{:});
0063     end
0064 end
0065 
0066 % process output
0067 if nargout > 0
0068     h = hh;
0069 end

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019