• | **Converting speed into pace and expressing it correctly**
on Aug 11, 2015 at 10:14:17 am |

Hi everyone

Please can someone help me with an expression.

I would like to convert speed (km/hr or miles/hr) into pace (min/km or min/mile).

To do this, I need to divide 60 by the speed and then express the fractions as a time.

For example my text layer named "Pace" is currently 5.67 km/hr.

To calculate the pace it would be 60 / Pace layer (5.67) = 10.58

Then i need to convert the .58 into seconds

Thanks very much

Chris

• | **Re: Converting speed into pace and expressing it correctly** on Aug 11, 2015 at 12:49:42 pm Last Edited By Xavier Gomez on Aug 11, 2015 at 12:53:52 pm |

Once you get your pace as decimal number in min/km, to decompose it in min:sec, you can do

min = Math.floor(pace);

sec = (pace-min)*60;

This gives the seconds part as a decimal number.

If you want a plain integer for the seconds, replace the second line by:

sec = Math.round((pace-min)*60);

Xavier

• | **Re: Converting speed into pace and expressing it correctly** on Aug 11, 2015 at 11:20:22 pm |

Thanks Xavier for your reply.

Would this be the full expression or just the decimal to seconds? I have pasted what you have given me, but as Im rusty with expressions, Im not sure how to write the entire expression.

Thanks a lot

• | **Re: Converting speed into pace and expressing it correctly** on Aug 12, 2015 at 9:15:32 am |

Ah ok, i started where you had troubles.

Full expression:

// x : input speed (unit distance/hour)

x = 5.67;

// pace in min / unit distance

pace = 60/x;

// decompose min:sec

min = Math.floor(pace);

sec = Math.round((pace-min)*60);

if (sec===60){sec=0; ++min;};

// display text :

"pace : " + min + " minutes " + sec + " seconds per unit distance";

• | **Re: Converting speed into pace and expressing it correctly** on Aug 12, 2015 at 10:31:37 pm |

Thank you so much Xavier.

I have tried this and am coming across a slight issue. The Pace value that this expression is converting from, is a random expression on a separate layer. I thought i would be able to pick whip the "source text" of this layer and plug it in to your expression, but it appears that I can not not do that.

Would you know how i can get the expressed value of another layer and plug it into your expression?

Thanks again for your help in this.

• | **Re: Converting speed into pace and expressing it correctly** on Aug 13, 2015 at 12:52:42 am |

You'd have to parse the speed text and extract the number, the way to do it depends on how the text looks like.

I think it would be a bit easier if the speed value was carried by a slider (with your random expression on it), and then collected (=pickwhipped) by both text layers (the speed and the pace one).

In the speed text:

x = effect("Slider Control")("Slider").value;

"Speed : " + x + "km/h";

And in the pace text, the expression from the previous post with x taking the slider value.

Xavier