Denormalize vector

瘦欲@ 提交于 2019-12-01 10:40:14

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.

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.

Real Solution: Considering that you are struggling about this simple math, you should definitely get some good introductory material about the maths involved, some good books for example.*


*: Yes, this is intended to be part of the answer. Teach fishing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!