Code covered by the BSD License
-
flockAlignPnY(P,Y,L,B);
Using simple cooridinate translation and rotation we'll align P to Y
-
flockBaryCenter(F);
This simple function utilazes polygeom
-
flockFindRelLocS(Y,F);
Find followers location relative to Y
-
flockNumOfBots(F);
-
flockRank(me,A)
inputs: Sx sub group of followers locations
-
flockSetY(L,B);
input X1Y1, X2Y2
-
flockSort(A,L,B)
-
flockStep(Ptn, Flwr, Ldr, me)...
flockStep is the main loop the follower execute
-
polygeom( x, y )
POLYGEOM Geometry of a planar polygon
-
flockTest.m
-
View all files
from
Flocking Algorithm
by Shlomo Segal
A Simple application of a flocking algorithm. Following Gervasi Coordination without Communicatio
|
| flockBaryCenter(F);
|
function centroid = flockBaryCenter(F);
% This simple function utilazes polygeom
% to find the barycenter of set of 2D points
% [centroidX centroidY] = baryCenter([X1 Y1; X2 Y2;...])
% First it will make a convex hull from the vertexes given
% only then it will aply polygeom
tmp = size(F);
if (tmp(2) == 3) % for indexed F = [n,X,Y ]
% convet the XY matrix to [Xi],[Yi]
X = F(:,2);
Y = F(:,3);
elseif (tmp(2) == 2) % for simple F = [X,Y ]
X = F(:,1);
Y = F(:,2);
else
error( ' Bad input ');
end
% Find a order that will make a convex hull polygon
k = convhull(X,Y);
% Rearrange the vector in such way
X = X(k);
Y = Y(k);
% Now, finally find the barycenter
polyProps = polygeom(X,Y);
centroid = [polyProps(2) polyProps(3)];
return
|
|
Contact us at files@mathworks.com