Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The Maximum Number of Control Points to Draw a Bezier Curve with QPainterPath
QtWS25 Last Chance

The Maximum Number of Control Points to Draw a Bezier Curve with QPainterPath

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 7.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yaseminyilmaz
    wrote on last edited by
    #1

    Hi all,

    I've drawn the bezier curve by using QPainterPath as following. The initial control point (C0, start point) is set with the function moveTo. The control points C1, C2 and the last control point (C4, end point) are set with the function cubicTo. Is the maximum number of control points is 4 to create bezier curve with QPainterPath? If not, could you please explain how to draw a bezier curve with 6 control points?

    @
    QPainterPath mCurrentPath;
    mCurrentPath.moveTo(5, 5);
    mCurrentPath.cubicTo(40, 10, 50, 50, 199, 199);
    this->addPath(mCurrentPath);
    @

    Thanks a lot for your explanations and helps,

    Yasemin

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      yaseminyilmaz
      wrote on last edited by
      #2

      I want to learn the Qt's limitations related to bezier curves. I suppose QtSDK does not include a function to draw higher-degree (>4) bezier curves, doesn't it?

      Thanks in advance

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KA51O
        wrote on last edited by
        #3

        Have you tried to "compose":https://qt-project.org/doc/qt-4.8/qpainterpath.html#composing-a-qpainterpath different painter paths ? This way you could construct bezier splines with a higher degree.

        For example you could first draw a spline using the first 4 points (A,B,C,D) then draw a second spline using points B,C,D,E and so on. Depending on the combination of points you use to compose the splines you get different results.

        I guess you're familiar with the "theoretics":http://en.wikipedia.org/wiki/Bézier_curve for splines?

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          yaseminyilmaz
          wrote on last edited by
          #4

          Hi KA51O,

          Thanks a lot for your help,

          I've tried to compose the different painter paths for example fifth degree bezier curve (five control points). But the result is the composition of several curves. Whereas I've expected only one curve composing of five control points. I've read the wiki article but I can't figure out how to draw higher degree bezier curves by using QPainterPath.

          Can QPainterPath succeed it? Otherwise should I try external library (Qwt) or write myself? I will be so glad if you can explain.

          @
          QPainterPath mPath;
          mCurrentPath.moveTo(Q_NODE_POINT(0));
          mCurrentPath.cubicTo(Q_NODE_POINT(1), Q_NODE_POINT(2), Q_NODE_POINT(3));
          mPath.moveTo(Q_NODE_POINT(1));
          mPath.cubicTo(Q_NODE_POINT(2), Q_NODE_POINT(3), Q_NODE_POINT(4));
          mCurrentPath.connectPath(mPath);
          this->addPath(mCurrentPath);
          @

          1 Reply Last reply
          0
          • K Offline
            K Offline
            KA51O
            wrote on last edited by
            #5

            The idea of composing the PainterPaths was just a guess, you could also try it with quadratic Bezier curves. If there isn't an easy way to achieve your desired functionality this way, I don't think it would make much sense to write something yourself, as splines are a common thing and there should be solutions for this ready for use. If you know any external library that offers the features you are looking for I'd suggest you use that. I'm only familiar with the theoretics from my time at the university, but I haven't used it in Qt by now. Sorry but I can't offer any more...

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KA51O
              wrote on last edited by
              #6

              I just got another idea how you might be able to make this work using PainterPaths. QPainterPath has a method pointAtPercent(). You could use this to compose the PainterPaths. Paint the first PainterPath till t 0.5 or something then paint the second PainterPath starting at t 0.5. Take a look at how the curves in "this section of the wiki article":http://en.wikipedia.org/wiki/Bézier_curve#Higher-order_curves are drawn this might give you a better idea of what i mean.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved