Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

qreal QPainterPath::angleAtPercent ( qreal  t  )  const

Returns the angle perpendicular to the slope of the path at the percentage t. The angle is constructed with the reference frame of the horizontal (x) axis and the left side of the path (left as defined by the direction of the path). The argument t has to be between 0 and 1.

Note that similarly to the other percent methods, the percentage measurment is not linear with regards to the length if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 2753 of file qpainterpath.cpp.

References length().

{
    if (t < 0 || t > 1) {
        qWarning("QPainterPath::angleAtPercent accepts only values between 0 and 1");
        return 0;
    }

    qreal totalLength = length();
    qreal curLen = 0;
    qreal bezierLen = 0;
    QBezier bez = bezierAtT(*this, t, &curLen, &bezierLen);
    qreal realT = (totalLength * t - curLen) / bezierLen;

    qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4);
    qreal m2 = slopeAt(realT, bez.y1, bez.y2, bez.y3, bez.y4);
    //tangent line
    qreal slope = 0;

#define SIGN(x) ((x < 0)?-1:1)
    qreal angle = 0;
    if (m1) {
        slope = m2/m1;
        angle = (atan((-slope)/(1.0))*180./Q_PI);
    } else {
        if (m2 > 0) {
            angle = -90;
        } else {
            angle = 90;
        }
    }

    //adjust the angle so that it's in the direction
    //in which the path is going
    if (m1 >= 0 && m2 >= 0) {
        //Quadrant 1
        angle *= -1;
    } else if (m1 <  0 && m2 >= 0) {
        //Quadrant 2
        angle = 180 - angle;
    } else if (m1 <  0 && m2 < 0) {
        //Quadrant 3
        angle = -180-angle;
    } else if (m1 >= 0 && m2 < 0) {
        //Quadrant 4
        angle *= -1;
    }

    return angle;
}


Generated by  Doxygen 1.6.0   Back to index