Path: news.mathworks.com!not-for-mail
From: "Dave Rowland" <rowland@uoneuro.uoregon.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: is my subject looking at the target?
Date: Tue, 5 Feb 2008 01:19:02 +0000 (UTC)
Organization: University of Oregon
Lines: 44
Message-ID: <fo8di6$c9$1@fred.mathworks.com>
References: <fnjif9$59p$1@fred.mathworks.com> <fnkk5e$o5g$1@fred.mathworks.com>
Reply-To: "Dave Rowland" <rowland@uoneuro.uoregon.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1202174342 393 172.30.248.38 (5 Feb 2008 01:19:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 5 Feb 2008 01:19:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 413924
Xref: news.mathworks.com comp.soft-sys.matlab:449283


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
wrote in message <fnkk5e$o5g$1@fred.mathworks.com>...
> "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
> 
thanks! it's working well.