简体   繁体   English

如何获取QGraphicsScene项目中QPolygonF项目的当前角度?

[英]How to get the current angle of a QPolygonF item in a QGraphicsScene item?

I'm want to implement seek behavior with an itme rotation towards the direction point. 我想通过朝向方向点的itme旋转实现搜索行为。 All manipulations I'm making in QGraphicsView with QGraphicsScene and a QPolygonF item. 我在QGraphicsView中使用QGraphicsScene和QPolygonF项目进行的所有操作。 在此处输入图片说明

I do not know the current angle of the QPolygonF item to subtract from the target point angle. 我不知道要从目标点角度减去QPolygonF item的当前角度。 How can i make it? 我该怎么做? 在此处输入图片说明

You can use a QGraphicsPolygonItem and rotate that towards the target. 您可以使用QGraphicsPolygonItem并将其向目标rotate (To determine the angle, take the item.pos() - point.pos() and calculate it's arctangent). (要确定角度,请使用item.pos() - point.pos()并计算其反正切)。

You should really not bother with rotating the painter as you do in the other question your refer to, but with rotating the Vehicle , which should be a QGraphicsSceneItem . 实际上,您不应该像在参考其他问题时那样旋转绘画器,而是旋转Vehicle (应该是QGraphicsSceneItem The GraphicsScene takes care of the transformations. GraphicsScene负责转换。

Next to that, probably the rotation angle should be the atan(...) *360/twopi . 紧接着,旋转角度可能应该是atan(...) *360/twopi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM