Qt5类之QLine and QLineF

来源:互联网 发布:淘宝客怎样推广产品 编辑:程序博客网 时间:2024/06/14 00:53

QLine



#include <QLine>



介绍



QLine表示平面上整数精度的二维向量,用于描述有限长度的直线也就是线段,起点与终点只具有整数精度。






线段位置的起点与终点可由p1(),x1(),y1(),p2(),x2(),y2()得到,dx()dy()返回线段的水平与垂直跨越长度。isNull()说明是否为无效线段。也可以使用translate()进行指定量的平移。



成员函数



QLine::QLine()QLine::QLine(const QPoint & p1,const QPoint & p2)QLine::QLine(int x1, int y1, int x2, int y2)//构造函数,构造空的或具有指定起点的线段。QPoint QLine::p1()constQPoint QLine::p2()constint QLine::x1()constint QLine::x2()constint QLine::y1()constint QLine::y2()constint QLine::dx()constint QLine::dy()const//取得线段的相关位置信息bool QLine::isNull()const//如果线段具有无效的起点或终点,返回truevoid QLine::setP1(const QPoint & p1)void QLine::setP2(const QPoint & p2)void QLine::setLine(int x1, int y1, int x2, int y2)void QLine::setPoints(const QPoint & p1,const QPoint & p2)//与之前的对应,设置线段的位置信息void QLine::translate(const QPoint & offset)void QLine::translate(int dx, int dy)//重载函数,对直线进行指定量的平移QLine QLine::translated(const QPoint & offset)constQLine QLine::translated(int dx, int dy)const//返回给定相应的偏移量平移得到的线段bool QLine::operator!=(const QLine & line)constbool QLine::operator==(const QLine & line)const//如果两条线段的起点与终点都相同,判定为两条线段等同,否则为不等同




相关的非成员


QDataStream & operator<<(QDataStream & stream,const QLine & line)QDataStream & operator>>(QDataStream & stream, QLine & line)//重载<<,>>运算符,使得QDataStream数据流用来存取QLine线段




QlineF



#include <QlineF>



介绍



QLineF与QLine不同在于提供了浮点精度线段表示,在成员函数方面增加了角度,单位向量等的表示,不过线段的表示法还是一样的,由两个点起点与终点标识。



静态公有成员


QLineF QLineF::fromPolar(qreal length, qreal angle) [static]//根据极坐标,返回指定长度与角度的向量,起点任意




公有类型

enumQLineF::IntersectType

QlineF::UnboundedIntersection表示两条线段实际不相交,但是其所在直线是相交的

QlineF::BoundedIntersection表示两条线段实际相交,在其所有的长度范围中

QlineF::NoIntersection表明两条线是平行的





成员函数


QLineF::QLineF()QLineF::QLineF(const QPointF & p1,const QPointF & p2)QLineF::QLineF(qreal x1, qreal y1, qreal x2, qreal y2)//同QLine,重载构造函数构造线段QLineF::QLineF(const QLine & line)//构造函数,将指定的整数精度的QLine改变为浮点精度的QLineF对象QPointF QLineF::p1()constQPointF QLineF::p2()constqreal QLineF::x1()constqreal QLineF::x2()constqreal QLineF::y1()constqreal QLineF::y2()const//取得线段相应的位置信息qreal QLineF::angle()const//取得线段的角度信息,返回[0,360),0度方向为x轴正向,按逆时针增加qreal QLineF::angleTo(const QLineF & line)const//当前线段到指定线段的角度。注意的是线段是有方向的,也就是向量,角度值计算时是起点重合方式来计算,返回[0,360)的正值qreal QLineF::dx()constqreal QLineF::dy()const//线段的水平与垂直量IntersectType QLineF::intersect(const QLineF & line, QPointF * intersectionPoint)const//当前线段与指定线段的相交情况,返回值为IntersectType,若相交,则intersectionPoint为交点,若平行则intersectionPoint未定义bool QLineF::isNull()const//线段是否是无效的qreal QLineF::length()const//线段的长度QLineF QLineF::normalVector()const//得到相同长度相同起点的与之垂直的线段





QPointF QLineF::pointAt(qreal t)const//如果t=0,返回起点,t=1,返回终点void QLineF::setP1(const QPointF & p1)void QLineF::setP2(const QPointF & p2)//设置更改端点的值void QLineF::setAngle(qreal angle)//设置更改角度的值,正数表示逆时针,负数表示顺时针void QLineF::setLength(qreal length)//起点不变,更改线段的长度void QLineF::setLine(qreal x1, qreal y1, qreal x2, qreal y2)void QLineF::setPoints(const QPointF & p1,const QPointF & p2)//设置端点值QLine QLineF::toLine()const//QLineF变换为QLine对象,四舍五入void QLineF::translate(const QPointF & offset)void QLineF::translate(qreal dx, qreal dy)QLineF QLineF::translated(const QPointF & offset)constQLineF QLineF::translated(qreal dx, qreal dy)const//同QLineQLineF QLineF::unitVector()const//取得当前向量的单位向量,起点不变bool QLineF::operator!=(const QLineF & line)constbool QLineF::operator==(const QLineF & line)const//同QLine




相关的非成员


QDataStream & operator<<(QDataStream & stream,const QLineF & line)QDataStream & operator>>(QDataStream & stream, QLineF & line)//同QLine



原创粉丝点击