function [d,phi,thd]=getgeometry(xr,yr,thr,x,y,th)
% Get the geometrical relationship between a pair of edges.
%
% The geometrical relationship is found by translating and
% rotating the two edges such that the reference is at the
% origin and oriented at 0 degrees.  This is done while
% preserving the relative positions of the two edges.  The
% geometry can then be expressed in terms of the target
% edge's distance, direction, and orientation difference.
%
% Parameters:
%
%   xr  x coordinate of reference edge
%   yr  y coordinate of reference edge
%   thr Orientation of reference edge
%   x   x coordinate of target edge
%   y   y coordinate of target edge
%   th  Orientation of target edge
%
% Return:
%
%   d   Distance between the two edges
%   phi Direction of target edge
%   thd Orientation difference
%
% Copyright (C) 2001-2009 Center for Perceptual Systems

% Translate to the origin
x=x-xr;
y=y-yr;

% Implied: xr=0; yr=0;

% Get target's distance and direction (before rotation)
[phi,d]=cart2pol(x,y);

% Rotate to get final direction and orientation difference
thd=th-thr;
phi=phi-thr;
