user1050619
user1050619

Reputation: 20916

pyqt5 normalize a vector

Assume I have 2 points in Pyqt5.

QtCore.QPoint(200,200)
QtCore.QPoint(400,400)

Now, I would like to normalize this vector points. Is there a way to find the normalized vector?

Upvotes: 1

Views: 215

Answers (1)

eyllanesc
eyllanesc

Reputation: 244311

Use QVector2D:

from PyQt5 import QtCore, QtGui

A = QtCore.QPoint(200,200)
B = QtCore.QPoint(400,400)

res = QtGui.QVector2D(B-A).normalized()
print(res)

Output:

PyQt5.QtGui.QVector2D(0.7071067690849304, 0.7071067690849304)

Upvotes: 1

Related Questions