Challenge

FINAL INDEPENDENT PROJECT

F1 2021 AustrianGP Lap chart simulation

AIM :

To simulate the lap chart of 2021 Austrian Grand Prix by using MATLAB program.

FORMULA ONE

Formula One is one of the most popular sports in the world. It is the highest class of international racing for single-seater formula racing cars. Formula One was inaugurated on 13 May 1950 as the World Drivers’ Championship at Silverstone in the United Kingdom. In 1981 it became known as the FIA Formula One World Championship.

Austrian GP

Austrian GP takes place over 71 laps of the 4.318-kilometre in Red Bull ring in Spielburg, Styria, Austria

Formula One returned to the circuit in the 2014 season. The Red Bull Ring also hosted a second F1 event named the Styrian Grand Prix in 2020 and 2021 after the COVID-19 Pandemic affected the schedules of both of those seasons.

Race Track Technical Data

Lap length

4.326km (2.688 miles)

Race laps

71

Race distance

307.02km

Maximum speed

327.4kph

Full throttle

79%

Downforce level

Low/medium

Gear changes per lap

32

Lap chart:

Like a cricket scorecard, Lap chart is a log of every lap covered by each car in a race, showing the exact position of car/driver in a particular race.

Lap charts gives more information like lap-by-lap position, gap in terms of time , number of stints etc..

Program:

clear all
close all
clc

figure

VER=animatedline('linewidth',2,'color','[0 0 0.5]');%RED BULL
NOR=animatedline('linewidth',2,'color','[1 0.5 0]');%McLaren
PER=animatedline('linewidth',2,'color','[0 0 0.5]');%Red Bull
HAM=animatedline('linewidth',2,'color','[0 0.8 0.6]');%Mercedes
BOT=animatedline('linewidth',2,'color','[0 0.8 0.6]');%Mercedes
GAS=animatedline('linewidth',2,'color','[0 0 0.2]');%Alpha Tauri
TSU=animatedline('linewidth',2,'color','[0 0 0.2]');%Alpha Tauri
RUS=animatedline('linewidth',2,'color','[0 0.8 1]');%Williams
STR=animatedline('linewidth',2,'color','[0 0.3 0]');%Aston Martin
SAI=animatedline('linewidth',2,'color','[0.9 0 0]');%Ferrari
VET=animatedline('linewidth',2,'color','[0 0.3 0]');%Aston Martin
LEC=animatedline('linewidth',2,'color','[0.9 0 0]');%Ferrari
RIC=animatedline('linewidth',2,'color','[1 0.5 0]');%McLaren
ALO=animatedline('linewidth',2,'color','[0 0 0.8]');%Alpine
GIO=animatedline('linewidth',2,'color','[0.7 0 0]');%Alfa Romeo
KIM=animatedline('linewidth',2,'color','[0.7 0 0]');%Alfa Romeo
OCO=animatedline('linewidth',2,'color','[0 0 0.8]');%Alpine
LAT=animatedline('linewidth',2,'color','[0 0.8 1]');%Williams
MSC=animatedline('linewidth',2,'color','[0 0 0]');%Haas
MAZ=animatedline('linewidth',2,'color','[0 0 0]');%Haas


axis([0 71 1 20])
axis ij
grid on
xlabel('LAP(S)')
ylabel('DRIVER POSITION')


%Total number of laps
x1 =0:71;
n=72;
xx1=linspace(x1(1),x1(end),n);
%ct=1;

%Drivers position lap by lap
%VERSTAPPEN starting from 1st position
y1=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
yy1=interp1(x1,y1,xx1);
tx1=text(x1(1),y1(1),'VER');

%Lando Norris starting from 2nd
y2=[2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3];
yy2=interp1(x1,y2,xx1);
tx2=text(x1(1),y2(1),'NOR');

%SERGIO PEREZ starting from 3rd
y3=[3 3 3 3 10 10 10 10 10 10 10 10 9 9 8 8 8 7 7 7 7 7 7 7 7 7 7 7 7 6 6 6 7 10 10 9 9 8 8 8 8 8 8 8 8 7 7 7 7 6 6 6 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5]
yy3=interp1(x1,y3,xx1);
tx3=text(x1(1),y3(1),'PER');

%LEWIS HAMILTON starting from 4th
y4=[4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4];
yy4=interp1(x1,y4,xx1);
tx4=text(x1(1),y4(1),'HAM');

%VALTTERI BOTTAS starting from 5th
y5=[5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2];
yy5=interp1(x1,y5,xx1);
tx5=text(x1(1),y5(1),'BOT');

%PIERRE GASLY starting from 6th
y6=[6 6 6 6 5 5 5 5 5 5 5 5 5 5 18 17 16 16 14 14 14 14 14 13 13 12 12 12 12 12 11 10 9 8 8 7 7 6 6 6 6 6 6 6 6 9 12 12 12 11 10 10 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9];
yy6=interp1(x1,y6,xx1);
tx6=text(x1(1),y6(1),'GAS');

%YUKI TSUNODA starting from 7th
y7=[7 7 7 7 6 6 6 6 6 6 6 6 10 19 19 18 18 17 16 15 15 15 15 15 15 15 15 15 15 14 14 13 13 11 11 11 11 11 10 10 10 10 10 10 10 10 9 9 9 9 9 9 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 12 12];
yy7=interp1(x1,y7,xx1);
tx7=text(x1(1),y7(1),'TSU');

%GEORGE RUSSELL starting from 8th
y8=[8 13 12 12 12 12 12 12 12 12 12 12 13 12 11 10 10 10 9 9 9 9 9 9 9 9 9 9 9 9 10 16 16 15 14 14 14 13 12 12 12 12 12 12 12 12 11 11 11 12 11 11 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11];
yy8=interp1(x1,y8,xx1);
tx8=text(x1(1),y8(1),'RUS');

%LANCE STROLL starting from 9th
y9=[9 8 8 8 7 7 7 7 7 7 7 7 6 6 9 19 19 19 17 18 18 17 17 17 17 17 17 17 17 16 16 15 15 13 13 13 13 14 13 13 13 13 13 13 13 13 15 17 17 16 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 13 13];
yy9=interp1(x1,y9,xx1);
tx9=text(x1(1),y9(1),'STR');

%CARLOS SAINZ starting from 10th
y10=[10 14 13 13 13 13 13 13 13 13 13 13 12 13 14 9 9 8 8 8 8 8 8 8 8 8 8 8 8 8 7 7 6 6 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7 7 7 7 7 6 6];
yy10=interp1(x1,y10,xx1);
tx10=text(x1(1),y10(1),'SAI');

%SEBASTIAN VETTEL starting from 11th
y11=[11 9 9 9 8 8 8 8 8 8 8 8 7 7 5 5 5 9 18 17 16 16 16 16 16 16 16 16 16 15 15 14 14 12 12 12 12 12 11 11 11 11 11 11 11 11 10 10 10 10 14 14 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 17 17];
yy11=interp1(x1,y11,xx1);
tx11=text(x1(1),y11(1),'VET');

%CHARLES LECREC starting from 12th
y12=[12 10 10 10 11 11 11 11 11 11 11 11 11 10 7 7 7 6 6 6 6 6 6 6 6 6 6 6 6 5 5 5 5 5 6 10 10 10 9 9 9 9 9 9 9 8 8 8 8 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8];
yy12=interp1(x1,y12,xx1);
tx12=text(x1(1),y12(1),'LEC');

%DANIEL RICCIARDO starting from 13th
y13=[13 11 11 11 9 9 9 9 9 9 9 9 8 8 6 6 6 5 5 5 5 5 5 5 5 5 5 5 5 7 12 11 10 9 9 8 8 7 7 7 7 7 7 7 7 6 6 6 6 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7];
yy13=interp1(x1,y13,xx1);
tx13=text(x1(1),y13(1),'RIC');

%FERNANDO ALONSO starting from 14th
y14=[14 16 15 15 15 15 15 15 15 15 15 15 15 14 13 12 12 12 11 11 11 11 11 11 11 11 11 11 11 11 9 9 11 16 15 15 15 15 14 14 14 14 14 14 14 14 13 13 13 13 12 12 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 10 10 10 10 10];
yy14=interp1(x1,y14,xx1);
tx14=text(x1(1),y14(1),'ALO');

%ANTONIO GIOVINNAZI starting from 15th
y15=[15 12 19 19 18 18 17 17 17 17 17 17 17 16 15 14 14 14 13 13 13 13 13 14 14 14 14 14 14 17 18 18 18 18 18 17 17 17 17 17 17 17 17 17 17 17 17 16 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 14 14];
yy15=interp1(x1,y15,xx1);
tx15=text(x1(1),y15(1),'GIO');

%KIMI RAIKKONEN starting from 16th
y16=[16 15 14 14 14 14 14 14 14 14 14 14 14 13 12 11 11 11 10 10 10 10 10 10 10 10 10 10 10 10 8 8 8 7 7 6 6 9 15 15 15 15 15 15 15 15 14 14 14 14 13 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 16 16];
yy16=interp1(x1,y16,xx1);
tx16=text(x1(1),y16(1),'KIM');

%ESTABEN OCON starting from 17th
y17=[17 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20];
yy17=interp1(x1,y17,xx1);
tx17=text(x1(1),y17(1),'OCO');

%NICOLAS LATIFI starting from 18th
y18=[18 18 17 17 17 16 16 16 16 16 16 16 16 15 14 13 13 13 12 12 12 12 12 12 12 13 13 13 13 13 13 12 12 14 17 16 16 16 16 16 16 16 16 16 16 16 16 15 16 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 15 15];
yy18=interp1(x1,y18,xx1);
tx18=text(x1(1),y18(1),'LAT');

%MICK SCHUMACHER starting from 19th
y19=[19 17 16 16 16 17 18 18 18 18 18 18 18 17 16 15 15 15 15 16 17 18 18 18 18 18 18 18 18 18 17 17 17 17 16 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18];
yy19=interp1(x1,y19,xx1);
tx19=text(x1(1),y19(1),'MSC');

%NIKITA MAZPIN starting from second
y20=[20 19 18 18 19 19 19 19 19 19 19 19 19 18 17 16 17 18 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 ];
yy20=interp1(x1,y20,xx1);
tx20=text(x1(1),y20(1),'MAZ');

videofile=VideoWriter('lap_chart.avi','uncompressed avi');
videofile.FrameRate = 10;
open(videofile)

for i=1:n
 
% MAX VERSTAPPEN
    addpoints(VER,xx1(i),yy1(i));
    tx1.Position=[xx1(i),yy1(i)]
    if i==33 
        text(x1(i),y1(i),'PIT', 'Horiz','left', 'Vert','top','color','[0 0 0.5]')
    elseif i==61
        text(x1(i),y1(i),'PIT', 'Horiz','left', 'Vert','top','color','[0 0 0.5]')
    end
       
% LANDO NORRIS        
    addpoints(NOR,xx1(i),yy2(i));
    tx2.Position=[xx1(i),yy2(i)]
     if i==31 
        text(x1(i),y2(i),'PIT', 'Horiz','center','Vert','top','color','[1 0.5 0]')
     end
     
% SERGIO PEREZ     
     addpoints(PER,xx1(i),yy3(i));
    tx3.Position=[xx1(i),yy3(i)]
     if i==33 
        text(x1(i),y3(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0 0.5]')
     end
     
%LEWIS HAMILTON     
     addpoints(HAM,xx1(i),yy4(i));
    tx4.Position=[xx1(i),yy4(i)]
     if i==32 
        text(x1(i),y4(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0.8 0.6]')
     elseif i==54
         text(x1(i), y4(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0.8 0.6]')
     end

%VALTTERI BOTTAS     
      addpoints(BOT,xx1(i),yy5(i));
    tx5.Position=[xx1(i),yy5(i)]
     if i==31 
        text(x1(i),y5(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0.8 0.6]')
     end
     
%PIERRE GASLY     
     addpoints(GAS,xx1(i),yy6(i));
    tx6.Position=[xx1(i),yy6(i)]
     if i==14 
        text(x1(i),y6(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0 0.2]')
     
     elseif i==46
         text(x1(i), y6(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0 0.2]')
     end
     
%YUKI Tsunoda     
    addpoints(TSU,xx1(i),yy7(i));
    tx7.Position=[xx1(i),yy7(i)]
     if i==13 
        text(x1(i),y7(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0 0.2]')
     
     elseif i==52
         text(x1(i), y7(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0 0.2]')
     end
     
%GEORGE RUSSELL
      addpoints(RUS,xx1(i),yy8(i));
    tx8.Position=[xx1(i),yy8(i)]
     if i==31 
        text(x1(i),y8(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0.8 1]')
     end
     
%LANCE STROLL
     addpoints(STR,xx1(i),yy9(i));
    tx9.Position=[xx1(i),yy9(i)]
     if i==15
        text(x1(i),y9(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0.3 0]')
     
     elseif i==47
         text(x1(i), y9(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0.3 0]')
     end
     
%CARLOS SAINZ     
      addpoints(SAI,xx1(i),yy10(i));
    tx10.Position=[xx1(i),yy10(i)]
     if i==49 
        text(x1(i),y10(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0.9 0 0]')
     end
     
%SEBASTIAN VETTEL 
       addpoints(VET,xx1(i),yy11(i));
    tx11.Position=[xx1(i),yy11(i)]
     if i==18
        text(x1(i),y11(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0.3 0]')
     
     elseif i==50
         text(x1(i), y11(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0.3 0]')
     end
     
%CHARLES LECREC
      addpoints(LEC,xx1(i),yy12(i));
    tx12.Position=[xx1(i),yy12(i)]
     if i==35 
        text(x1(i),y12(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0.9 0 0]')
     end
 
%DANIEL RICCIARDO     
        addpoints(RIC,xx1(i),yy13(i));
    tx13.Position=[xx1(i),yy13(i)]
     if i==30 
        text(x1(i),y13(i), 'PIT', 'Horiz','left', 'Vert','top','color','[1 0.5 0]')
     end
     
%FERNANDO ALONSO     
     addpoints(ALO,xx1(i),yy14(i));
    tx14.Position=[xx1(i),yy14(i)]
     if i==33 
        text(x1(i),y14(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0 0.8]')
     end
     
%ANTONIO GIOVINNAZI
      addpoints(GIO,xx1(i),yy15(i));
    tx15.Position=[xx1(i),yy15(i)]
     if i==2
        text(x1(i),y15(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0.7 0 0]')
     
     elseif i==30
         text(x1(i), y15(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0.7 0 0]')
     end

%KIMI RAIKKONEN     
     addpoints(KIM,xx1(i),yy16(i));
    tx16.Position=[xx1(i),yy16(i)]
     if i==38 
        text(x1(i),y16(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0.7 0 0]')
     end
     
%ESTABEN OCON 
      addpoints(OCO,xx1(1),yy17(i));
    tx17.Position=[xx1(1),yy17(i)]
    
%NICOLAS LATIFI
        addpoints(LAT,xx1(i),yy18(i));
    tx18.Position=[xx1(i),yy18(i)]
     if i==34 
        text(x1(i),y18(i), 'PIT', 'Horiz','left', 'Vert','top','color','[0 0.8 1]')
     end
     
%MICK SCHUMACHER
        addpoints(MSC,xx1(i),yy19(i));
    tx19.Position=[xx1(i),yy19(i)]
     if i==35 
        text(x1(i),y19(i), 'PIT', 'Horiz','left', 'Vert','top','color','k')
     end
    
%NIKITA MAZPIN
          addpoints(MAZ,xx1(i),yy20(i));
    tx20.Position=[xx1(i),yy20(i)]
     if i==28
        text(x1(i),y20(i), 'PIT', 'Horiz','left', 'Vert','top','color','k')
        elseif i==46
         text(x1(i), y20(i), 'PIT', 'Horiz','left', 'Vert','top','color','k')
     end
        
pause(0.03);
drawnow
img = getframe(gcf)
writeVideo(videofile,img);

end

close(videofile)

Code Explanation:

  • We have to create a new figure window
  • Creating animated line for each driver specified with team colors in Formula One
  • There are 71 laps which is in X-axis and corresponding drivers position in Y-axis.
  • Y1, y2, y3……. y20 contains drivers position on each lap
  • Interpolating from original y-data to 72 evenly spaced x-values
  • Adding text for each line as three letter drivers code, depending on grid position.
  • Now we have to create an animation by adding points to the line in a for loop using the addpoints
  • And we have to animate the text (drivers code name) along with line.
  • Using if-else for driver Pit stop according to team strategy, if the driver had second pit stop use elseif statement. Repeating the same process for all 20 drivers.
  • Create an animation of a line growing as it accumulates 72 data points, display the changes on the screen after each iteration through the loop by using drawnow.
  • Creating a videofile by using videoWriter object and writing a video to an uncompressed AVI file.
  • Set frame rate for corresponding pause duration
  • Obtaining frame as a movie.
  • After the end of loop closing the videofile.

Result:

Finally, simulation of F1 2021 Austrian GP race lap chart has been obtained, you can click the link below for the videofile of lap-chart simulation.

https://youtu.be/0DyapgzZBbA

References:

Track Information

https://www.racefans.net/f1-information/going-to-a-race/red-bull-ring-circuit-information/

Race Result

https://www.formula1.com/en/results.html/2021/races/1071/austria/race-result.html

Race Highlights

https://youtu.be/LxLVqf5OtIE

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.