pyqt4文档阅读(7.5):QLineF

本系列文章长期更新修改.


QLineF,是QLine的浮点数版本,但QLineF拥有的函数比QLine丰富得多,这主要是因为线条的很多操作都离不开浮点数.


属性:


Types

  • enum IntersectType { NoIntersection, BoundedIntersection, UnboundedIntersection }

Methods

  • __init__ (self, QLine line)
  • __init__ (self)
  • __init__ (self, QPointF apt1, QPointF apt2)
  • __init__ (self, float x1pos, float y1pos, float x2pos, float y2pos)
  • __init__ (self, QLineF other)
  • float angle (self, QLineF l)
  • float angle (self)
  • float angleTo (self, QLineF l)
  • float dx (self)
  • float dy (self)
  • IntersectType intersect (self, QLineF l, QPointF intersectionPoint)
  • bool isNull (self)
  • float length (self)
  • QLineF normalVector (self)
  • QPointF p1 (self)
  • QPointF p2 (self)
  • QPointF pointAt (self, float t)
  • setAngle (self, float angle)
  • setLength (self, float len)
  • setLine (self, float aX1, float aY1, float aX2, float aY2)
  • setP1 (self, QPointF aP1)
  • setP2 (self, QPointF aP2)
  • setPoints (self, QPointF aP1, QPointF aP2)
  • QLine toLine (self)
  • translate (self, QPointF point)
  • translate (self, float adx, float ady)
  • QLineF translated (self, QPointF p)
  • QLineF translated (self, float adx, float ady)
  • QLineF unitVector (self)
  • float x1 (self)
  • float x2 (self)
  • float y1 (self)
  • float y2 (self)

Static Methods

  • QLineF fromPolar (float length, float angle)

Special Methods

  • QLineF __mul__ (self, QMatrix m)
  • QLineF __mul__ (self, QTransform m)
  • bool __eq__ (self, QLineF d)
  • bool __ne__ (self, QLineF d)
  • int __nonzero__ (self)
  • object __repr__ (self)


详细分析:


1.QLineF与QLine

虽然QLineF的函数比QLine丰富得多,但它们也有许多用法相同的函数,下面的函数用法都和QLine相同或相似,用法参考QLine篇.

  • __init__ (self)
  • __init__ (self, QPointF apt1, QPointF apt2)
  • __init__ (self, float x1pos, float y1pos, float x2pos, float y2pos)
  • __init__ (self, QLineF other)
  • float x1 (self)
  • float x2 (self)
  • float y1 (self)
  • float y2 (self)
  • QPointF p1 (self)
  • QPointF p2 (self)
  • setP1 (self, QPointF aP1)
  • setP2 (self, QPointF aP2)
  • setLine (self, float aX1, float aY1, float aX2, float aY2)
  • setPoints (self, QPointF aP1, QPointF aP2)
  • translate (self, QPointF point)
  • translate (self, float adx, float ady)
  • QLineF translated (self, QPointF p)
  • QLineF translated (self, float adx, float ady)
  • float dx (self)
  • float dy (self)
  • bool isNull (self)

QLine和QLineF能互相转换,其中下面的toLine()会将浮点数属性四舍五入成整数属性.

  • __init__ (self, QLine line)
  • QLine toLine (self)

2.角度和长度

线段的表示,除了起点终点坐标表示法,还可以把终点替换成角度和长度.

但是,一般角度和长度都是浮点数的存在,因此只有QLineF才有这两个虚拟属性.

  • float angle (self)
  • setAngle (self, float angle)
  • float length (self)
  • setLength (self, float len)

注意,QLineF对角度和长度的改变,都是根据起点改变的.即起点不会变,只有终点会改变.

关于角度的方向,Qt仍然是以水平向右的线段为0度,线段逆时针转则角度不断增加.

角度的取值范围为[0,360),单位是角度,不是弧度.

3.判断线段相交

QLineF特有的IntersectType枚举类型,即为线段相交的几种情况.

枚举量描述
NoIntersection0两线段平行
BoundedIntersection
1两线段相交
UnboundedIntersection2两线段不相交,但所在直线相交
下面函数用来判断线段相交情况,第二个参数是一个输出参数,储存相交的坐标,若两线段平行,则该参数输出未定义.

  • IntersectType intersect (self, QLineF l, QPointF intersectionPoint)

4.线段计算

函数含义备注
float angle (self, QLineF l)两线段夹角取值范围[0,180)
float angleTo (self, QLineF l)两线段夹角该夹角为自身逆时针旋转到和参数线段水平的夹角,取值范围[0,360)
QLineF normalVector (self)法向量该法向量起点和长度和自身一样,角度是自身逆时针旋转90度的角度
QPointF pointAt (self, float t)比例点求从起点开始延伸t*长度的位置,t取值范围[0,1].
t=0时即为起点,t=1时为终点
QLineF unitVector (self)单位向量该单位向量起点和角度和自身一样,长度是1

5.从起点生成线段

fromPolar静态方法以(0,0)为起点,根据参数的角度和长度,生成一个QLineF对象.

  • QLineF fromPolar (float length, float angle)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值