Home > matGeom > geom2d > createRay.m

createRay

PURPOSE ^

CREATERAY Create a ray (half-line), from various inputs.

SYNOPSIS ^

function ray = createRay(varargin)

DESCRIPTION ^

CREATERAY Create a ray (half-line), from various inputs.

   RAY = createRay(POINT, ANGLE)
   POINT is a N*2 array giving starting point of the ray, and ANGLE is the
   orientation of the ray.

   RAY = createRay(X0, Y0, ANGLE)
   Specify ray origin with 2 input arguments.

   RAY = createRay(P1, P2)
   Create a ray starting from point P1 and going in the direction of point
   P2.

   Ray is represented in a parametric form: [x0 y0 dx dy]
   x = x0 + t*dx
   y = y0 + t*dy;
   for all t>0

   Example
   origin  = [3 4];
   theta   = pi/6;
   ray = createRay(origin, theta);
   figure(1); clf; hold on;
   axis([0 10 0 10]);
   drawRay(ray);

   See also:
   rays2d, createLine, points2d

 ------
 Author: David Legland
 e-mail: david.legland@grignon.inra.fr
 Created: 2007-10-18
 Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ray = createRay(varargin)
0002 %CREATERAY Create a ray (half-line), from various inputs.
0003 %
0004 %   RAY = createRay(POINT, ANGLE)
0005 %   POINT is a N*2 array giving starting point of the ray, and ANGLE is the
0006 %   orientation of the ray.
0007 %
0008 %   RAY = createRay(X0, Y0, ANGLE)
0009 %   Specify ray origin with 2 input arguments.
0010 %
0011 %   RAY = createRay(P1, P2)
0012 %   Create a ray starting from point P1 and going in the direction of point
0013 %   P2.
0014 %
0015 %   Ray is represented in a parametric form: [x0 y0 dx dy]
0016 %   x = x0 + t*dx
0017 %   y = y0 + t*dy;
0018 %   for all t>0
0019 %
0020 %   Example
0021 %   origin  = [3 4];
0022 %   theta   = pi/6;
0023 %   ray = createRay(origin, theta);
0024 %   figure(1); clf; hold on;
0025 %   axis([0 10 0 10]);
0026 %   drawRay(ray);
0027 %
0028 %   See also:
0029 %   rays2d, createLine, points2d
0030 %
0031 % ------
0032 % Author: David Legland
0033 % e-mail: david.legland@grignon.inra.fr
0034 % Created: 2007-10-18
0035 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas.
0036 
0037 if length(varargin)==2
0038     p0 = varargin{1};
0039     arg = varargin{2};
0040     if size(arg, 2)==1
0041         % second input is the ray angle
0042         ray = [p0 cos(arg) sin(arg)];
0043     else
0044         % second input is another point
0045         ray = [p0 arg-p0];
0046     end
0047     
0048 elseif length(varargin)==3   
0049     x = varargin{1};
0050     y = varargin{2};
0051     theta = varargin{3};
0052     ray = [x y cos(theta) sin(theta)];   
0053 
0054 else
0055     error('Wrong number of arguments in ''createRay'' ');
0056 end

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