Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

c# - Invert larger numbers to (close to) zero and zeros to larger numbers

text

I would like to transform the number beings used to create this slope/sine in the sample below to "inverse" numbers that I am showing in the goal image below.

So; A value that is close to 1 would transform to something close to 0. A value that is close to -1 would transform to something close to 0. A positive value that is close to 0 would transform to something close to 1. A negative value that is close to 0 would transform to something close to -1.

Unfortunately I don't know how to better phrase the question. I don't think I actually want "inverse" numbers, so hopefully my request makes sense. I am trying to understand what Math logic I can use to achieve my goal.

Thank you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you want something like this:

public static double Transform(double x) {
   if (Math.Abs(x) > 1) Throw new ArgumentException("Absolute value must be less or equals than 1");
   return Math.Sign(x) - x;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...