- Home /
Mapping dot product to positive range
A dot product between two angles gives me a value ranging from [-1,1], but I'm trying to use it in a target weighting system where every value (distance, facing, etc) is evaluated in a range of [0,1], with 1 being the highest possible weight. As such, is there any simple way to remap a dot product, such that a value of -1 is evaluated as 0 or 0.1 (the lowest possible weight), a value of 0 is evaluated as 0.5, and a value of 1 tops out at 1?
Answer by DiegoSLTS · Jun 23, 2015 at 08:43 PM
You can't change what values are returned by the dot product, it's an algebraic definition, but you can easily map that value on another range after getting it. Something like this should work to map the [-1,1] range to the [0,1] range:
float dotProductResult = /*some dot product*/;
dotProductResult = (dotProductResult + 1)/2;
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Help Understanding Script 2 Answers
How to calculate inner vertices of a line renderer? (math question) 1 Answer