Sign in to follow this  

stuck on extremely simple equation

This topic is 4863 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

Ok, this is really embarassing, shame on me. I have a float in the range of 0.0f to 1.0f, so e.g. the point in the middle of the screen is 0.5f, on the left 0.0f and on the right 1.0f. I need to convert this value to match up with the directx perspective range which goes from -1.0f to 1.0f. So basically 0.5f would become 0.0f, 0.0f would become -1.0f and 1.0f would become 1.0f 0.0f -> -1.0f 0.5f -> 0.0f 1.0f -> 1.0f I know, this is really easy, but I can't figure out how to do this :( regards

Share this post


Link to post
Share on other sites
Or, for a common sense answer:

You have a set of values whose range is 1 (0 to 1). You those values to be in a range of 2, so you multiply those values by 2. The range is now 0 to 2, but you want it to be -1 to 1, to you subract 1.

[Edited by - thedevdan on August 20, 2004 7:54:24 PM]

Share this post


Link to post
Share on other sites
Try thinking of it pictorially in your head, failing that draw a picture of what you want. That may work for you, different people think in different ways. Investigating how your brain works and then working on developing your method of thought and learning with that in mind can work wonders.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I find that using "y = mx + c" makes these kind of linear mappings very simple. Treat y as your output and x as your input, then you only need 2 actual cases of your mapping to solve for m and c. Hobserve:

mapping:
(x) -> (y)
0.0f -> -1.0f (1st case)
1.0f -> 1.0f (2nd case)

In the 1st case, we have:

(-1.0f) = m(0.0f) + c

hence c = -1.0f

Subs c into the second case to solve for m:

(1.0f) = m(1.0f) - 1.0f,
m = 2.0f;

so, the mapping is "y = 2x - 1"

The cool thing about this method is that it works for *any* linear mapping.


Share this post


Link to post
Share on other sites
The useless thing about that method is that it doesn't work for anything else. Fortunately many things are linear, so if you can't do it another way then your method isn't that bad. However if you find a situation where it isn't linear you then have to understand the method for solving that system as well. If you can just visualise the system then you'll always have a good shot at solving it, without any prior knowledge of the type of system involved. I'm not explaining it very well.

Let's have an example, you need an orthogonal transformation that takes given vectors to others. Try to do it using simultaneous equations and you're in for a difficult time. But understand the system and you'll be able to find some nice shortcuts.

Not a great example, oh well. Just choose whatever method you find the easiest.

Share this post


Link to post
Share on other sites
AP: the cool thing about it is that it works for any polynomial.

higherspeed: for each problem there are slow and fast answers. Of course, when problems involve more than one dimension, linear algebra will come in handy. However, for problems as simple as this one, simply considering the desired equation and substituting two known values is faster.

Share this post


Link to post
Share on other sites
ToohrVyk: I think you misunderstood my point. What I'm saying is that thinking the problem out, as the initial solutions centre on, is a far better general method, which will always be better than applying a solution that relies on a specific method.

These methods, while right and for many people useful, only limit what you can do.

Share this post


Link to post
Share on other sites
[Argh, I just understood your point. You're right about the fact that you need to go beyond the particular solutions, and the larger the mathematical culture, the easier it is to adapt general solutions to particular cases, or to find a particular solution that is adapted. I'll leave my previous response for... entertainment purposes]

I entirely disagree with you, because of two things.

First, to consider a linear equation y = ax+b is also a general solution (it is, in fact, an interpolation polynomial method applied to a degree one polynomial) that also works for problems that linear algebra has many troubles [EDIT: solving] (such as interpolating between N points with a C-infinite easily integrable function). Sure, you may argue that usual problems in the computer world involve linear equations, not polynomials, but this restriction is just going against the generality of your solution ("it's more general in this particular case").

Also, even if it was a more general solution, this does not make it absolutely better than any other solution. Actually, most of the time it is the particular solutions that are used, rather than the general ones. Why? Because the more information you know about a problem, the faster it is to solve it, and by definition, general solutions "know" less about the problems than those particular solution that actively assume things.

I'd just like to finish by saying that using method A for one problem does not prevent you from using methods B, C, D... for other problems. There's nothing like a law in mathematics that says "thou shalst not change theorems once in a lifetime". For each problem, find the least general solution that applies to that problem (or even create one), and use it: in most cases it will be faster than the general method.

Share this post


Link to post
Share on other sites
I'm not saying that you should choose a more general method. I'm saying that you shouldn't confine yourselves to methods at all. In doing so you leave yourself open to tripping up on an easy problem. The best maths exams try to test your mathematical ability and not how well you can carry out a certain method. They'll give problems that are certainly solvable using a given method, but there will be an easier way, a shortcut.

Clearly methods are important. But they should never be relied upon. They are clearly useful when mathematical ability isn't needed. For instance programming the algorithm into a computer. But there will always be situations that trip people up.

Share this post


Link to post
Share on other sites

This topic is 4863 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this