# stuck on extremely simple equation

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

## 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

2x - 1

##### Share on other sites
I was taught math for 13 years, just to forget even the simpliest things, thanks :)

Could you explain me how you derived the formula from the values given?

##### Share on other sites
wasn't me but here comes the answer...

0.0f - 1.0f >> -1.0f - 1.0f

0.0f * 2 = 0.0f
1.0f * 2 = 2.0f

0.0f - 1 = -1.0f
2.0f - 1 = 1.0f

>> x * 2 - 1

##### 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 on other sites
thanks everybody :)

##### 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 on other sites
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"

##### 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 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.

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 11
• 16
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633003
• Total Posts
3009849
• ### Who's Online (See full list)

There are no registered users currently online

×