本文整理汇总了C++中BezierCurve::getPointOnCubic方法的典型用法代码示例。如果您正苦于以下问题:C++ BezierCurve::getPointOnCubic方法的具体用法?C++ BezierCurve::getPointOnCubic怎么用?C++ BezierCurve::getPointOnCubic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BezierCurve
的用法示例。
在下文中一共展示了BezierCurve::getPointOnCubic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findDistance
qreal BezierCurve::findDistance(BezierCurve curve, int i, QPointF P, QPointF &nearestPoint, qreal &t) { //finds the distance between a cubic section and a point
//qDebug() << "---- INTER CUBIC SEGMENT";
int nSteps = 24; int k0;
QPointF Q;
Q = curve.getVertex(i-1);
qreal distMin = eLength(Q-P);
nearestPoint = Q;
t = 0;
for(int k=1; k<=nSteps;k++) {
qreal s = (k+0.0)/nSteps;
Q = curve.getPointOnCubic(i, s);
qreal dist = eLength(Q-P);
if(dist <= distMin) {
distMin = dist;
nearestPoint = Q;
t = s;
k0 = k;
}
}
//QPointF Q1 = curve.getPointOnCubic(i, t);
return distMin;
}
示例2: findIntersection
bool BezierCurve::findIntersection(BezierCurve curve1, int i1, BezierCurve curve2, int i2, QList<Intersection>& intersections) //finds the intersection between two cubic sections
{
bool result = false;
//qDebug() << "---- INTER CUBIC CUBIC" << i1 << i2;
QPointF P1, Q1, P2, Q2;
QLineF L1, L2;
QRectF R1;
QRectF R2;
P1 = curve1.getVertex(i1-1);
Q1 = curve1.getVertex(i1);
P2 = curve2.getVertex(i2-1);
Q2 = curve2.getVertex(i2);
L1 = QLineF(P1, Q1);
L2 = QLineF(P2, Q2);
//qDebug() << "-------------------- ";
R1.setTopLeft(P1);
R1.setBottomRight(Q1);
R2.setTopLeft(P2);
R2.setBottomRight(Q2);
QPointF intersectionPoint = QPointF(50.0, 50.0); // bogus point
QPointF* cubicIntersection = &intersectionPoint;
if ( R1.intersects(R2) || L2.intersect(L1, cubicIntersection) == QLineF::BoundedIntersection )
{
//if (L2.intersect(L1, intersection) == QLineF::BoundedIntersection) {
//qDebug() << " FOUND rectangle intersection ";
//if (intersectionPoint != curve1.getVertex(i1-1) && intersectionPoint != curve1.getVertex(i1)) {
// qDebug() << " it's not one of the points ";
// find the cubic intersection
int nSteps = 24;
P1 = curve1.getVertex(i1-1);
for(int i=1; i<=nSteps; i++)
{
qreal s = (i+0.0)/nSteps;
Q1 = curve1.getPointOnCubic(i1, s);
P2 = curve2.getVertex(i2-1);
for(int j=1; j<=nSteps; j++)
{
qreal t = (j+0.0)/nSteps;
Q2 = curve2.getPointOnCubic(i2, t);
L1 = QLineF(P1, Q1);
L2 = QLineF(P2, Q2);
if (L2.intersect(L1, cubicIntersection) == QLineF::BoundedIntersection)
{
QPointF intersectionPoint = *cubicIntersection;
if (intersectionPoint != curve1.getVertex(i1-1) && intersectionPoint != curve1.getVertex(i1))
{
qreal fraction1 = eLength(intersectionPoint-Q1)/(0.0+eLength(Q1-P1));
qreal fraction2 = eLength(intersectionPoint-Q2)/(0.0+eLength(Q2-P2));
qreal t1 = (i - fraction1)/nSteps;
qreal t2 = (j - fraction2)/nSteps;
Intersection intersection;
intersection.point = intersectionPoint;
intersection.t1 = t1;
intersection.t2 = t2;
intersections.append( intersection );
result = true;
//qDebug() << "FOUND cubic interesection " << intersectionPoint << i << j;
}
}
P2 = Q2;
}
P1 = Q1;
}
}
else
{
//return false; // approximation to speed up the calculation
}
//qDebug() << "------";
return result;
}