How to Get Vertical Line from Point and Line

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How to Get Vertical Line from Point and Line相关的知识,希望对你有一定的参考价值。

Description

How to get vertical line cross one point which out of line in line.

QPoint Line::VerticalPoint(QPoint pt)
{
    QPointF ptCross = pt;
    double dtY = static_cast<double>(y1() - y2());
    double dtX = static_cast<double>(x1() - x2());
    double k,b,m;
    /**  0 = kx +b -y;  对应垂线方程为 -x -ky + m = 0;(mm为系数) */
    if(abs(dtX - 0) < 1e-10){
        ptCross = QPointF(x1(),pt.y());
        goto _END;
    }

    if(abs(dtY - 0) < 1e-10){
        ptCross = QPointF(pt.x(),y1());
        goto _END;
    }

    k = dtY/dtX;
    b = (y1()-k*x1());
    m = pt.x() + k*pt.y();

    ptCross.setX((m-k*b)/(k*k + 1));
    ptCross.setY(k*ptCross.x()+b);

_END:
    return ptCross.toPoint();
}

以上是关于How to Get Vertical Line from Point and Line的主要内容,如果未能解决你的问题,请参考以下文章

How to determine which grid cells a line segment passes through?

sh how-to-deal-command-line-parameters.sh

How-To: Create ISO Images from Command-Line

How to resolve emulator cannot be launched issue by command line

xml 画一条线。字体:https://stackoverflow.com/questions/3616676/how-to-draw-a-line-in-android

xml 编辑文本更改线条颜色。字体:https://stackoverflow.com/questions/24677414/how-to-change-line-color-in-edittext。