pPainter -> setPen(pen());
// If there are two particles to attach to then draw a the vector and attach to them
if (m_pStartParticle && m_pEndParticle) {
if (m_pStartParticle -> collidesWithItem(m_pEndParticle))
return;
QLineF centerLine
(m_pStartParticle
-> pos
(), m_pEndParticle
-> pos
());
QPolygonF endPolygon
= m_pEndParticle
-> polygon
();
QPointF p1
= endPolygon.
first() + m_pEndParticle
-> pos
();
for (int i = 1; i < endPolygon.count(); ++i) {
p2 = endPolygon.at(i) + m_pEndParticle -> pos();
QLineF::IntersectType intersectType
= polyLine.
intersect(centerLine,
&intersectPoint
);
if (intersectType
== QLineF::BoundedIntersection) break;
p1 = p2;
}
setLine
(QLineF(intersectPoint, m_pStartParticle
-> pos
()));
}
// else if there is a starting particle and no ending particle then handle
else if (m_pStartParticle && !m_pEndParticle) {
}
// likewise if there is no starting particle but an ending particle, handle
else if (!m_pStartParticle && m_pEndParticle) {
}
// The default case of NO particles, is just a vector. We do nothing and just drop into the vector draw
else {
}
// Draw the vector
double drawAngle, realAngle, Theta;
realAngle = ::acos(aLine.dx() / aLine.length());
if (m_Theta.axisOrientation == AXIS_HORIZ) {
QPointF currCoordP1
(aLine.
p1().
x(), aLine.
p1().
y());
Theta = (::atan(aLine.dy() / aLine.dx()) * (180 / PhysConsts::PI));
qDebug("Line (x, y): (%f, %f)", currCoordP1.x(), currCoordP1.y());
// If we're in the Quad I (+x, +y) or Quad II (-x, +y)
if ((currCoordP1.x() >= 0 && currCoordP1.y() >= 0) || (currCoordP1.x() < 0 && currCoordP1.y() >= 0)) {
if (Theta < 0)
Theta = -Theta;
}
// Quad III (-x, -y) or Quad IV (+x, -y)
else if ((currCoordP1.x() < 0 && currCoordP1.y() < 0) || (currCoordP1.x() >= 0 && currCoordP1.y() < 0)) {
if (Theta > 0)
Theta = -Theta;
}
}
m_Theta.degrees = Theta;
drawAngle = (aLine.dy() >= 0) ? (PhysConsts::PI * 2) - realAngle : (PhysConsts::PI * 2) + realAngle;
arrowP1
= aLine.
p1() + QPointF(sin(drawAngle
+ PhysConsts
::PI / 3) * m_arrowSize,
cos(drawAngle
+ PhysConsts
::PI / 3) * m_arrowSize
);
arrowP2
= aLine.
p1() + QPointF(sin(drawAngle
+ PhysConsts
::PI - PhysConsts
::PI / 3) * m_arrowSize,
cos(drawAngle
+ PhysConsts
::PI - PhysConsts
::PI / 3) * m_arrowSize
);
m_arrowHead.clear();
m_arrowHead << line().p1() << arrowP1 << arrowP2;
pPainter -> drawLine(aLine);
pPainter -> drawPolygon(m_arrowHead);
m_pLabel -> setPlainText(formattedLabel.sprintf("%s: (%.6f, @=%3.2f)", m_rawLabel.toStdString().c_str(), m_magnitude, Theta));
tmpPath.addPolygon(m_arrowHead);
pPainter -> fillPath(tmpPath, brush);
}