May 18, 2011

profuma profuma
Lab Rat
26 posts

Pl Explain math in Dial qml example

 

Hi,
In Qt SDK 1.1 (Dial control example) Dial.qml the angle of needle is represented by

angle: Math.min(Math.max(-130, root.value*2.6 – 130), 133)

where did the -130,130,133 value come from? Why is a factor of 2.6 used?

3 replies

May 18, 2011

Franzk Franzk
Lab Rat
830 posts

Aesthetics probably. Angles between -130 and +133 are shown. This whole thing results in root.value being a number between 0 and (133 + 130)/2.6, which is 263/2.6 ~= 100.

So given that information, it is all about scaling a 0-100 value to range that looks nice.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 18, 2011

profuma profuma
Lab Rat
26 posts

Seems to make sense now. The ‘dial control’ code shows the x position has been multiplied by a factor of 100, so to offset that dial code has been scaled down by roughly 100 but the dial has value up 0 to 120 – so they are off by 20 degree ? To offset slider which is 34 px in width, 30 px has been subtracted from slider container width. Why would they complicate the code unnecessarily is beyond me.

May 18, 2011

Franzk Franzk
Lab Rat
830 posts

I do not know the example. I just reasoned backwards from the chunk of code you posted.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

 
  ‹‹ more flashy      Any idea when use OAuth with QML? ››

You must log in to post a reply. Not a member yet? Register here!