- Home /
math question, remapping angle value
Hi there !
I have an angle float value in degrees varying from 0 to 360 stored in the variable named angle.
I want to remap that angle value to values ranging from -1 to 1 that would be stored in float variables named verticalPower and horizontalPower. I made an image to show how I would like this to be remapped, for example when angle==90 verticalPower=0 and horizontalPower=1.
The reason why I am stuck is because the angle value resets to 0 after reaching 360. I can not use simple remapping like this: low2 + (value - low1) * (high2 - low2) / (high1 - low1)
Any idea how I could acheive this ??
Thank you
Answer by whydoidoit · Jul 07, 2012 at 01:21 PM
Um - have you tried taking the Sin of that angle for your blue and the Cos for red?
Answer by snow404 · Jul 07, 2012 at 03:45 PM
This is really a nice suggestion and still works but not perfectly because sin45=0.7 and not 0.5. Similar results happen with cos. Thank you very much !
Answer by celikomerdev · Mar 12, 2021 at 07:09 AM
public static Vector3 LocalTilt(Vector3 euler)
{
Vector3 localTilt = Vector3.zero;
localTilt.x = Mathf.Sin(euler.x*Mathf.Deg2Rad);
localTilt.y = Mathf.Sin(euler.y*Mathf.Deg2Rad);
localTilt.z = Mathf.Sin(euler.z*Mathf.Deg2Rad);
return localTilt;
}