Click here to Skip to main content
15,888,351 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Trapezoid interpolation Pin
Ralf Meier6-Feb-17 0:23
mveRalf Meier6-Feb-17 0:23 
GeneralRe: Trapezoid interpolation Pin
Joan M6-Feb-17 21:47
professionalJoan M6-Feb-17 21:47 
AnswerRe: Trapezoid interpolation Pin
Ralf Meier7-Feb-17 0:00
mveRalf Meier7-Feb-17 0:00 
GeneralRe: Trapezoid interpolation Pin
Joan M7-Feb-17 0:54
professionalJoan M7-Feb-17 0:54 
GeneralRe: Trapezoid interpolation Pin
Ralf Meier7-Feb-17 1:25
mveRalf Meier7-Feb-17 1:25 
GeneralRe: Trapezoid interpolation Pin
Joan M7-Feb-17 3:10
professionalJoan M7-Feb-17 3:10 
GeneralRe: Trapezoid interpolation Pin
Ralf Meier7-Feb-17 6:57
mveRalf Meier7-Feb-17 6:57 
GeneralRe: Trapezoid interpolation Pin
Joan M7-Feb-17 10:13
professionalJoan M7-Feb-17 10:13 
Hi again Ralf,

Well, that formula works perfectly if v0 is 0...

If v0 > 0 then I need to loop to decrease the vmax to make it suitable to the movement... which is super-ugly in the best case.

So... I guess that the formula you sent me is good, but it lacks the control of v0.

VB
LimitIterations = 1000
    ' Search the amount of time and distance we use to accelerate from v0 to vmax.
    ta = Abs((vmax - v0) / a)
    da = (v0 * ta) + (0.5 * a * ta * ta)
    ' Search the amount of time and distance we use to brake from vmax to vf.
    tf = Abs((vmax - vf) / a)
    df = (vf * tf) + (0.5 * a * tf * tf)
   
    ' If da and df are bigger than the distance to run...
    If (da + df > dist + 0.000000001) Then
      ' adapt the acceleration and braking distances to the distance we must run.
      DistTotal = xf - x0 - da - df
      RelAccDec = da / (da + df)
      dist_corr_acc = DistTotal * RelAccDec
      da = da + dist_corr_acc
      dist_corr_dec = DistTotal * (1 - RelAccDec)
      df = df + dist_corr_dec

      ' Now that we know the correct distances it should be easy to find the needed time and therefore the reached vmax after the acceleration stage.
      taux = Sqr(da / (0.5 * a))  ' Normal formula that doesn't work when v0 > 0
      taux = (Sqr((2 * a * da) + (v0 * v0)) - v0) / a  ' Rare formula that nobody understands...
      vmax = v0 + (a * taux)  ' Easy way to calculate the vmax.

      ' Ugliest code in the world... if there is not a better option I'll end up making a binary search to minimize the cpu time (I've seen cases of 500 iterations and when one starts making these ugly things no one knows what can happen).
      Do
        ' refresh the values (time, distance...) to find the maximum allowed speed for that movement vmax...
        ta = Abs((vmax - v0) / a)
        da = (v0 * ta) + (0.5 * a * ta * ta)
        tf = Abs((vmax - vf) / a)
        df = (vf * tf) + (0.5 * a * tf * tf)
        If (da + df > dist + 0.000000001) Then
          vmax = vmax - 1   ' Decrease the vmax till it works... 
          iterations = iterations + 1
          If (iterations > LimitIterations) Then
            ErrorID = 1
            Exit Do
          End If
        Else
          Exit Do
        End If
      Loop
    End If


So this is what I've done till now... It should be much easier to find the maximum speed available for the movement.

so, thank you very much for your time.

Joan.
GeneralRe: Trapezoid interpolation Pin
Ralf Meier7-Feb-17 20:21
mveRalf Meier7-Feb-17 20:21 
GeneralRe: Trapezoid interpolation Pin
Joan M7-Feb-17 20:45
professionalJoan M7-Feb-17 20:45 
GeneralRe: Trapezoid interpolation Pin
Ralf Meier7-Feb-17 21:34
mveRalf Meier7-Feb-17 21:34 
GeneralRe: Trapezoid interpolation Pin
Joan M7-Feb-17 21:46
professionalJoan M7-Feb-17 21:46 
AnswerRe: Trapezoid interpolation Pin
Ralf Meier8-Feb-17 0:33
mveRalf Meier8-Feb-17 0:33 
GeneralRe: Trapezoid interpolation Pin
Joan M8-Feb-17 1:07
professionalJoan M8-Feb-17 1:07 
GeneralRe: Trapezoid interpolation Pin
Ralf Meier8-Feb-17 2:01
mveRalf Meier8-Feb-17 2:01 
GeneralRe: Trapezoid interpolation Pin
Joan M8-Feb-17 8:59
professionalJoan M8-Feb-17 8:59 
GeneralRe: Trapezoid interpolation Pin
Ralf Meier8-Feb-17 10:05
mveRalf Meier8-Feb-17 10:05 
GeneralRe: Trapezoid interpolation Pin
Joan M9-Feb-17 4:26
professionalJoan M9-Feb-17 4:26 
GeneralRe: Trapezoid interpolation Pin
Ralf Meier9-Feb-17 5:32
mveRalf Meier9-Feb-17 5:32 
GeneralRe: Trapezoid interpolation Pin
Joan M9-Feb-17 8:59
professionalJoan M9-Feb-17 8:59 
GeneralRe: Trapezoid interpolation Pin
Ralf Meier9-Feb-17 9:35
mveRalf Meier9-Feb-17 9:35 
AnswerRe: Trapezoid interpolation Pin
Ralf Meier9-Feb-17 20:02
mveRalf Meier9-Feb-17 20:02 
GeneralRe: Trapezoid interpolation Pin
Joan M9-Feb-17 21:49
professionalJoan M9-Feb-17 21:49 
GeneralRe: Trapezoid interpolation Pin
Ralf Meier10-Feb-17 0:06
mveRalf Meier10-Feb-17 0:06 
GeneralRe: Trapezoid interpolation Pin
Joan M10-Feb-17 0:11
professionalJoan M10-Feb-17 0:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.