octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help for little math problem


From: Olaf Till
Subject: Re: Need help for little math problem
Date: Thu, 22 Sep 2011 13:26:36 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

On Thu, Sep 22, 2011 at 10:27:06AM +0100, Michael Goffioul wrote:
> 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.

No help with the math problem, but maybe 2 possibilities to solve this
differently:

1. Round or reject user input for M and m if M deviates too far from a
multiple of m (I guess in most useful cases M should be a multiple of
m anyway),

or

2. Do the mapping only in direction double -> integer, i.e. map the
current value from double to integer (by some rounding as hinted by
you), but preserve both the double and the integer to which it
maps. If a new integer value comes back from the widget (I don't know
how), check if it has changed with respect to the old integer
value. If not, keep the preserved current double value. If yes, change
the preserved current double value by a multiple of M (or up to max or
min).

Was just an idea ...

Olaf


reply via email to

[Prev in Thread] Current Thread [Next in Thread]