当前位置: 首页>>代码示例>>C++>>正文


C++ QVector3D::toVector2D方法代码示例

本文整理汇总了C++中QVector3D::toVector2D方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector3D::toVector2D方法的具体用法?C++ QVector3D::toVector2D怎么用?C++ QVector3D::toVector2D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QVector3D的用法示例。


在下文中一共展示了QVector3D::toVector2D方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: drawCircle

void AngleTool::drawCircle()
{
    double *firstPoint = m_mainPolyline->getPoint(0);
    double *circleCentre = m_mainPolyline->getPoint(1);
    double *lastPoint = m_mainPolyline->getPoint(2);

    int xIndex, yIndex, zIndex;
    m_2DViewer->getView().getXYZIndexes(xIndex, yIndex, zIndex);
    QVector3D firstPointProjected(firstPoint[xIndex], firstPoint[yIndex], 0.0);
    QVector3D circleCentreProjected(circleCentre[xIndex], circleCentre[yIndex], 0.0);
    QVector3D lastPointProjected(lastPoint[xIndex], lastPoint[yIndex], 0.0);

    // Calculem l'angle que formen els dos segments
    QVector3D firstSegment = MathTools::directorVector(circleCentreProjected, firstPointProjected);
    QVector3D secondSegment = MathTools::directorVector(circleCentreProjected, lastPointProjected);
    m_currentAngle = MathTools::angleInDegrees(firstSegment, secondSegment);

    // Calculem el radi de l'arc de circumferència que mesurarà un quart del segment més curt dels dos que formen l'angle
    double distance1 = firstSegment.length();
    double distance2 = secondSegment.length();
    double radius = qMin(distance1, distance2) / 4.0;

    // Calculem el rang de les iteracions per pintar l'angle correctament
    double initialAngle = MathTools::angleInRadians(firstSegment.toVector2D());
    if (initialAngle < 0.0)
    {
        initialAngle += 2.0 * MathTools::PiNumber;
    }
    double finalAngle = MathTools::angleInRadians(secondSegment.toVector2D());
    if (finalAngle < 0.0)
    {
        finalAngle += 2.0 * MathTools::PiNumber;
    }
    // Tenim els dos angles al rang [0,2pi)
    // Assegurem que girem en sentit horari -> tindrem angle positiu
    if (finalAngle < initialAngle)
    {
        std::swap(initialAngle, finalAngle);
    }
    double angle = finalAngle - initialAngle;
    // Assegurem que tenim l'angle al rang [0, pi]
    if (angle > MathTools::PiNumber)
    {
        angle = 2.0 * MathTools::PiNumber - angle;
        std::swap(initialAngle, finalAngle);
    }
    int degrees = qRound(angle * MathTools::RadiansToDegreesAsDouble);
    double increment = angle / degrees;

    // Reconstruim l'arc de circumferència
    m_circlePolyline->deleteAllPoints();
    for (int i = 0; i <= degrees; i++)
    {
        angle = initialAngle + i * increment;
        double newPoint[3];
        newPoint[xIndex] = cos(angle) * radius + circleCentre[xIndex];
        newPoint[yIndex] = sin(angle) * radius + circleCentre[yIndex];
        newPoint[zIndex] = 0.0;
        m_circlePolyline->addPoint(newPoint);
    }

    m_circlePolyline->update();
}
开发者ID:chinhtrandn,项目名称:starviewer,代码行数:63,代码来源:angletool.cpp


注:本文中的QVector3D::toVector2D方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。