image thumbnail

VANET node - RoadSide Unit scenario simulations

by

 

This file contains matlab simulations of nodal interaction scenarios in VANETs

MarkingBoundaryDoubleRSU_VanetNode_Interaction.m
axis([0 100 0 100]);hold on
nodes = 5;
PauseTime = 0.05; 
[x,y] = ginput(nodes);
plot(x,y,'--ys','LineWidth',2,...
                'MarkerEdgeColor','b',...
                'MarkerFaceColor','b',...
                'MarkerSize',4)
[p,q] = ginput(2);

plot(p(1),q(1),'*k')
plot(p(2),q(2),'*k');

xp = x(1);
yp = y(1);
m = 0; 

for loop = 1:20
    for i = 2:nodes
        xc = x(i); 
        yc = y(i); 
        xp = x(i-1);
        yp = y(i-1);
        m = floor(sqrt((xp-xc)*(xp-xc)+(yp-yc)*(yp-yc)))
        a1 = linspace(xp,xc,m);
        b1 = linspace(yp,yc,m);
            for j = 2:m
            h1 = plot(a1(j),b1(j),'*r')

            pt  = [a1(j);b1(j)];
            pt1 = [p(1);q(1)];
            pt2 = [p(2);q(2)];
            d1 = norm(pt-pt1); 
            d2 = norm(pt-pt2); 
            
            if(d1<=20 && d1<d2)
                   h2 = plot([a1(j) p(1)],[b1(j) q(1)])
                   pause(PauseTime);
                   set(h2,'Visible','off');
                   continue
            elseif(d2<=20)
                   h3 = plot([a1(j) p(2)],[b1(j) q(2)])
                   pause(PauseTime);
                   set(h3,'Visible','off');
                   continue;                
            end
                    
            
            pause(PauseTime);            
            set(h1,'Visible','off');

            end
    end
end

Contact us