已知A点到任意多边形距离最小,求该多边形最小距离点的坐标。

我提供一种思路
1。先变量多边形顶点,找到最近的哪个顶点
2.判断A点到该顶点的距离,A点到该顶点旁边两条边的距离
遍历这三个距离,找出最小距离,即是答案

#ifndef ALGORITHM_H
#define ALGORITHM_H

#include <QWidget>



class ALgorithmLibrary:public QWidget
{
   
   
 Q_OBJECT

public:
    ALgorithmLibrary() {
   
   }
    ~ALgorithmLibrary(){
   
   };

  virtual  QPointF uniqueInterface(QPointF p1,QVector<QPointF>multipolyons)=0;


};


class ALgorithm : public ALgorithmLibrary,public QWidget
{
   
   
    Q_OBJECT

public:
    ALgorithm(QWidget *parent = nullptr);
    ~ALgorithm();


   QPointF uniqueInterface(QPointF p1,QVector<QPointF>multipolyons);

private:
    double caculateLength(QPointF p1,QPointF p2);

    QMap<double,QPointF> caculateMinDistanceMultiPolyonPoint(QPointF p1,QVector<QPointF>multipolyons);

    int caculateIndexOfValue(QPointF p1,QVector<QPointF>multipolyons);

    QMap<QString,QPointF>twoPointInleftAndRightofCurrentPointByIndex(int i,QVector<QPointF>arry);

    QPointF findPerpendicularIntersection(QPointF p1,QPointF PL1,QPointF PL2);

    QPointF judgeMinDistance(QPointF p1,QMap<QString,QPointF>left_right);
    bool IsInInterval(QPointF p,QPointF A,QPointF B);


    bool arePointsEqual(const QPointF& p1, const QPointF& p2);
    // 比较两个 QPointF 对象是否相等的函数



};
#endif // ALGORITHM_H

#include "algorithm.h"

#include <QVector>
#include <algorithm>  // 包含std::min_element
#include <iostream>

#include<cmath>
#include<QDebug>


bool ALgorithm::arePointsEqual(const QPointF& p1, const QPointF& p2)
{
   
   
    const double epsilon = 1e-10; // 允许的误差范围
    return (qAbs(p1.x() - p2.x()) < epsilon && qAbs(p1.y() - p2.y()) < epsilon);
}

ALgorithm::ALgorithm(QWidget *parent)
    : QWidget(parent)

{
   
   




}

ALgorithm::~ALgorithm()
{
   
   

}

QPointF ALgorithm::uniqueInterface(QPointF p1, QVector<QPointF> v)
{
   
   


  auto it=caculateMinDistanceMultiPolyonPoint(p1,v);

  auto i= caculateIndexOfValue(it.value( it.keys().first()),v);
    if(i==-1)
    {
   
   
        return QPointF(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值