How to get y Position from a cubic bezeir curve
Solved
General and Desktop
-
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 ?
-
-
@Chris-Kawa Thank you very much , this is what i needed.
-