本文整理汇总了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();
}