Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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 a QLineF 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.



  • This post is deleted!


  • 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 (only QVector2D in QtGui, intended for GUI stuff like vertexes and not geometry calculations). The QLine class has a unitVector() function which returns another QLine. 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.


  • Qt Champions 2017

    @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 (only QVector2D in QtGui, intended for GUI stuff like vertexes and not geometry calculations). The QLine class has a unitVector() function which returns another QLine. 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 and QVector4D. 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.


  • Moderators


Log in to reply