Is there a Qt class representing a 2D ray (point and direction)?
-
This is a quick question about the availability of a suitable geometric class in Qt. I tried searching but didn't find anything useful, but it might be because I don't know the correct terminology. Any help would be appreciated!
I want to represent a ray (half-line) defined as a 2D point (
QPointF
) and a direction (e.g. an angle or vector in 2D). This is different to aQLineF
since it has only one point and the other end goes off into infinity in the defined direction. Does such a class exist in Qt already? It seems like there should be one. I'd ideally like to benefit from built-in methods for rotating such an object instead of rolling my own. -
Following up on this - I think there is not such a class and it seems like there won't be one, mainly because there is even not a vector class in
QtCore
(onlyQVector2D
inQtGui
, intended for GUI stuff like vertexes and not geometry calculations). TheQLine
class has aunitVector()
function which returns anotherQLine
. Since there's not even a vector class I expect there will not be a ray class. If anyone knows for sure, I'd still be interested to hear. -
Following up on this - I think there is not such a class and it seems like there won't be one, mainly because there is even not a vector class in
QtCore
(onlyQVector2D
inQtGui
, intended for GUI stuff like vertexes and not geometry calculations). TheQLine
class has aunitVector()
function which returns anotherQLine
. Since there's not even a vector class I expect there will not be a ray class. If anyone knows for sure, I'd still be interested to hear.@sasl said in Is there a Qt class representing a 2D ray (point and direction)?:
Following up on this - I think there is not such a class and it seems like there won't be one, mainly because there is even not a vector class in
QtCore
(onlyQVector2D
inQtGui
, intended for GUI stuff like vertexes and not geometry calculations). TheQLine
class has aunitVector()
function which returns anotherQLine
. Since there's not even a vector class I expect there will not be a ray class. If anyone knows for sure, I'd still be interested to hear.There's
QVector2D
,QVector3D
andQVector4D
. I really don't understand the question though, a "ray" is the same as a line - 2 vectors (or 2 points for that matter). Written in parametric form the only difference is that the scaling parameter for a ray goes to positive only, while for a line it can go positive and negative. In linear algebra there's no distinction between a point and a vector, as a (radius) vector identifies a specific point and vice versa. Transforming points is the same as transforming vectors, which is simply a matrix operator applied in the vector space. Finally Qt isn't a proper geometry library, it provides what is needed for graphics, not for general purpose calculations. -
Following up on this - I think there is not such a class and it seems like there won't be one, mainly because there is even not a vector class in
QtCore
(onlyQVector2D
inQtGui
, intended for GUI stuff like vertexes and not geometry calculations). TheQLine
class has aunitVector()
function which returns anotherQLine
. Since there's not even a vector class I expect there will not be a ray class. If anyone knows for sure, I'd still be interested to hear.@sasl
there is also QMatrix
https://doc.qt.io/qt-5/qmatrix.html