[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Need help for little math problem
From: |
Michael Goffioul |
Subject: |
Need help for little math problem |
Date: |
Thu, 22 Sep 2011 10:27:06 +0100 |
Hi,
I'm having some troubles implementing uicontrol::slider properly, as it is based
on a floating-point scale, while slider widgets (in Qt) are usually
using an integer
scale. So I need to do a mapping between the 2. I guess there are a few
math-experts reading this list, so I thought I could get some useful input.
uicontrol::slider scale is defined by:
- min
- max
- M (major step)
- m (minor step)
All numbers are double (Matlab doc says M and m cannot be smaller than 1e-6).
This scale needs to be mapped to an integer scale. The first (wrong) idea that
came to my mind is to map m to 1, such that the scale above becomes:
- 0
- ceil((max-min)/m)
- M/m
- 1
But this would only be valid if M is a multiple of m (M/m is integer), which is
not guaranteed. I could use round(M/m) as an approximation for the major step,
but I'm afraid of significant rounding errors when converting back an
int value to
its floating-point equivalent, when the user actually wants to increase/decrease
the value by the major step value.
I guess I'd some sort of lcm(M,m) to find the right unit value in the
integer scale,
but M and m are floating point values, a lcm doesn't make sense.
Would anybody have any idea how to do this mapping?
Thanks,
Michael.
- Need help for little math problem,
Michael Goffioul <=