My Math Forum  

Go Back   My Math Forum > High School Math Forum > Algebra

Algebra Pre-Algebra and Basic Algebra Math Forum


Reply
 
LinkBack Thread Tools Display Modes
January 22nd, 2008, 04:24 AM   #1
Newbie
 
Joined: Jan 2008

Posts: 3
Thanks: 0

Reverse calculation

Hey everyone. Nice to be here =)
I'm programming a game, and I have a function which calculates y(vertical screen position) based on a variable I call Y, and other variables as well, like z.

And for the game-editor, I want to be able to click the screen and it would calculate what the Y would be for that position, so I have a function which calculates the Y based on y instead.

At first this function was easy to reverse because then it looked like something like this:
y= horizon+Y*z+z/10;
So the reversed version for that would look like this:
Y= (y-horizon-z/10)/z;

With these I could calculate from y to Y and from Y to y.

But now I've made the function more complex for more depth.

Now it looks like this:
y=horizon+z/ground*(600-horizon)+(Y+(0-(Y*Y)/(((600-horizon)/18.5)*(600-horizon))))*(z/100);
Yeah, that's a big evil function.
And no matter how much I try, I can't seem to figure out how to reverse it in order to get Y based on y.

I started by cutting out almost all of the function to make it really simple, and made a reversed function of that, then adding more to the function and updating the reversed one. But I only got this far:
y= (Y+(0-(Y*Y)));
and the reversed one:
Y=y-(y-(Math.sqrt(0-y)));

Math.sqrt is square root so Math.sqrt(100) would return 10

I hope some of the geniuses in here could lend a hand, or at least point me in the right direction.
Any comments are welcome.

Thanks =)
Clox is offline  
 
January 22nd, 2008, 06:43 AM   #2
Global Moderator
 
CRGreathouse's Avatar
 
Joined: Nov 2006
From: UTC -5

Posts: 16,046
Thanks: 938

Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms
The trouble is that the function is complicated by many unrelated things. Let's take them out one at a time.

y=horizon+z/ground*(600-horizon)+(Y+(0-(Y*Y)/(((600-horizon)/18.5)*(600-horizon))))*(z/100);

Define A = horizon + z/ground*(600-horizon). Then

y = A + (Y - (Y*Y)/(((600-horizon)/18.5)*(600-horizon)))*(z/100);

Define C = z/100/(((600-horizon)/18.5)*(600-horizon)). Then
y = A + (z/100)*Y - C*(Y*Y);

Define B = z/100. Then

y = A + B*Y - C*(Y*Y);

Now you can see that you need only the quadratic formula to solve this. Of course choosing which solution you need is perhaps not easy... testing it by having both appear (in some form) marked differently while working on the program might be the best way.
CRGreathouse is offline  
January 23rd, 2008, 12:24 AM   #3
Newbie
 
Joined: Jan 2008

Posts: 3
Thanks: 0

Thanks, CRGreathouse.
I have now solved the problem. And I simplified it and made it more effective too. I have done a lot reading and searching and I have now a lot better understanding of equations much thanks to you.
And now im actually looking forward to learn more about equations and actually math in general =)

Thanks a lot
Clox is offline  
Reply

  My Math Forum > High School Math Forum > Algebra

Tags
calculation, reverse



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
reverse calculation of growth rates outtahere Economics 3 October 3rd, 2013 11:07 AM
reverse engineering a graph ravynware Algebra 0 April 15th, 2012 07:11 PM
reverse n vdrn Number Theory 28 October 22nd, 2011 04:07 PM
Reverse Modulo swtrse Number Theory 2 August 6th, 2009 04:53 AM
Reverse solve f(x)? NumberA Algebra 5 April 19th, 2009 11:03 AM





Copyright © 2019 My Math Forum. All rights reserved.