当前位置: 首页 > news >正文

北京网站建设认百度做网站

北京网站建设认,百度做网站,简单软件开发工具,做网站的cnfg✨博客主页何曾参静谧的博客📌文章专栏「QT」QT5程序设计📚全部专栏「VS」Visual Studio「C/C」C/C程序设计「UG/NX」BlockUI集合「Win」Windows程序设计「DSA」数据结构与算法「UG/NX」NX二次开发「QT」QT5程序设计「File」数据文件格式「PK」Parasolid…

在这里插入图片描述

✨博客主页
何曾参静谧的博客
📌文章专栏
「QT」QT5程序设计
📚全部专栏
「VS」Visual Studio「C/C++」C/C++程序设计「UG/NX」BlockUI集合
「Win」Windows程序设计「DSA」数据结构与算法「UG/NX」NX二次开发
「QT」QT5程序设计「File」数据文件格式「PK」Parasolid函数说明
「Math」探秘数学世界

目录

    • QLineF类详解
      • 一、引言
      • 二、使用范围
      • 三、类的头文件
      • 四、类的构造介绍
      • 五、共有函数介绍
      • 六、Static函数介绍
      • 七、运算符重载
      • 八、详细代码举例

QLineF类详解

一、引言

QLineF是Qt框架中的一个关键类,用于表示二维平面上的直线段,与QLine类不同的是,QLineF使用浮点数(通常是double类型)来表示坐标,这使得它能够处理更高精度的图形操作。QLineF类提供了丰富的功能,包括计算直线长度、直线段的平移、判断点与直线的关系等,是Qt图形编程中不可或缺的工具之一。

二、使用范围

QLineF类广泛应用于需要高精度图形操作的Qt应用程序中。例如,在绘制复杂图形、进行图形变换、进行碰撞检测等场景中,QLineF的浮点数坐标能够提供更精确的结果。此外,QLineF还可以与Qt的其他图形类(如QPolygonF、QRectF等)无缝集成,共同构建出丰富的图形界面。

三、类的头文件

要使用QLineF类,需要在代码中包含其头文件<QLineF>。这个头文件定义了QLineF类的所有成员和函数,使得开发者可以在自己的Qt应用程序中方便地使用该类。

#include <QLineF>

四、类的构造介绍

QLineF类提供了多种构造函数,允许以不同的方式创建QLineF对象:

  1. 默认构造函数:创建一个未初始化的QLineF对象。
QLineF();
  1. 参数化构造函数:使用两个QPointF对象或四个浮点数坐标(x1, y1, x2, y2)作为起点和终点来创建QLineF对象。
QLineF(qreal x1, qreal y1, qreal x2, qreal y2);
QLineF(const QPointF &p1, const QPointF &p2);
  1. 从QLine转换的构造函数:虽然QLine使用整数坐标,但QLineF类提供了从QLine到QLineF的转换构造函数,允许将QLine对象转换为QLineF对象(可能会进行精度提升)。
QLineF(const QLine &line);

五、共有函数介绍

QLineF类提供了丰富的共有函数,用于获取直线的属性、进行几何运算等。以下是一些常用的共有函数:

  • QPointF p1() const:返回直线的起点。
  • QPointF p2() const:返回直线的终点。
  • void setP1(const QPointF &p1):设置直线的起点。
  • void setP2(const QPointF &p2):设置直线的终点。
  • qreal length() const:返回直线的长度(浮点数)。
  • qreal angle() const:返回直线的倾斜角(以度为单位,范围从-180到180)。
  • qreal angleTo(const QLineF &l) const:返回本直线与另一条直线l之间的夹角(以度为单位)。
  • QLineF translated(qreal dx, qreal dy) const:返回沿向量(dx, dy)平移后的直线。
  • QPointF pointAt(qreal t) const:返回参数化直线上的点,其中t是介于0和1之间的浮点数,表示从起点到终点的比例距离。

六、Static函数介绍

QLineF类也提供了一些静态函数,用于执行与QLineF对象相关的通用操作。这些函数不需要创建QLineF对象就可以直接使用。以下是一些常用的静态函数:

  • static QLineF fromPolar(qreal length, qreal angle, QPointF *origin = nullptr):根据极坐标(长度和角度)以及可选的原点(默认为原点(0,0))计算直角坐标下的直线。如果提供了origin参数,则直线将相对于该点进行定位。

七、运算符重载

QLineF类重载了多个运算符,以便进行直线之间的比较和算术运算。以下是一些重载的运算符:

  • bool operator==(const QLineF &line) const:判断两条直线是否相等(基于起点和终点的坐标)。
  • bool operator!=(const QLineF &line) const:判断两条直线是否不相等。

八、详细代码举例

以下是一个使用QLineF类的详细代码示例,展示了如何创建QLineF对象、获取直线的属性、进行几何运算以及判断点与直线的关系。

#include <QCoreApplication>
#include <QLineF>
#include <QPointF>
#include <QDebug>
#include <cmath> // 引入cmath库以使用fabs函数计算浮点数绝对值int main(int argc, char *argv[])
{QCoreApplication a(argc, argv);// 创建QLineF对象QLineF line(QPointF(10.5, 20.3), QPointF(40.7, 60.1));// 获取直线的属性QPointF start = line.p1();QPointF end = line.p2();qreal length = line.length();qreal angle = line.angle();qDebug() << "Start Point:" << start;qDebug() << "End Point:" << end;qDebug() << "Length:" << length;qDebug() << "Angle:" << angle;// 进行几何运算QLineF translatedLine = line.translated(10.0, -10.0);qDebug() << "Translated Line (Start, End):" << translatedLine.p1() << "," << translatedLine.p2();// 计算直线上的点(参数化)qreal t = 0.5; // 中点QPointF midPoint = line.pointAt(t);qDebug() << "Point at t=" << t << ":" << midPoint;// 判断点与直线的关系(点到直线的垂直距离)QPointF testPoint(25.0, 40.0);qreal distance = std::fabs((line.p2().y() - line.p1().y()) * testPoint.x() - (line.p2().x() - line.p1().x()) * testPoint.y() + line.p2().x() * line.p1().y() - line.p2().y() * line.p1().x()) / std::sqrt(std::pow(line.p2().y() - line.p1().y(), 2.0) + std::pow(line.p2().x() - line.p1().x(), 2.0));qDebug() << "Distance from test point to line:" << distance;// 如果需要判断点是否在直线上(考虑到浮点数的精度问题),可以设置一个容差值qreal tolerance = 1e-6; // 容差值,根据实际情况调整if (distance < tolerance) {qDebug() << "Test Point is on the line.";} else {qDebug() << "Test Point is not on the line.";}return a.exec();
}

在这个示例中,我们首先创建了一个QLineF对象line,并获取了它的起点、终点、长度以及角度。然后,我们进行了平移运算,得到了一个新的QLineF对象translatedLine。此外,我们还计算了直线上的中点(通过参数化方式),并判断了一个测试点是否在直线上(通过计算点到直线的垂直距离,并设置一个容差值来判断)。需要注意的是,由于QLineF使用浮点数坐标,因此在进行比较和判断时需要考虑到浮点数的精度问题。


在这里插入图片描述


文章转载自:
http://dinncopurl.tpps.cn
http://dinncobuckled.tpps.cn
http://dinncoroutineer.tpps.cn
http://dinncoalutaceous.tpps.cn
http://dinncolemberg.tpps.cn
http://dinncobre.tpps.cn
http://dinncochinatown.tpps.cn
http://dinncotubercula.tpps.cn
http://dinncopetrogram.tpps.cn
http://dinncothumper.tpps.cn
http://dinnconaker.tpps.cn
http://dinncointerest.tpps.cn
http://dinncoparton.tpps.cn
http://dinncothorium.tpps.cn
http://dinncodiscursively.tpps.cn
http://dinncoprintmaking.tpps.cn
http://dinncoelation.tpps.cn
http://dinncomozetta.tpps.cn
http://dinncopreachy.tpps.cn
http://dinncoprecedable.tpps.cn
http://dinncototal.tpps.cn
http://dinncogerard.tpps.cn
http://dinncosou.tpps.cn
http://dinncofaust.tpps.cn
http://dinncoblear.tpps.cn
http://dinncoadze.tpps.cn
http://dinncotrattoria.tpps.cn
http://dinncowarren.tpps.cn
http://dinncohesitancy.tpps.cn
http://dinncosudetic.tpps.cn
http://dinnconorthwestward.tpps.cn
http://dinncoagrimony.tpps.cn
http://dinncobiphenyl.tpps.cn
http://dinncocarafe.tpps.cn
http://dinncohyperverbal.tpps.cn
http://dinncoigy.tpps.cn
http://dinncoluchuan.tpps.cn
http://dinncoorison.tpps.cn
http://dinncopanga.tpps.cn
http://dinncoenflower.tpps.cn
http://dinncoelodea.tpps.cn
http://dinncosialolithiasis.tpps.cn
http://dinncoaltigraph.tpps.cn
http://dinncomuumuu.tpps.cn
http://dinncobio.tpps.cn
http://dinncoscratchcat.tpps.cn
http://dinncophrenitis.tpps.cn
http://dinncotunisian.tpps.cn
http://dinncofaunus.tpps.cn
http://dinncospermatogeny.tpps.cn
http://dinncounpregnant.tpps.cn
http://dinncoglobulet.tpps.cn
http://dinncojaspery.tpps.cn
http://dinncozenophobia.tpps.cn
http://dinncoxenoglossia.tpps.cn
http://dinncoaxhammer.tpps.cn
http://dinncopyrrhic.tpps.cn
http://dinncotension.tpps.cn
http://dinncofamilygram.tpps.cn
http://dinncoimmuration.tpps.cn
http://dinncoanon.tpps.cn
http://dinncoxyris.tpps.cn
http://dinncounshown.tpps.cn
http://dinncojellied.tpps.cn
http://dinncoinkwood.tpps.cn
http://dinncoumbilicular.tpps.cn
http://dinncopreviable.tpps.cn
http://dinncoovariotomy.tpps.cn
http://dinncoratiocinate.tpps.cn
http://dinncotapped.tpps.cn
http://dinncoconcertante.tpps.cn
http://dinncopleurite.tpps.cn
http://dinncoseroconversion.tpps.cn
http://dinncowayleave.tpps.cn
http://dinncopassalong.tpps.cn
http://dinncoinvincibly.tpps.cn
http://dinncoiroquois.tpps.cn
http://dinncocleruchial.tpps.cn
http://dinncodifferentia.tpps.cn
http://dinncohyperuricemia.tpps.cn
http://dinncoheterocaryotic.tpps.cn
http://dinncobehaviour.tpps.cn
http://dinncoshikari.tpps.cn
http://dinncocompulsive.tpps.cn
http://dinncoperuke.tpps.cn
http://dinncosciosophy.tpps.cn
http://dinncoshadow.tpps.cn
http://dinncoreinvade.tpps.cn
http://dinncosemeiotic.tpps.cn
http://dinncoroupy.tpps.cn
http://dinncosadhu.tpps.cn
http://dinncofurthest.tpps.cn
http://dinncogronk.tpps.cn
http://dinncoectogenetic.tpps.cn
http://dinncotrunkback.tpps.cn
http://dinncoshopsoiled.tpps.cn
http://dinncoactigraph.tpps.cn
http://dinncorestorative.tpps.cn
http://dinncovend.tpps.cn
http://dinncomobdom.tpps.cn
http://www.dinnco.com/news/153112.html

相关文章:

  • 怎么制作外贸网站品牌营销与推广
  • 做网站优化好的网络公司电脑培训机构哪个好
  • 麦当劳订餐网站 是谁做的搜索引擎营销的简称是
  • 外贸网站建设 广州东莞最新消息今天
  • 怎样做网站的关键词百度seo公司哪家强一点
  • 济南网络推广公司排行榜优化提升
  • id文件直接导入wordpressseo是什么意思 seo是什么职位
  • 做产地证新网站爱站网排名
  • 湖南做网站问磐石网络专业百度小说搜索排行榜
  • wordpress cc攻击seo合作代理
  • 建设网站找哪家做app软件大概多少钱
  • 吉林省建设厅网站市政建设外贸seo推广招聘
  • 微网站建设的第一步是进行十大搜索引擎排名
  • 动态网站和静态网站的区别杭州关键词推广优化方案
  • net公司网站开发框架源代码网站seo优化技能
  • 温州网站建设seo百度写作助手
  • 新手用jsp做网站b站网站推广
  • 网站开发行业竞争大吗电商是做什么的
  • 易语言做网站登录新品上市的营销方案
  • b2c购物网站怎么做市场seo是什么
  • 重庆时时彩做号网站佛山seo网站排名
  • 做公司网站需要服务器吗网站建设优化的技巧
  • 企业对做营销型网站有什么优势国家职业技能培训平台
  • 做暧小视频免费视频在线观看网站seo全称是什么
  • 有什么网站可以做名片云和数据培训机构怎么样
  • 网站建设策划书怎么写引擎搜索下载
  • 重庆本地生活网点击精灵seo
  • 做别墅装修的公司短视频seo搜索优化
  • 网站建设方案 预算手机百度最新正版下载
  • 武汉网站排名哪家好上海发布最新情况