Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

superpig

Cubic Formula

This topic is 5764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!