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. How to get y Position from a cubic bezeir curve
Forum Updated to NodeBB v4.3 + New Features

How to get y Position from a cubic bezeir curve

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 239 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    summit
    wrote on last edited by Chris Kawa
    #1

    I am drawing a bezeir curve in QT using Painter.

    painter.setPen(Qt::blue);
            QPainterPath path;
            glm::vec2 startPoint(0, (1.0 - opacityCurve[0].opacity) * height()); // Invert y-coordinate
            path.moveTo(startPoint.x, startPoint.y);
    
            for (size_t i = 1; i < opacityCurve.size(); ++i) {
                int x1 = static_cast<int>(opacityCurve[i - 1].position.x * width());
                int x2 = static_cast<int>(opacityCurve[i].position.x * width());
                int y1 = static_cast<int>((1.0 - opacityCurve[i - 1].position.y) * height()); // Invert y-coordinate
                int y2 = static_cast<int>((1.0 - opacityCurve[i].position.y) * height());     // Invert y-coordinate
                int cx1 = static_cast<int>(opacityCurve[i - 1].handle2.x * width());
                int cy1 = static_cast<int>((1.0 - opacityCurve[i - 1].handle2.y) * height()); // Invert y-coordinate
                int cx2 = static_cast<int>(opacityCurve[i].handle1.x * width());
                int cy2 = static_cast<int>((1.0 - opacityCurve[i].handle1.y) * height()); // Invert y-coordinate
    
                QPointF startPointF(startPoint.x, startPoint.y);
                QPointF controlPoint1F(cx1, cy1);
                QPointF controlPoint2F(cx2, cy2);
                QPointF endPointF(x2, y2);
                path.cubicTo(controlPoint1F, controlPoint2F, endPointF);
    
                // Draw control points
                painter.setPen(Qt::black);
                painter.setBrush(Qt::green);  // Use a different color for control points
                painter.drawEllipse(controlPoint1F, 5, 5);
                painter.drawEllipse(controlPoint2F, 5, 5);
    
                // Draw lines connecting control points to curve points
                painter.setPen(Qt::darkGray);  // Choose a color for the connecting lines
                painter.drawLine(startPointF, controlPoint1F);
                painter.drawLine(endPointF, controlPoint2F);
    
                // Update startPoint for the next iteration
                startPoint = glm::vec2(x2, y2);
            }
    
            // Set the alpha value to 128 for semi-transparency (adjust as needed)
            QColor fillColor(0, 0, 255, 64); // Blue color with alpha = 128
            painter.setBrush(fillColor);
            painter.drawPath(path);
    

    Now if i want to know the Y position of the curve at given time 0.5 how can i do that ?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      See QPainterPath::pointAtPercent().

      S 1 Reply Last reply
      3
      • Chris KawaC Chris Kawa

        See QPainterPath::pointAtPercent().

        S Offline
        S Offline
        summit
        wrote on last edited by
        #3

        @Chris-Kawa Thank you very much , this is what i needed.

        1 Reply Last reply
        0
        • S summit has marked this topic as solved on

        • Login

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