C#にArduinoのマップのような機能はありますか?
16203 次
2 に答える
22
あなたは拡張メソッドでそれを行うことができます(decimal
例えば):
public static class ExtensionMethods
{
public static decimal Map (this decimal value, decimal fromSource, decimal toSource, decimal fromTarget, decimal toTarget)
{
return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}
}
次に、次のように使用できます。
decimal res = 2.Map(1, 3, 0, 10);
// res will be 5
于 2013-01-16T07:50:32.177 に答える
4
private static int map(int value, int fromLow, int fromHigh, int toLow, int toHigh)
{
return (value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
}
于 2019-06-19T10:30:29.437 に答える