Random commentary about C++, STL, Boost, Perl, Python, Algorithms, Problem Solving and Web Search
A classic problem when writing plotting software.We assume that N/M = S/T if we want to keep the aspect ratio unchanged.Regardless of the aspect ratio, we shouldtransform the co-ordinates x,y of each datapoint to x * S/N and y * T/M
There are a few ways you can do this. Depends a lot upon what type of information you want preserved. Solution 1: Trivial one. Here compute new value of x to floor(S/N)*x for each x. Compute y to be floor(T/M)*y. However this solution does not take into account the input "spread". For example if your inputs for 'x' is largely less than or equal to S but have say only one at N, you would have "compressed" all x to accommodate this single occurrence.The following two solutions inspects the input to determine how the values of 'x' and 'y' are spread to determine what algorithm to use to make the mapping:Many values in the input are in the range 0<x<S and fewer in the S,x<N range:Solution 2: Use something similar to A-law or Mu-Law schemes used to represent speech in the audio world. Here values on the lower side tend to be mapped more accurately while those on the higher side get mapped more aggressively.Many values of x are in the S<x<N range and fewer in the 0<x<S range.Solution 3: Use a 'inverse' mapping.