taro <- function(t,v=80,d=2400){
to=d/v # time for oneway trip
if((t%/%to)%%2==0) return(v*t%%to)
else return(d - v*t%%to)
}

taro=Vectorize(taro)
t=seq(0,300,0.1)
plot(t,taro(t,v=80),type='l',bty='l',xlab='時間',ylab='Aからの距離',axes=F)
axis(2)
axis(1,labels = F)

jiro <- function(t,.v=70,.d=2400){
.d - taro(t,v=.v,d=.d)
}

jiro=Vectorize(jiro)
lines(t,jiro(t),col=2)
legend('bottom',bty='n',legend=c('太郎','次郎'),col=1:2,lwd=1)