I have an object which starts at velocity = 0. Accelerates to a known max speed and continues thereon at constant velocity (max speed).
My problem: How long does it take to reach a known destination?
I've visually described it like this: Where we have velocity on vertical-axis, and time on horizontal-axis. Up to where the lines intersect (let's call this time $t_M$, the blue line is the current velocity, after that, the red line. Equation for blue line is $v = a \cdot t$ where $a$ is acceleration, $v$ is velocity (vertical-axis) and $t$ is time (horizontal-axis). Equation for the red line it $v = M$, where $M$ is the max speed (known) and $v$ velocity.
Since the distance to travel is know, it should be as easy as adding up the area under the blue line, up until it equals the requested distance. Is there any way to do this without handling the areas before and after $t_M$ individually?
My current solution is:
$a$ (acceleration, known), $d$ (requested distance, known), $M$ (max speed, known)
$t_M = M / a$
$distanceDuringAccel = t_M * M / 2$ (the area under the blue line)
if distanceDuringAccel > d We will not reach our destination during acceleration, add the area under the red line aswell else we will reach destination during acceleration. t = sqrt(2 * d / a)
The above works, but feels very clumsy. Is there a better way to address this?