Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 985241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:08:10+00:00 2026-05-16T05:08:10+00:00

I’m trying to write a method that interpolates from 0 to x (position of

  • 0

I’m trying to write a method that interpolates from 0 to x (position of an object in one dimension) over time using acceleration at the beginning and deceleration at the end (ease out / ease in) with the only constraints that the total time is provided, as well as the duration of the acceleration and deceleration. the motion should replicate the inertia effect and I’m considering a Hermite curve for the non-linear portions.

double Interpolate(
    double timeToAccel, double timeCruising, double timeToDecel,
    double finalPosition,
    double currentTime)
{
    //...
}

Can someone point me out to a portion of code that does that? I don’t know how to integrate the Hermite curve, hence don’t know how much I’ll move in the accelerating portion or in the decelerating portion, and in turn I can’t figure out what will be the speed in the linear portion.

Thanks.

Some reference to illustrate my question.

Edit:

  • start and end speeds are null, and the current time is also part of the parameters in the method, I’ve updated the signature.
  • basically the idea is to imagine a move at constant speed on a distance d, this gives a total duration. Then we add the acceleration and deceleration phases, while maintaining the same duration, hence we have an unknown new cruise speed to determinate (because we move less in the Hermite phases than in the linear phases they have replaced). Maybe the amount of move lost in the Hermite phases, compared to a linear move of the same duration is the ratio between the top and bottom area in the curves, just an idea from a non expert.

Edit: Roman and Bob10 have provided full working solutions. I implemented the code from Roman. Thanks to you both, guys! I appreciate your perfect support and your detailed solutions, you saved me long searches and trials.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:08:10+00:00Added an answer on May 16, 2026 at 5:08 am

    First, let’s make a cubic hermite spline function:

    /*
      t  - in interval <0..1>
      p0 - Start position
      p1 - End position
      m0 - Start tangent
      m1 - End tangent
    */
    double CubicHermite(double t, double p0, double p1, double m0, double m1) {
       t2 = t*t;
       t3 = t2*t;
       return (2*t3 - 3*t2 + 1)*p0 + (t3-2*t2+t)*m0 + (-2*t3+3*t2)*p1 + (t3-t2)*m1;
    }
    

    Now your task is to calculate the p0, p1, m0 and m1 for both ease-in and ease-out portions. Let us add a few variables to make the math a bit easier to write:

    double Interpolate(
        double timeToAccel, double timeCruising, double timeToDecel,
        double finalPosition,
        double currentTime) {
    
        double t1 = timeToAccel;
        double t2 = timeCruising;
        double t3 = timeToDecel;
        double x = finalPosition;
        double t = currentTime;
    

    We need to specify where should the object be when it stops accelerating and starts decelerating. You can specify these however you please and still produce a smooth movement, however, we would like a somewhat “natural” solution.

    Let’s assume that the cruising speed is v. During crusing, the object travels distance x2 = v * t2. Now, when the object accelerates from 0 to speed v, it travels distance x1 = v * t1 / 2. Same for deceleration x3 = v * t3 / 2. Put all together:

    x1 + x2 + x3 = x

    v * t1 / 2 + v * t2 + v * t3 / 2 = x

    From that we can calculate our speed and the distances:

        double v = x / (t1/2 + t2 + t3/2);
        double x1 = v * t1 / 2;
        double x2 = v * t2;
        double x3 = v * t3 / 2;
    

    And now that we know everything, we just feed it into our cubic hermite spline interpolator

        if(t <= t1) {
           // Acceleration
           return CubicHermite(t/t1, 0, x1, 0, v*t1);
        } else if(t <= t1+t2) {
           // Cruising
           return x1 + x2 * (t-t1) / t2;
        } else {
           // Deceleration
           return CubicHermite((t-t1-t2)/t3, x1+x2, x, v*t3, 0);
        }
    }
    

    I tested this in Excel, here’s the equivalent VBA code to play with. There are some divisions by zero for boundary conditions, I leave fix to this as an excercise to the reader

    
    Public Function CubicHermite(t As Double, p0 As Double, p1 As Double, _
    m0 As Double, m1 As Double) As Double
       t2 = t * t
       t3 = t2 * t
       CubicHermite = (2 * t3 - 3 * t2 + 1) * p0 + _
    (t3 - 2 * t2 + t) * m0 + (-2 * t3 + 3 * t2) * p1 + (t3 - t2) * m1
    End Function
    
    Public Function Interpolate(t1 As Double, t2 As Double, t3 As Double, _
    x As Double, t As Double) As Double
        Dim x1 As Double, x2 As Double, x3 As Double
    
        v = x / (t1 / 2 + t2 + t3 / 2)
        x1 = v * t1 / 2
        x2 = v * t2
        x3 = v * t3 / 2
    
        If (t <= t1) Then
           Interpolate = CubicHermite(t / t1, 0, x1, 0, v*t1)
        ElseIf t <= t1 + t2 Then
           Interpolate = x1 + x2 * (t - t1) / t2
        Else
           Interpolate = CubicHermite((t-t1-t2)/t3, x1+x2, x, v*t3, 0)
        End If
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.