Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 绘制QLine后,QLine上的调整点_C++_Qt - Fatal编程技术网

C++ 绘制QLine后,QLine上的调整点

C++ 绘制QLine后,QLine上的调整点,c++,qt,C++,Qt,因此,我正在基于QDial的位置绘制QLine,在场景中绘制QLine之后,我需要定期调整线上点的位置 下面是我如何得到分数的 void addNewPoint( int qdialAngle ){ double oldX = m_sceneCenter; double oldY = m_sceneCenter; double newX = oldX + qCos(qDegreesToRadians(range)) * m_sceneRadius; double

因此,我正在基于QDial的位置绘制QLine,在场景中绘制QLine之后,我需要定期调整线上点的位置

下面是我如何得到分数的

void addNewPoint( int qdialAngle ){
    double oldX = m_sceneCenter;
    double oldY = m_sceneCenter;
    double newX = oldX + qCos(qDegreesToRadians(range)) * m_sceneRadius;
    double newY = oldY + qCos(qDegreesToRadians(range)) * m_sceneRadius;
    QPointF pt(newX, newY);
    m_historyPoint_list.append(pt);
    m_historyPoint_count++;

    switch(m_historyPoint_count){
        case 1:
            m_historyPoint_A = pt;
            break;
        case 2:
            m_historyPoint_B = pt;
            m_historyPoint_count = 0;
            break;
     }
}
这是我如何从这些点画出这条线的

void drawPathLine(){
    m_HistoryLine = QLineF(m_historyPoint_A, m_historyPoint_B);
    QPen linePen(Qt::green, Qt::SolidLine);
    linePen.setWidth(2);

    m_currentLineItem = m_GraphicsScene->addLine(m_HisoryLine, linePen);
    m_line_list.append(m_currentLineItem);
}
这一切都很好,我只是不知道如何调整线上的点后

基本上,我需要画的线随着时间慢慢地被吸引到场景的中心

如果我将QGraphicscene慢慢向上扩展,效果在很大程度上是有效的,至少对原型是有效的,但问题是随着时间的推移,线条变得越来越小。QLine似乎没有设置为ignoretransformations的标志,在本例中,该标志可以正常工作。无论哪种方式,缩放场景都有其他问题,这让我相信这可能不是一个好办法

我试图用指针来表示这些点,但QLineF不接受指针

一旦画好这条线,如何调整

以下是我正在尝试的:

void offsetPoints(){ //called from a timer
    foreach(QGraphicsLineItem* line, m_line_list){
        QLineF adjLine = line->line();
        int adjLine_pt1_x = adjLine.p1.x();
        int adjLine_pt1_y = adjLine.p1.y();
        int adjLine_pt2_x = adjLine.p2.x();
        int adjLine_pt2_y = adjLine.p2.y();

        QPointF newOffsetP1 = QPointF(getNewPoint( getBearing(adjLine_pt1_x, adjLine_pt1_y),
        getRange(adjLine_pt1_x, adjLine_pt1_y));

        QPointF newOffsetP2 = QPointF(getNewPoint( getBearing(adjLine_pt2_x, adjLine_pt2_y),
        getRange(adjLine_pt2_x, adjLine_pt2_y));

        adjLine.setP1(newOffsetP1);
        adjLine.setP2(newOffsetP2);
        line->setline(adjLine);
    }
}

QPointF getNewPoint(double bearing, double range){
    double oldX = 400;
    double oldY = 400;

    double m_offsetSpeed -= 0.1;
    double newX = oldX + qCos(qDegreesToRadians(bearing)) * (range - m_offsetSpeed);         
    double newY = oldY + qSin(qDegreesToRadians(bearing)) * (range - m_offsetSpeed); 

    QPointF newPoint = QPointF(newX, newY);
    return newPoint;
}

double getBearing(int Xpos, int Ypos){
    double lat1 = m_center.x();
    double lon1 = m_center.y();
    double lat2 = Xpos;
    double lon2 = Ypos;

    double X = qSin(lon2 - lon1) * qCos(lat2);
    double Y = qCos(lat1) * qSin(lat2) - qSin(lat1) * qCos(lat2) * qCos(lon2 - lon1);
    double bearing = (qAtan2(Y,X) * (180 / 3.14159265), 360);

    if(bearing < 0)
        bearing += 360;

    return bearing;
}

double getRange(int Xpos, int Ypos){
    double centerX = m_center.x();
    double centerY = m_center.y();

    double newX = centerX - Xpos;
    double newY = centerY - Ypos;

    double distance = qPow(newX, 2) - qPow(newY,2);

    double range = qSqrt( distance);
    return range;
}
void offsetPoints(){//从计时器调用
foreach(QGraphicsLineItem*行,m_行列表){
QLineF adjLine=直线->直线();
int adjLine_pt1_x=adjLine.p1.x();
int adjLine_pt1_y=adjLine.p1.y();
int adjLine_pt2_x=adjLine.p2.x();
int adjLine_pt2_y=adjLine.p2.y();
QPointF newOffsetP1=QPointF(getNewPoint(getBearing)(邻接线pt1\ux,邻接线pt1\uy),
getRange(邻接线1_x,邻接线1_y));
QPointF newOffsetP2=QPointF(getNewPoint(getBearing)(邻接线pt2\ux,邻接线pt2\uy),
getRange(邻接线_pt2_x,邻接线_pt2_y));
adjLine.setP1(新偏移量P1);
adjLine.setP2(newOffsetP2);
行->设置行(调整行);
}
}
QPointF getNewPoint(双轴承,双量程){
双oldX=400;
双倍oldY=400;
双m_偏移速度-=0.1;
双新X=旧X+qCos(Qdegreestorarians(轴承))*(范围-m_偏移速度);
双新Y=旧Y+qSin(Qdegreestorarians(轴承))*(范围-m_偏移速度);
QPointF newPoint=QPointF(newX,newY);
返回newPoint;
}
双getBearing(int Xpos,int YPO){
双板条1=m_中心.x();
双lon1=m_center.y();
双lat2=Xpos;
双lon2=Ypos;
双X=qSin(lon2-lon1)*qCos(lat2);
双Y=qCos(lat1)*qSin(lat2)-qSin(lat1)*qCos(lat2)*qCos(lon2-lon1);
双轴承=(qAtan2(Y,X)*(180/3.14159265),360);
如果(轴承<0)
轴承+=360;
返回轴承;
}
双getRange(int Xpos,int Ypos){
双中心x=m_center.x();
双中心y=m_center.y();
double newX=centerX-Xpos;
双新Y=中心Y-Ypos;
双倍距离=qPow(newX,2)-qPow(newY,2);
双量程=qSqrt(距离);
返回范围;
}
画完线后,这些线肯定在做些什么,但它们的行为非常不稳定。我觉得我很接近,也许我的数学错了

我在“m_History Point_list”中存储用于创建线的点。我的想法是,我应该能够对点执行这些计算,然后线将“简单地”更新,但它们不起作用,因为一旦点在列表中,它们就变成常量点


同样,如果有人知道一种方法,我可以将ItemIgnorestTransformation应用到我的行中,这样当我缩放场景时,行不会收缩,大多数头痛都会消失。

函数addNewPoint是不可复制的,因为有未定义的变量,而且你永远不会使用QdialAngle。我必须从一台计算机传输代码为了在这里得到这个,是的,有一些方法丢失了。qdialAngle直接从QDial上设置的角度传入。每当QDial改变时,它调用addNewPoint以给定角度传入。m_offsetSpeed-=0.1,如注释所示。与m_scene_center一样,我显示了它是如何计算的(查看->大小().width()/2)我向您展示了的值,您可以通过github、dropbox等共享代码。不,我不能。作业限制。然后共享可复制的内容