Skip to main content
GameDev.net gamedev.net
🔒 Locked

Simple algebra (probably)

Started by RobM Apr 13, 2009 at 5:04 PM 5 replies 700+ views
Original Post
RobM
RobM
Hi It's been quite a few years since I last did any algebra, so can anyone help with this equation? 10.0f = fError * (1200.0f / (2.0f * fDistance * 5.7978830f)) * (1.0f + (256.0f / fDistance)) What I'd like to do is get the value of 'fDistance' when the whole equation equals 10.0f (I already know what 'error' is). Simply substituting 'fDistance' with 10.0f, as I'd thought, doesn't seem to work - probably because of the addition in the second part but I can't remember how to do this. Any ideas? (before I buy a book on algebra for people who haven't used it since school!) Thanks in advance
Captain_Thunder
Captain_Thunder
Do you know the value of fError? In order to find fDistance, you need to fill in all other variables.
RobM
RobM
Hi

Yes, I know the value of fError in advance.

e.g.

10.0f = 5.5f * (1200.0f / (2.0f * fDistance * 5.7978830f)) * (1.0f + (256.0f / fDistance))

Thanks
Erik Rufelt
Erik Rufelt
Your equation can be rewritten as:
10 = k / dist + 256*k / dist^2
where k = fError * 1200 / (2 * 5.7978830)
multiply both sides by dist^2 and you get:
10*dist^2 = k*dist + 256*k
which makes:
10*dist^2 - k*dist - 256*k = 0

This is a quadratic equation. You solve a quadratic equation 'ax^2 + bx + c = 0' using the formula:
x1 = (-b + sqrt(b^2 - 4ac)) / 2a
x2 = (-b - sqrt(b^2 - 4ac)) / 2a
So you get two solutions. In your case this is:
x1 = (k + sqrt(k*k + 4*10*256*k)) / 20
Plug in the value of k from above, fError * 1200 / (2 * 5.7978830), and you have your first solution. Then just change the '+' to a '-' for the second one in the equation above.
RobM
RobM
Works like a charm, thanks for the super-quick answer, Erik.
trunks14
trunks14
I'm supposing here that all of the .0f's come from C/C++ float types.



where



and



Edit:

Oh I didn't notice someone replied already, it took me forever to get the formula right :)
RobM
RobM
Sorry trunks14, definitely not a wasted effort though, it really helps to visualise it in that format too. Thanks for your post.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.