- #1
newjerseyrunner
- 1,533
- 637
I have this function that I need to reverse.
I can't figure out how to reverse it though, I should be able to take the resulting int, put it through a function with the height value and get back distance. Normally, when I get stuck, I just ask wolfram alpha to solve it for me, but that doesn't seem to be giving me an answer.
I feel like wolfram alpha is having trouble because the general equation has some quirks that the actual code won't? Like the fact that both renderer -> viewPortHalfH and dist are always positive and non-zero. How would I tell wolfram alpha about this (would it even help?)
int getYPosition(float height, float dist) const {
const float hh = renderer -> viewPortHalfH / dist;
return renderer -> viewPortHalfH - hh + hh * ((height + renderer -> player -> verticalAngle * dist) / 128.0f);
}
float getDistYPosition(float height, int yPosition) const {
//wtf, I can't figure out what this should be
return 1;
}
I can't figure out how to reverse it though, I should be able to take the resulting int, put it through a function with the height value and get back distance. Normally, when I get stuck, I just ask wolfram alpha to solve it for me, but that doesn't seem to be giving me an answer.
Is there something with my equation that makes it fundamentally irreversible?y = k - (k/d) + (k/d) * ((h + v * d) / 128) solve d
I feel like wolfram alpha is having trouble because the general equation has some quirks that the actual code won't? Like the fact that both renderer -> viewPortHalfH and dist are always positive and non-zero. How would I tell wolfram alpha about this (would it even help?)