Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411485 Posts in 69371 Topics- by 58427 Members - Latest Member: shelton786

April 24, 2024, 04:41:33 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Help solving this equation
Pages: [1]
Print
Author Topic: Help solving this equation  (Read 617 times)
MadWatch
Level 1
*



View Profile WWW
« on: September 20, 2014, 02:10:29 PM »

Hello everyone.

I'm working on an algorithm to smooth the animations my artist is making into our home made animation editor. By "smoothing" I mean giving the moving nodes a continuous velocity profile. So my algorithm must transform a broken velocity profile into a continuous one.

So here is the hard part.


I have a function that looks like this. This is the velocity profile I want. The variables I know are:
  • sV the start velocity (not necessarily null)
  • eV the end velocity (not necessarily null nor equal to sV)
  • et the total time
  • d the surface below the curve, that also is the distance of the move

I'm trying to use those to compute these outputs:
  • mV the maximal velocity
  • mt the time of the maximal velocity

The constraint is that the acceleration must equal the deceleration. In other words, both segments of the curve have the same slope (the later is just the negative of the former).

From this I could write the following equations:
  • d = (((mV - sV)^2 / 2*mt^2) + sV) * mt + (((eV - mV)^2 / 2*(et - mt)^2) + mV) * (et - mt)
    which can be simplified into
    d = (mV - sV)^2 / 2*mt + sV*mt + (eV - mV)^2 / 2*(et - mt) + mV*et - mV*mt
    This first equation is the primitive of my velocity.
  • (mV - sV) / mt = -(eV - mV) / (et - mt)
    which is the constraint that both slope shall be equal.

So. Two unknown variables. Two equations. The last equation allow me to define one unknown variable from the other. This shall be solvable right ? Right ?

I didn't manage to solve it Facepalm

When I put the equation on the paper I get something horribly long and complicated and I can't put it into a form that allow me to extract a solution. When I enter it into an equation solving program I get horribly long solutions that are unusable because they always produce division by zero.

Yet, I don't see any reason why this wouldn't be solvable. I guess I'm making a mistake here Shrug
Could someone give me a clue on this ?  Beg

Regards






Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #1 on: September 20, 2014, 03:22:22 PM »

Look up intersection of two lines, there's loads of articles on it. Think of it as a geometry problem. Work out mV and mT first. d should follow afterwards.
Logged
Boreal
Level 6
*


Reinventing the wheel


View Profile
« Reply #2 on: September 20, 2014, 04:38:03 PM »

Look up intersection of two lines, there's loads of articles on it. Think of it as a geometry problem. Work out mV and mT first. d should follow afterwards.

I don't think he knows the slope of the lines, he has to calculate that based on the integral.
Logged

"In software, the only numbers of significance are 0, 1, and N." - Josh Barczak

magma - Reconstructed Mantle API
jgrams
Level 3
***



View Profile
« Reply #3 on: September 20, 2014, 05:44:39 PM »

I'm not sure where you get the squared terms in the d equation from.

Shouldn't it be d = mt*(sv + mv)/2 + (et-mt)*(ev+mv)/2?

That makes it all nicely solveable. Unless I've screwed it up (which is certainly possible, so do the math yourself!) I get:

Code:
mv = (2*d - t*(ev-sv)) / (2*t)
mt = (2*d - t*(sv+mv)) / (sv+ev)



Two asides:

I think that two unknowns and two equations doesn't necessarily mean a solution exists. It usually does, but they could cancel out somehow so that you still have no solutions or an infinite number of solutions. Even if a solution does exist, there may not be a closed-form or an analytical solution. There are plenty of situations where there is no equation or even an infinite series which gives the solution, so you have to use a numerical solver like Newton's method or whatever.

And it's "latter" (two 't's) and former, not "later".
Logged
MadWatch
Level 1
*



View Profile WWW
« Reply #4 on: September 20, 2014, 11:57:14 PM »

I'm not sure where you get the squared terms in the d equation from.
You're right. I screwed up with my first equation. It's obvious when looking at it from a geometric point of view Embarrassed

Thank you very much jgrams Smiley
Logged
MadWatch
Level 1
*



View Profile WWW
« Reply #5 on: September 21, 2014, 01:55:03 AM »

Code:
mv = (2*d - t*(ev-sv)) / (2*t)
mt = (2*d - t*(sv+mv)) / (sv+ev)
It doesn't look like those works (assuming the 't' is 'et'). I don't get the expected results when using them. How did you get them ?

I tried solving this on my own but all I get is a second order polynomial equation with no real solution. So I guess I screwed again Sad
Logged
MadWatch
Level 1
*



View Profile WWW
« Reply #6 on: September 21, 2014, 03:50:26 AM »

I think I got it  Smiley
Code:
mv = (-4.*d - sqrt(((4.*d)**2.) + 8.*et*((sv**2. + ev**2.)*et - (2.*ev + 2.*sv)*d))) / (-4.*et)
mt = (et*mv - et*sv) / (2.*mv - ev - sv)
Logged
jgrams
Level 3
***



View Profile
« Reply #7 on: September 21, 2014, 03:58:55 AM »

Oh, good. Yeah, I flipped a sign that caused a bunch of things to cancel out. I don't know where my brain is these last few days.

I was just posting to say that it sucked that you got only imaginary solutions, because it looked like there should be enough freedom for there to be a real one...

And...supposedly it's better (more numerically stable) to solve quadratic equations like this:

Code:
quadratic_roots(a, b, c) {
d = b*b - 4*a*c;  // discriminant
if(d >= 0) {
s = (b<0) ? -1 : 1
q = -(b + s*sqrt(d))
return [-q/a, -c/q]
}
return [];
}
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic