本文整理汇总了C++中QVector2D::length方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector2D::length方法的具体用法?C++ QVector2D::length怎么用?C++ QVector2D::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector2D
的用法示例。
在下文中一共展示了QVector2D::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getLimitPos
QPointF ImageMarker::getLimitPos(QPointF newPos)
{
qreal loLen;
qreal hiLen;
if (!m_limit) {
return QPointF();
}
QVector2D ownVector = QVector2D(newPos);
QVector2D limVector = QVector2D(m_limit->pos());
if (m_outerLimit) {
loLen = ownVector.length();
hiLen = limVector.length();
}
else {
loLen = limVector.length();
hiLen = ownVector.length();
}
if (loLen <= hiLen) {
return QPointF();
}
return (ownVector.normalized() * (m_outerLimit ? hiLen : loLen)).toPointF();
}
示例2: mouseMoveEvent
void LiftDragPlot::mouseMoveEvent(
QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
{
QPoint pos = event->pos();
QVector2D diff = QVector2D(pos - mBeginPos);
if (diff.length() > selectionTolerance())
{
mDragging = true;
}
if (mDragging)
{
const double cd = xAxis->pixelToCoord(pos.x());
const double cl = yAxis->pixelToCoord(pos.y());
const double c = cd / 2;
const double a = c / cl / cl;
mMainWindow->setMinDrag(c);
mMainWindow->setMaxLD(1 / sqrt(4 * a * c));
}
}
else if (QCPCurve *graph = qobject_cast<QCPCurve *>(plottable(0)))
{
const QCPCurveDataMap *data = graph->data();
double resultTime;
double resultDistance = std::numeric_limits<double>::max();
for (QCPCurveDataMap::const_iterator it = data->constBegin();
it != data->constEnd();
++it)
{
QVector2D pt = QVector2D(xAxis->coordToPixel(it.value().key),
yAxis->coordToPixel(it.value().value));
double dist = pt.distanceToPoint(QVector2D(event->pos()));
if (dist < resultDistance)
{
resultTime = it.value().t;
resultDistance = dist;
}
}
if (resultDistance < selectionTolerance())
{
setMark(resultTime);
}
else
{
mMainWindow->clearMark();
QToolTip::hideText();
}
}
}
示例3:
bool B9SupportStructure::IsVertical()
{
QVector2D disp = QVector2D(topPivot) - QVector2D(bottomPivot);
if(disp.length() < 0.1)
return true;
return false;
}
示例4: F
double Torus::F(const QVector3D &pp)
{
QVector3D p = pp - position;
QVector2D p2 = QVector2D(p.x(), p.z());
QVector2D q = QVector2D(p2.length() - t.x(), p.y());
return q.length() - t.y();
}
示例5:
/**
* Computes the intersection between two line segments on the XY plane
* Segments must intersect within their extents for the intersection to be valid
* z coordinate is ignored
**/
bool Polygon3D::segmentSegmentIntersectXY(QVector2D &a, QVector2D &b, QVector2D &c, QVector2D &d,
float *tab, float *tcd, bool segmentOnly, QVector2D &intPoint)
{
QVector2D u = b - a;
QVector2D v = d - c;
if( u.lengthSquared() < MTC_FLOAT_TOL || v.lengthSquared() < MTC_FLOAT_TOL )
{
return false;
}
float numer = v.x()*(c.y()-a.y()) + v.y()*(a.x()-c.x());
float denom = u.y()*v.x() - u.x()*v.y();
if (denom == 0.0f) {
// they are parallel
*tab = 0.0f;
*tcd = 0.0f;
return false;
}
float t0 = numer / denom;
QVector2D ipt = a + t0*u;
QVector2D tmp = ipt - c;
float t1;
if (QVector2D::dotProduct(tmp, v) > 0.0f){
t1 = tmp.length() / v.length();
}
else {
t1 = -1.0f * tmp.length() / v.length();
}
//Check if intersection is within segments
if( !( (t0 >= MTC_FLOAT_TOL) && (t0 <= 1.0f-MTC_FLOAT_TOL) && (t1 >= MTC_FLOAT_TOL) && (t1 <= 1.0f-MTC_FLOAT_TOL) ) ){
return false;
}
*tab = t0;
*tcd = t1;
QVector2D dirVec = b-a;
intPoint = a+(*tab)*dirVec;
return true;
}
示例6: calculate_coordinates
void CFruchtermanReingold::calculate_coordinates() {
CalculateForces();
for(int i = 0; i < vgc_nodes_num; ++i) {
if(!vgc_graph->vertice_exists(i)) continue;
QVector2D delta = vgc_vertices[i].v_force * NODE_MASS * TIME_DELTA * TIME_DELTA;
vgc_vertices[i].v_coordinates += delta.toPoint() * std::min(delta.length(), (double)vgc_temperature) / delta.length();
}
Cool();
}
示例7: projection_on_curve
float Window::projection_on_curve(const QVector2D& projected) {
//This is the distance where the curves changed in terms of the window size
const float radius = 0.8f;
float z = 0.0f;
if (projected.lengthSquared() <= (0.5f * radius * radius)) {
//Inside the sphere
z = sqrt(radius * radius - projected.lengthSquared());
}
else {
//Outside of the sphere using hyperbolic sheet
z = (0.5f * radius * radius) / projected.length();
}
return z;
}
示例8: obstacleForce
QVector2D Boids::obstacleForce(std::vector<Boids*> obstacles) const
{
QVector2D dist;
QVector2D meanPos;
QVector2D force;
if(obstacles.size() == 0) return QVector2D(0,0);
for(unsigned int i(0);i<obstacles.size();i++)
{
dist = this->getPos() - obstacles[i]->getPos();
//differentiating big or small obstacle
if(obstacles[i]->isItAnObstacle() == SMALL)
{
if(dist.length() < OBST_SMALL_RAD + OBST_DIST)
meanPos += dist;
}
else
{
if(dist.length() < OBST_BIG_RAD + OBST_DIST)
meanPos += dist;
}
}
//multiplying by obstacle force coeffcient
meanPos = meanPos*OBSTACLE_FORCE;
//Make the force tengent to the obstacle
force = QVector2D(meanPos.y(),-meanPos.x());
return force;
}
示例9: mouseReleaseEvent
void GLWidget::mouseReleaseEvent(QMouseEvent *e) {
// Mouse release position - mouse press position
QVector2D diff = QVector2D(e->pos()) - mousePressPosition;
// Rotation axis is perpendicular to the mouse position difference
// vector
QVector3D n = QVector3D(diff.y(), diff.x(), 0.0).normalized();
// Accelerate angular speed relative to the length of the mouse sweep
qreal acc = diff.length() / 100.0;
// Calculate new rotation axis as weighted sum
rotationAxis = (rotationAxis * angularSpeed + n * acc).normalized();
// Increase angular speed
angularSpeed += acc;
}
示例10: mouseReleaseEvent
void JaguarView::mouseReleaseEvent(QMouseEvent *event)
{
QPoint pos;
QVector2D v;
switch(m_mode) {
case MODE_RULER:
pos = ((QPointF) mapToScene(event->pos())).toPoint();
m_scaleLineItem->setLine(ptMouseDown.x(), ptMouseDown.y(), pos.x(), pos.y());
v = QVector2D(pos - ptMouseDown);
scene()->removeItem(m_scaleLineItem);
emit rulerDone(v.length());
break;
default:
break;
}
return QGraphicsView::mouseReleaseEvent(event);
}
示例11: mouseReleaseEvent
void OpenGLWidget::mouseReleaseEvent(QMouseEvent *e)
{
QApplication::restoreOverrideCursor();
if (e->button() == Qt::RightButton)
{
// Mouse release position - mouse press position
QVector2D diff = QVector2D(e->localPos()) - m_lastMousePosition;
// Rotation axis is perpendicular to the mouse position difference vector
QVector3D n = QVector3D(diff.y(), diff.x(), 0.0).normalized();
// Accelerate angular speed relative to the length of the mouse sweep
qreal acc = diff.length() / 100.0;
// Calculate new rotation axis as weighted sum
m_rotationAxis = (m_rotationAxis * m_angularSpeed + n * acc).normalized();
// Increase angular speed
m_angularSpeed += acc;
}
e->accept();
}
示例12: mouseMoveEvent
void MeshViewer::mouseMoveEvent(QMouseEvent *e)
{
switch (interactionState) {
case Camera: {
if (e->buttons() & Qt::LeftButton) {
QVector2D diff = QVector2D(e->pos()) - mouseState.prev_pos;
if ((e->modifiers() & Qt::ShiftModifier)) { //press "shift" key
viewerState.translation += QVector3D(diff.x() / 100.0, -diff.y() / 100.0, 0.0);
}
else if (e->modifiers() & Qt::ControlModifier) //press "crl" key
{
viewerState.translation += QVector3D(0.0, 0.0, diff.x() / 100.0 - diff.y() / 100.0);
}
else{
// Rotation axis is perpendicular to the mouse position difference
// vector
QVector3D n = QVector3D(diff.y(), diff.x(), 0.0).normalized();
// Accelerate angular speed relative to the length of the mouse sweep
qreal acc = diff.length() / 4.0;
// Calculate new rotation axis as weighted sum
viewerState.rotationAxis = (viewerState.rotationAxis * viewerState.angularChange + n * acc).normalized();
// Change rotation angle
viewerState.angularChange = acc;
viewerState.rotation = QQuaternion::fromAxisAndAngle(viewerState.rotationAxis, viewerState.angularChange) * viewerState.rotation;
}
viewerState.updateModelView();
mouseState.prev_pos = QVector2D(e->pos());
}
updateGL();
break;
}
case Camera_Translation:
if (e->buttons() & Qt::LeftButton) {
QVector2D diff = QVector2D(e->pos()) - mouseState.prev_pos;
viewerState.translation += QVector3D(diff.x() / 100.0, -diff.y() / 100.0, 0.0);
viewerState.updateModelView();
mouseState.prev_pos = QVector2D(e->pos());
}
updateGL();
break;
case Camera_Zoom:
if (e->buttons() & Qt::LeftButton) {
QVector2D diff = QVector2D(e->pos()) - mouseState.prev_pos;
viewerState.translation += QVector3D(0.0, 0.0, diff.x() / 100.0 - diff.y() / 100.0);
viewerState.updateModelView();
mouseState.prev_pos = QVector2D(e->pos());
}
updateGL();
break;
//selection box
case SelectFace:
case SelectEdge:
case SelectVertex: {
if (mouseState.isPressed) {
isSelecting = true;
sbox.corner_win[2] = e->x();
sbox.corner_win[3] = viewerState.viewport.h - e->y();
/*
cout<<"e->x(win[2])"<<endl<<e->x()<<endl;
cout<<"e->y(win[3])"<<endl<<e->y()<<endl;
viewerState.print();
*/
computeGlobalSelectionBox();
}
else {
isSelecting = false;
mouseState.isPressed = false;//later added
}
// cout<<"moving mousestate"<<mouseState.isPressed<<endl;
updateGL();
break;
}
}
}
示例13: line
/**
* オリジナルの座標系での頂点座標v1とv2を通る直線を、縮尺された座標系のhtSpace上に描画する。
*/
void HoughTransform::line(const QVector2D& p1, const QVector2D& p2, float sigma) {
QVector2D v1 = (p1 - bbox.minPt) * scale;
QVector2D v2 = (p2 - bbox.minPt) * scale;
QVector2D vl, vr;
if (v1.x() < v2.x()) {
vl = v1;
vr = v2;
} else {
vl = v2;
vr = v1;
}
QVector2D vu, vd;
if (v1.y() < v2.y()) {
vd = v1;
vu = v2;
} else {
vd = v2;
vu = v1;
}
QVector2D dir = v2 - v1;
float len = dir.length();
sigma *= scale;
float sigma2 = SQR(sigma);
if (fabs(dir.x()) > fabs(dir.y())) {
for (int x = 0; x < htSpace.cols; x++) {
int y = dir.y() * ((float)x - v1.x()) / dir.x() + v1.y() + 0.5f;
if (y < 0 || y >= htSpace.rows) continue;
float h = 0;
if (x >= vl.x() && x <= vr.x()) {
h = len;
} else if (x < vl.x()) {
h = len * expf(-(SQR(x - vl.x()) + SQR(y - vl.y())) * 0.5f / sigma2);
} else {
h = len * expf(-(SQR(x - vr.x()) + SQR(y - vr.y())) * 0.5f / sigma2);
}
htSpace.at<float>(y, x) += h;
}
} else {
for (int y = 0; y < htSpace.rows; y++) {
int x = dir.x() * ((float)y - v1.y()) / dir.y() + v1.x() + 0.5f;
if (x < 0 || x >= htSpace.cols) continue;
float h = 0;
if (y >= vd.y() && y <= vu.y()) {
h = len;
} else if (y < vd.y()) {
h = len * expf(-(SQR(x - vd.x()) + SQR(y - vd.y())) * 0.5f / sigma2);
} else {
h = len * expf(-(SQR(x - vu.x()) + SQR(y - vu.y())) * 0.5f / sigma2);
}
htSpace.at<float>(y, x) += h;
}
}
}
示例14:
/**
* カーテシアン座標系から、極座標系へ変換する。
*/
void Util::cartesian2polar(const QVector2D &pt, float &radius, float &theta) {
radius = pt.length();
theta = atan2f(pt.y(), pt.x());
}
示例15: advance
//.........这里部分代码省略.........
qreal tFriction = t->getTableFriction();
FrictionMovement(tFriction);
}
//If we didn't collide with a ball, see if we collided with a block. Collisions must be handled differently since blocks are fixed objects, and balls can move.
if (block)
{
chomp->play(":/sounds/spring.wav");
//if we're colliding vertically, switch the ball's y component
if( (x + radius > block->getXPos() && x + radius < block->getXPos() + block->getWidth()) && (y < block->getYPos() || y > block->getYPos() + block->getHeight()) )
yComponent = -yComponent;
else
//otherwise we're colliding horizontally, and reverse the y component
xComponent = -xComponent;
}
else if(bHole) // if approaching black hole
{
// if the ball has rotated for quite a while, just delete the ball.
if(this->angle >= M_PI)
{
delete this;
return;
}
if(playBlackHoleSound)
{
chomp->play(":/sounds/whip.wav");
this->playBlackHoleSound = false;
}
qreal r = bHole->getRadius();
qreal b_x = bHole->getXPos(),
b_y = bHole->getYPos();
// The ball moves in circular motion
setPos(b_x + cos(this->angle) * r,
b_y + sin(this->angle) * r);
this->angle += bHole->returnPower();
return;
}
else if(other) //otherwise, we're colliding with a ball
{
chomp->play(":/sounds/clang.wav");
qreal otherX = other->pos().x();
qreal otherY = other->pos().y();
//Make vectors representing our velocity and the item's velocity
QVector2D othervec = QVector2D(otherX, otherY);
QVector2D collision = ballvec - othervec;
QVector2D othervelocity = QVector2D(other->getXVel(), other->getYVel());
qreal distance = collision.length();
//if the ball is inside another object due to going too fast..
if (distance <= this->getRadius())
{
qDebug()<< "inside another object!" << other;
collision = QVector2D(1,0); // make sure not to divide by 0
distance = 1 ; //hack to make sure ball doesn't get stuck inside things
}
//calculate the components of the velocity vectors paralell to the collision
collision = collision / distance; // normalise the collision vector
qreal ballCollisionVelocityInitial = QVector2D::dotProduct(ballvelocity, collision);
qreal otherCollisionVelocityInitial = QVector2D::dotProduct(othervelocity, collision);
//assume the objects collide elastically, so the new velocities are given by...
qreal ballCollisionVelocityFinal = otherCollisionVelocityInitial;
qreal otherCollisionVelocityFinal = ballCollisionVelocityInitial;
QVector2D newVelVec = collision *(ballCollisionVelocityFinal - ballCollisionVelocityInitial);
this->setXVel(this->getXVel() + newVelVec.x());
this->setYVel(this->getYVel() + newVelVec.y());
QVector2D newOtherVelVec = collision * (otherCollisionVelocityFinal - otherCollisionVelocityInitial);
other->setXVel(other->getXVel() + newOtherVelVec.x());
other->setYVel(other->getYVel() + newOtherVelVec.y());
}
}
}
}
setPos(this->pos().x() + this->getXVel(), this->pos().y()+ this->getYVel());
//friction slow down
qreal tFriction = t->getTableFriction();
FrictionMovement(tFriction);
//get the current speed of the ball
qreal speed = qSqrt(qPow(xComponent,2)+qPow(yComponent,2));
if(speed<0.1)
{
xComponent = 0;
yComponent = 0;
}
}