4

How can I denormalize a vector that has been normalized to get the original values prior to normalizing?

For example:

vec = [-0.5, -1.0, 0.0]
vec_length = sqrt(vec.x^2 + vec.y^2 + vec.z^2)
vec_normalized = [vec.x/vec_length, vec.y/vec_length, vec.z/vec_length]

yields:

vec_length = 1.11803
vec_normalized = [-0.447214,-0.894427,0]

How can I get the original vector [-0.5, -1.0, 0.0] from the normalized vector [-0.447214,-0.894427,0]?

Thanks!

user3417614
  • 131
  • 2
  • 7

2 Answers2

7

You can't.
There are infinite number of vectors whose normalized form is [-0.447214, -0.894427, 0].

If you want a "nicer" form, you can try up-scaling to an arbitrary number, random example:

I want x to be -3:

scale = -3 / vec_normalized.x;
vec2 = [vec_normalized.x * scale, vec_normalized.y * scale, vec_normalized.z * scale];

result:

scale = 6.70819787
vec2 = [-3, -6, 0]

But be careful not to choose a component which is 0, because that would yield scale = infinity.

TWiStErRob
  • 44,762
  • 26
  • 170
  • 254
3

Recovery: The inverse of division is multiplication. Hence:

vec = [vec_normalized.x*vec_length,
       vec_normalized.y*vec_length,
       vec_normalized.z*vec_length]

If vec_length is unknown, you can not restore the original vector. Normalization can be seen as a lossy compression of direction+magnitude to just direction. There is an infinite number of vectors that map to a single normalized vector.

Mathematically, a function that maps multiple different input values to a single output value, is not invertible.

A nice property about normalized vectors is that if you want a specific magnitude f with that direction, you can just multiply your vector f, and know that it has length f.

Precision: However, note that this does not necessarily give you the original vector, but rather, in the general case, an approximation thereof. This is because of the finite precision with which floating point numbers are represented in memory. Consequently, the normalized vector in computing might not actually be the the exact normalized vector mathematically.

Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
  • I think he wants to get `[-0.5, -1.0, 0.0]` without knowing `vec_length`, but only knowing ONLY `[-0.447214,-0.894427,0]`... – TWiStErRob Nov 13 '14 at 15:39
  • @TWiStErRob: I am not sure; that just came to my mind, too. Maybe it was too obvious to me that this should be obvious. (Note: When I say obvious, I do so in a negative way, critisizing myself, because "obvious" is a crap argument) – Sebastian Mach Nov 13 '14 at 15:41
  • Yep, at uni we had the same issue, there were about 5 levels of trivial (=obvious) based who said it. As I saw it took you 2-3 edits to get to a point where you realized that the solutions are infinite so it's far from obvious. – TWiStErRob Nov 13 '14 at 16:22
  • Let's say, to me it's obvious that you cannot restore the unnormalized vector, and even the (non-)invertibility of some functions, like the normalize function, is obvious, so I just assumed the OP still has the length around. Btw, you have a [fencepost error](http://en.wikipedia.org/wiki/Off-by-one_error#Fencepost_error) in your counting of my edits, which were only 1-2 ;) – Sebastian Mach Nov 13 '14 at 16:35
  • Agreed for both parts of your comment, note that I was counting the updates I saw in real time and not the squashed edits SO does and stores in history ;) – TWiStErRob Nov 13 '14 at 16:42
  • @TWiStErRob: I am confused. Was a tough day :P The better the sleep that follows :) – Sebastian Mach Nov 13 '14 at 21:19