bugMyPaint - Bugs: bug #21735, Tilt value varies (incorrectly)...

Show feedback again

You are not allowed to post comments on this tracker with your current authentification level.

bug #21735: Tilt value varies (incorrectly) with ascension

Submitted by:  Brien Dieterle <briend>
Submitted on:  Sun Mar 2 05:44:45 2014  
Severity: 3 - NormalPriority: 5 - Normal
Status: FixedPrivacy: Public
Assigned to: NoneOpen/Closed: Closed
Release: 1.1.0+gite443277Planned Release: None
Operating System: Linux

(Jump to the original submission Jump to the original submission)

Mon Jun 23 21:55:24 2014, comment #14:

[This is a canned response, please forgive the broken formatting: it's one of the many things Gna! unfortunately does not do well.]

This bug tracker will shortly be moving to Github. As part of this process, we are reviewing old bug reports on gna.org.

This bug was marked as Fixed long ago, but was still classified as Open. Github does not distinguish between Fixed+Open and Fixed+Closed in the
way we once did here, so this bug is now being marked Closed, and will not be migrated into the github issues tracker.

If you believe that this bug still affects the most recent git master of MyPaint (and thus the next release), please feel free to open a new
issue on Github about it. Our new issue trackers are:


Andrew Chadwick <achadwick>
Project Administrator
Sun May 25 06:51:03 2014, comment #13:

So, we digressed a bit but I think a good summary would be that the kernel folks limit the drivers to 60 degrees of movement, and GTK gives its apps the percentage-of-60 degrees, which requires a slightly different formula to calculate tilt versus the way QT apps derive tilt. As Martin noticed, the problem is amplified as the pen is tilted further from vertical, so most of the time it is not noticable.

So basically in GTK, where xtilt and ytilt are supplied as percentages-of-60 (-1 thru 1):

const float rad = hypot(xtilt, ytilt);
tilt_declination = 90-(rad*60);

Will correctly calcuate the tilt regardless of azimuth/bearing.

Brien Dieterle <briend>
Sat Mar 15 18:52:47 2014, comment #12:

Thanks Martin! Strange that your tilt is inaccurate. When you say "very flat" are you actually tilting the pen to nearly 90 degrees? It won't register any tilt beyond 60 degrees. I also noticed that you have to keep the nib in contact with the pad all the time or else the values will go crazy. If you check out that linuxwacom thread I posted earlier they talk about the conundrum of QT and GTK-- QT isn't doing the tilt calc either, Krita is. GTK maps everything to -1 thru 1 but doesn't actually tell anyone the max tilt is 60 degrees. QT screws up by just assuming 60 degrees is the maximum tilt (although this works out better in reality). The kernel folks seem to be limiting all pens to 60 degrees of tilt for this reason, which seems a shame since there are some tablets that support 90 degrees of tilt. So nothing seems to be ideal. You could almost argue the wacom kernel folks should calculate tilt... or maybe that QT and GTK shouldn't even do any massaging of the input data.

Brien Dieterle <briend>
Sat Mar 15 11:17:38 2014, comment #11:

As a side-note, you could argue now that it should be fixed in GTK instead. Personally I don't think it's GTK's task to do fancy tablet tilt trigonometry... but I wonder now if Qt is doing it...

Martin Renold <martinxyz>
Project Administrator
Sat Mar 15 11:02:26 2014, comment #10:

I've made some before and after tests with the stylus fixed inside a plastic box on my Intuos3 and a brush that paints without pressure.

First thing to notice is that my tilt input is not very precise (with both versions). When I move around without turning, and with tilt mechanically fixed, it already fluctuates quite a bit. When holding the pen very flat, tilt is practically useless for me. Maybe things have improved with Intuos4.

In my brush I mapped declination to color hue (and dab angle to ascension). I attached the brush for reference, and a PNG of my result. I tested at two different angles (the test on the right is much at a much flatter angle). I scribbled by moving the pen-box with the pen pointing n,s,e,w. Ideally, the color hue should be the same for all four directions.

Your change seems to have helped somewhat for flat angles. For steep angles it was not possible for me to identify a problem before or after the patch.

I took the liberty to create and push a commit in your name: https://gitorious.org/mypaint/mypaint/commit/bedbe

(file #20345, file #20346)

Martin Renold <martinxyz>
Project Administrator
Fri Mar 14 18:31:01 2014, comment #9:

attached patch

(file #20328)

Brien Dieterle <briend>
Wed Mar 12 23:26:08 2014, comment #8:

The awesome Keith Scherb helped me figure this one out. It is almost ridiculous how simple the code is now. Please give this a shot. Seems to work great. Here are the changes needed in brushlib/mypaint-brush.c:

tilt_ascension = 180.0*atan2(-xtilt, ytilt)/M_PI;
//float e;
//if (abs(xtilt) > abs(ytilt)) {
//e = sqrt(1+ytilt*ytilt);
//e = abs(ytilt);
//} else {
//e = sqrt(1+xtilt*xtilt);
//e = abs(xtilt);

const float rad = hypot(xtilt, ytilt);
//float cos_alpha = rad/e;
//if (cos_alpha >= 1.0) cos_alpha = 1.0; // fix numerical inaccuracy
//tilt_declination = 180.0*acos(cos_alpha)/M_PI;
tilt_declination = 90-(rad*60);

Brien Dieterle <briend>
Wed Mar 12 09:19:26 2014, comment #7:

It's like when the tablet ratio doesn't match the screen ratio: people get frustrated, they just never figure out why. (Also, there are maybe not many tilt users.)

If you find a solution, I got an intuos3 collecting dust to test with.

Martin Renold <martinxyz>
Project Administrator
Wed Mar 12 05:35:52 2014, comment #6:

More info. It appears this has to do with GTK reporting values as -1 to 1 instead of degrees or radians. Krita on the other hand, being QT, does it differently and uses degrees. So really the -1 to 1 values are sort-of a percentage of 60 degrees. I wonder if we can just convert that number into radians based on the 60 degree assumption, and THEN do the declination calculation and everything would be fixed...?


"GIMP, Inkscape, and MyPaint all treat the values they get from GTK as
the normalized length of the tool's projection along the corresponding
axis (they take the arctangent of the values to get an azimuth). While
GTK doesn't explicitly state that this is what applications receive,
its a reasonable reading of their documentation: "tilt attributes
range from -1.0 to 1.0 ... representing the maximum tilt to the left
or up ... [and] to the right or down". It looks like in practice GTK
actually only scales the tilt values it gets from X based on the
minimum and maximum. Its not what applications expect, but appears to
work well enough that nobody's bothered to file a bug."

Brien Dieterle <briend>
Wed Mar 5 15:21:54 2014, comment #5:

Well changing that to -1 didn't work at all-- just made things worse. So, I decided to try The Gimp and see if this behavior existed there... Gimp 2.8.. downloaded a tilt brush. It acts the same! Finally I try another program-- Krita. Download a tilt brush-- it works fine! The tilt is consistent regardless of ascension. Somehow Krita is getting it right. I checked out the source and I see almost the exact same code as MyPaint

qreal KisPaintInformation::declination(const KisPaintInformation& info, qreal maxTiltX, qreal maxTiltY, bool normalize)
qreal xTilt = qBound(qreal(-1.0), info.xTilt() / maxTiltX , qreal(1.0));
qreal yTilt = qBound(qreal(-1.0), info.yTilt() / maxTiltY , qreal(1.0));

qreal e;
if (fabs(xTilt) > fabs(yTilt)) {
e = sqrt(qreal(1.0) + yTilt*yTilt);
} else {
e = sqrt(qreal(1.0) + xTilt*xTilt);

qreal cosAlpha = sqrt(xTilt*xTilt + yTilt*yTilt)/e;
qreal declination = acos(cosAlpha); // in radians in [0, 0.5 * PI]

// mapping to 0.0..1.0 if normalize is true
return normalize ? (declination / (M_PI * qreal(0.5))) : declination;

I tried adjusting mypaint code to look more like this, and even leave the values in Radians and normalized. I adjusted my brush in Mypaint to use values from 0 to 1 (instead of 0 to 90) and.... it was still weird had more tilt N/S versus E/W.

Back to the drawing board. (no pun intended)

Brien Dieterle <briend>
Tue Mar 4 15:37:06 2014, comment #4:

Coworker suggested this is happening:


instead of this:


I'm going to change the code from 1- to 1+
if (abs(xtilt) > abs(ytilt)) {
e = sqrt(1+ytilt*ytilt);
} else {
e = sqrt(1+xtilt*xtilt);


if (abs(xtilt) > abs(ytilt)) {
e = sqrt(1-ytilt*ytilt);
} else {
e = sqrt(1-xtilt*xtilt);
and see if that helps

Brien Dieterle <briend>
Tue Mar 4 04:08:57 2014, comment #3:

I think this output will clarify and demostrate the bug-- the declination is dramatically lower when south versus east. x and y tilt are essentially reversed so I would expect the numbers to be nearly the same:

Pen tilted towards me (south):

xtilt 0.039370, ytilt 0.984252
ascension -2.290610, declination 10.173764

Pen tilted the same amount towards the right (east)

xtilt 0.984252, ytilt 0.023622
ascension -88.625168, declination 45.438477

Brien Dieterle <briend>
Mon Mar 3 22:07:54 2014, comment #2:

A coworker (who knows math much better than I) worked out a proof that a 55 degree angle as reported against to the X axis will appear to be a ~45 degree angle against the X axis when the bearing is rotated 45 degrees. This matches up with the numbers I was getting from xinput test. So the next thing I will do is uncomment those printf statements in the code and see what numbers mypaint is deriving from the xinput values.

Brien Dieterle <briend>
Sun Mar 2 06:00:30 2014, comment #1:

FWIW there is something else that seems off. If I tilt the pen as much as possible while still registering pressure I can get up to 55 degrees onl the NESW bearings. So, 0,55 0,-55 55,0 -55,0. However at the NE, SE, NW, SW bearings I can only achieve 45,45 -45,-45 45,-45 and -45,45. Obviously the actual pen is at the same angle during all of these measurments.

Brien Dieterle <briend>
Sun Mar 2 05:44:45 2014, original submission:

I created a brush that varies the radius with the declination (tilt). I noticed that as I hold the pen in different orientations the brush responds differently, as if the tilt is being reported as more or less depending on the ascension/bearing.

I verified with the output of xinput that my intous5 pro was reporting tilt values from -63,-63 (NorthWest) to 63,63 (SouthEast). Although at those extreme angles the nib was not able to make contact with the pad so in practice values of only up to 55 are possible.

Attached is a sample. You can see a pattern where the North and South directions are the biggest (indicating the biggest tilt value). East and West are both small, and other other four directions are all the same and they happen to be on the 45 degree marks. I've looked at the src code but I'm afraid I'm not great at math and trig. Doh!

I can't imagine why no one has noticed this except that maybe everyone just holds their pen at one orientation?

Brien Dieterle <briend>


Attached Files
file #20346:  tilttest.myb added by martinxyz (8kB - application/octet-stream)
file #20345:  tilt_test.png added by martinxyz (475kB - image/png)
file #20328:  brushlib.patch added by briend (812B - text/x-patch)
file #20230:  weirdbrushtilt.jpg added by briend (134kB - image/jpeg)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by achadwick (Posted a comment)
  • -unavailable- added by martinxyz (Posted a comment)
  • -unavailable- added by martinxyz
  • -unavailable- added by briend (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Error: not logged in



    Follow 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon Jun 23 21:55:24 2014achadwickOpen/ClosedOpen=>Closed
    Sat Mar 15 11:02:26 2014martinxyzAttached File-=>Added tilttest.myb, #20346
    Sat Mar 15 11:02:25 2014martinxyzAttached File-=>Added tilt_test.png, #20345
    Fri Mar 14 18:31:01 2014briendAttached File-=>Added brushlib.patch, #20328
    Wed Mar 12 09:19:26 2014martinxyzStatusNone=>Confirmed
      Carbon-Copy-=>Added portnov
    Sun Mar 2 05:44:45 2014briendAttached File-=>Added weirdbrushtilt.jpg, #20230
    Show feedback again

    Back to the top

    Powered by Savane 3.1-cleanup