Advertisement

Cubic Formula

Started by September 13, 2002 12:30 PM
3 comments, last by superpig 22 years, 5 months ago
I''m trying to write a function which will look up a value on a certain type of curve, for use in camera movement and whatnot. The curve is cubic, and negative (moves down towards x-positive). It has a minimum, at the origin (0,0), and a maximum at the point (t, A). At both of those points the gradient is zero. I know that the equation for a cubic curve is in the form y = ax^3 + bx^2 + cx + d but I can''t figure out how to calculate a, b, c, and d, when given t and A. I''ve tried differentiating: dy/dx = 3ax^2 + 2bx + c and because dy/dx = 0 when x = 0, I believe c must = 0. But that''s as far as I can get. Can anyone help? Superpig - saving pigs from untimely fates - sleeps in a ham-mock at www.thebinaryrefinery.cjb.net

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

You are on the right path. Just write all the conditions.
P(x) := ax^3 + bx^2 + cx + d
P''(x) = 3ax^2 + 2bx + c

P(0) = 0 => d = 0
P''(0) = 0 => c = 0

P(t) = A => at^3 + bt^2 = A
P''(t) = 0 => 3at^2 + 2bt = 0

From the last two, you solve the 2-variables 2-equations system. I think the result is a = 2A/t^3, b = -3A/t^2, but check it yourself.


Advertisement
quote:
Original post by alvaro
You are on the right path. Just write all the conditions.
P(x) := ax^3 + bx^2 + cx + d
P''(x) = 3ax^2 + 2bx + c

P(0) = 0 => d = 0
P''(0) = 0 => c = 0

P(t) = A => at^3 + bt^2 = A
P''(t) = 0 => 3at^2 + 2bt = 0


correct...
quote:

From the last two, you solve the 2-variables 2-equations system. I think the result is a = 2A/t^3, b = -3A/t^2, but check it yourself.



I''ve the opposite, a = -2A/t³ and b = 3A/t². Surely a small oversight on your side.
By the way, this result can also be prooved because A and t are > 0, and a must be < 0. So a negative value is necessary.
misterX is right. I probably forgot a ''-'' somewhere in my notes.
You are both wonderful, wonderful people, and I will love you eternally. This has been bothering me for two days.

Superpig
- saving pigs from untimely fates
- sleeps in a ham-mock at www.thebinaryrefinery.cjb.net

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement