-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojected_point_distance.m
53 lines (46 loc) · 1.6 KB
/
projected_point_distance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function d = projected_point_distance(x, t, y, x_star, t_star)
%--------------------------------------------------------------------------
%
% FUNCTION: projected_point_distance
%
% PURPOSE: Find the distance from a projected vector to a target
% point
%
% SYNTAX: d = projected_point_distance(x, t, y, x_star, t_star)
%
% INPUTS: x - observation location(s) - [n×d]
% t - observation time(s) - [n×1]
% y - vector observation(s) - [n×d]
% x_star - target point(s) - [k×d]
% t_star - target time(s) - [1×1]
%
% OUTPUTS: d - square distances [n×k]
%
% AUTHOR: Nicholas Lawrance
%
% CREATED: March 2010
%
% MODIFIED: March 2009
%
% See also:
%--------------------------------------------------------------------------
% Now can only predict at one time
% Calculate projected position (position of observation at target time)
% New_pos = x + y*(t_star - t)
% = (x - y*t) + y*t_star
projected_pos = permute(repmat(x + (t_star - diag(t))*y, [1, 1, size(x_star, 1)]), [1, 3, 2]);
target_pos = permute(repmat(x_star, [1, 1, size(x, 1)]), [3, 1, 2]);
d = sum((target_pos - projected_pos).^2, 3);
% OLD VERSION (NON - SYMMETRIC)
% start_pos = permute(repmat(x - diag(t)*y, [1, 1, size(x_star, 1)]), [1, 3, 2]);
% shift_pos = zeros(size(start_pos));
%
% % Horrible hack to fill dimensions of shifted positions
% for ii = 1:size(x, 2)
% shift_pos(:,:,ii) = y(:,ii)*t_star';
% end
%
% projected_pos = start_pos + shift_pos;
% target_pos = permute(repmat(x_star, [1, 1, size(x, 1)]), [3, 1, 2]);
%
% d = sum((target_pos - projected_pos).^2, 3);