[chronojump] Plotting the model with the time shifting



commit de472341aac2266c9a627935b1dea941dd66653b
Author: Xavier Padullés <testing chronojump org>
Date:   Fri Jan 15 22:35:50 2021 +0100

    Plotting the model with the time shifting

 r-scripts/sprintPhotocells.R | 19 +++++++++++--------
 r-scripts/sprintUtil.R       |  5 +++--
 2 files changed, 14 insertions(+), 10 deletions(-)
---
diff --git a/r-scripts/sprintPhotocells.R b/r-scripts/sprintPhotocells.R
index 17e55102..7a05ce28 100644
--- a/r-scripts/sprintPhotocells.R
+++ b/r-scripts/sprintPhotocells.R
@@ -184,7 +184,7 @@ drawSprintFromPhotocells <- function(sprintDynamics, splitTimes, positions, titl
         #Calculating measured average speeds
         avg.speeds = diff(positions)/diff(splitTimes)
         textXPos = splitTimes[1:length(splitTimes) - 1] + diff(splitTimes)/2
-        xlims = c(0, splitTimes[length(splitTimes)])
+        xlims = c(-sprintDynamics$T0, splitTimes[length(splitTimes)])
         
         # Plotting average speed
         par(mar = c(7, 4, 5, 7.5))
@@ -195,21 +195,20 @@ drawSprintFromPhotocells <- function(sprintDynamics, splitTimes, positions, titl
                 xlab="Time[s]", ylab="Velocity[m/s]",
                 axes = FALSE, yaxs= "i", xaxs = "i")
         text(textXPos, avg.speeds, round(avg.speeds, digits = 2), pos = 3)
-        axis(3, at = splitTimes, labels = splitTimes)
+        axis(3, at = c(-sprintDynamics$T0,splitTimes), labels = c(-sprintDynamics$T0,splitTimes))
         
         # Fitted speed plotting
         par(new=T)
-        plot(time, sprintDynamics$v.fitted, type = "l", xlab="", ylab = "",
+        plot((sprintDynamics$t.fitted - sprintDynamics$T0), sprintDynamics$v.fitted, type = "l", xlab="", 
ylab = "",
              ylim = c(0, max(c(avg.speeds, sprintDynamics$Vmax) + 1)), xlim = xlims,
              yaxs= "i", xaxs = "i", axis = F) # Fitted data
         axis(2, at = seq(0, sprintDynamics$Vmax + 1, by = 1))
         abline(h = sprintDynamics$Vmax, lty = 2)
         mtext(side = 1, line = 3, at = splitTimes[length(splitTimes)]*0.25, cex = 1.5 , substitute(v(t) == 
Vmax*(1-e^(-K*t)), list(Vmax="Vmax", K="K")))
-        
         if(plotFittedAccel)
         {
                 par(new = T)
-                plot(time, sprintDynamics$a.fitted, type = "l", col = "magenta", yaxs= "i", xaxs = "i", 
xlab="", ylab = "",
+                plot((sprintDynamics$t.fitted - sprintDynamics$T0), sprintDynamics$a.fitted, type = "l", col 
= "magenta", yaxs= "i", xaxs = "i", xlab="", ylab = "",
                      ylim=c(0,sprintDynamics$amax.fitted), xlim = xlims,
                      axes = FALSE )
                 axis(side = 4, col ="magenta", at = seq(0,max(sprintDynamics$a.fitted), by = 1))
@@ -219,7 +218,7 @@ drawSprintFromPhotocells <- function(sprintDynamics, splitTimes, positions, titl
         if(plotFittedForce)
         {
                 par(new=T)
-                plot(time, sprintDynamics$f.fitted, type="l", col="blue", yaxs= "i", xaxs = "i", xlab="", 
ylab="",
+                plot((sprintDynamics$t.fitted - sprintDynamics$T0), sprintDynamics$f.fitted, type="l", 
col="blue", yaxs= "i", xaxs = "i", xlab="", ylab="",
                      ylim=c(0,sprintDynamics$fmax.fitted), xlim = xlims,
                      axes = FALSE)
                 axis(line = 2.5, side = 4, col ="blue", at = seq(0, sprintDynamics$fmax.fitted + 100, by = 
100))
@@ -230,7 +229,7 @@ drawSprintFromPhotocells <- function(sprintDynamics, splitTimes, positions, titl
         if(plotFittedPower)
         {
                 par(new=T)
-                plot(time, sprintDynamics$p.fitted, type="l", axes = FALSE, xlab="", ylab="", col="red"
+                plot((sprintDynamics$t.fitted - sprintDynamics$T0), sprintDynamics$p.fitted, type="l", axes 
= FALSE, xlab="", ylab="", col="red"
                      , ylim=c(0,sprintDynamics$pmax.fitted + .1 * sprintDynamics$pmax.fitted), xlim = xlims
                      , yaxs= "i", xaxs = "i")
                 abline(v = sprintDynamics$tpmax.fitted, col="red", lty = 2)
@@ -263,7 +262,11 @@ testPhotocellsCJ <- function(positions, splitTimes, mass, personHeight, tempC, p
 {
         sprint = getSprintFromPhotocell(position = positions, splitTimes = splitTimes)
         print(sprint)
-        sprintDynamics = getDynamicsFromSprint(K = sprint$K, Vmax = sprint$Vmax, mass, tempC, personHeight, 
maxTime = max(splitTimes))
+        sprintDynamics = getDynamicsFromSprint(K = sprint$K, Vmax = sprint$Vmax, T0 = sprint$T0
+                                               , Mass = mass
+                                               , Temperature = tempC
+                                               , Height = personHeight
+                                               , maxTime = max(splitTimes))
         print(paste("K =",sprintDynamics$K.fitted, "Vmax =", sprintDynamics$Vmax.fitted))
         
         drawSprintFromPhotocells(sprintDynamics = sprintDynamics, splitTimes, positions, title = personName)
diff --git a/r-scripts/sprintUtil.R b/r-scripts/sprintUtil.R
index 8caf402e..85367f52 100644
--- a/r-scripts/sprintUtil.R
+++ b/r-scripts/sprintUtil.R
@@ -24,7 +24,7 @@ source(paste(options[1], "/scripts-util.R", sep=""))
 
 #Calculates all kinematic and dynamic variables using the sprint parameters (K and Vmax) and the conditions 
of the test (Mass and Height of the subject,
 #Temperature in the moment of the test and Velocity of the wind).
-getDynamicsFromSprint <- function(K, Vmax, Mass, Temperature = 25, Height , Vw = 0, maxTime = 10)
+getDynamicsFromSprint <- function(K, Vmax, Mass, T0 = 0, Temperature = 25, Height , Vw = 0, maxTime = 10)
 {
        # maxTime is used for the numerical calculations
         # Constants for the air friction modeling
@@ -44,7 +44,7 @@ getDynamicsFromSprint <- function(K, Vmax, Mass, Temperature = 25, Height , Vw =
         sfv.rel.fitted = sfv.fitted / Mass
 
         # Getting values from the exponential model. Used for numerical calculations
-        time = seq(0,maxTime, by = 0.01)      
+        time = seq(0,maxTime + T0, by = 0.01)      
         v.fitted=Vmax*(1-exp(-K*time))
         a.fitted = Vmax*K*exp(-K*time)
         f.fitted = Mass*a.fitted + Ka*(v.fitted - Vw)^2
@@ -75,6 +75,7 @@ getDynamicsFromSprint <- function(K, Vmax, Mass, Temperature = 25, Height , Vw =
                     t.fitted = time,
                     K.fitted = K,
                     Vmax.fitted = Vmax,
+                    T0.fitted = T0,
                     amax.fitted = amax.fitted,
                     fmax.fitted = fmax.fitted,
                     fmax.rel.fitted = fmax.rel.fitted,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]