Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: is my subject looking at the target?
Date: Mon, 28 Jan 2008 13:09:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <fnkk5e$o5g$1@fred.mathworks.com>
References: <fnjif9$59p$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1201525742 24752 172.30.248.35 (28 Jan 2008 13:09:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 28 Jan 2008 13:09:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:447916


"Dave Rowland" <rowland@uoneuro.uoregon.edu> wrote in message <fnjif9
$59p$1@fred.mathworks.com>...
> I am trying to write a bit of code that will allow me to
> determine when a subject is gazing at an object in space. 
> Here is what I have to work with:
> 1.  Position of the subject (X and Y coordinates, we ignore Z)
> 2.  The angle of the head
> 3.  The position of the object (again X and Y)
> What I need to do is first create a target around the object
> position (a circle centered at the object position with some
> user defined radius) and then determine if the subject is
> gazing at the target (a simple yes or no). 
> This should be straightforward, but I am new to Matlab and
> am having a hard time coming up with a solution.  If anyone
> can help, that would be great.  Thanks!
--------
  Let (xs,ys) be coordinates of the subject's position [1.] and (xt,yt) be those 
of the target [3.].  Let 'as' be the angle of the subject's head [2.].  Finally, let r 
be the user-defined radius.

 d2 = (xt-xs)^2+(yt-ys)^2-r^2; % Square of dist. to tangent pt.
 if d2 >= 0
  ah = atan2(r,sqrt(d2)); % Half of target's projected arc
  at = atan2(yt-ys,xt-xs); % Angle from subject to target
  df = mod(at-as+pi,2*pi)-pi; % Difference in angles
  if abs(df) <= ah
   fprintf('Subject is gazing at object.\n')
  else
   fprintf('Subject is not gazing at object.\n')
  end
 else
  fprintf('Subject is inside circle.\n')
 end

Roger Stafford