-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEPA_dist.m
executable file
·59 lines (35 loc) · 1.11 KB
/
EPA_dist.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
54
55
56
57
58
59
function [dist ] = GJK_dist( Shape1, Shape2 )
d=[1 1 1];
%pick a point
a=support(shape1,shape2,d);
%pick a second point to creat a line
b=support(shape1,shape2,-a);
%pick a third point to make a tirangle
ab=b-a;
ao=-a;
%perpendicular direction
d=cross(cross(ab,ao),ab);
c=support(shape1,shape2,d);
pts=[a b c];
if c==b || c==a %we have already converged (!) and the closest point is c
dist=norm(c);
else
while true
%we compute the norm of vector going from the origin to each member
%of the simplex
Norm_pts = (sqrt(sum(abs(pts').^2,2)));
%Computing and removing the farthest point of the simplex from the origin
[~,index]=max(Norm_pts);
pts_copy=pts;
pts(:,index)=[];
%new search direction
d=cross(cross(pts(:,2)-pts(:,1),-pts(:,1)),pts(:,2)-pts(:,1));
%adding a new point to the simplex.
c=support(shape1,shape2,d);
pts=[pts c];
if isequal(pts,pts_copy)
break;
end
end
dist = pointTriangleDistance(pts,[0 0 0]');
end