1

I have a canvas in Qt (QGraphicsScene in QGraphicsView) on which user can add shapes: circle, square, rectangle, ellipse and triangle and change the size of either (as single QGraphicsObject subclass). Between these shapes user can create lines and the direction of the line is indicated by drawing an arrow at the intersection point of the line and a shape in the similar manner to Qt's example ElasticNodes (the connection is also QGraphicsObject suclass).

Now in order to support bi-directional connections and multiple connections of the same shapes I change any subsequent connection line into quadratic curve with progressively bigger arc to allow their selection and visualisation.

  • The implementation of the shapes is so that their centre is NOT top left, but instead the centre of the shape.
  • The connection between them is a line between these two centres pushed back in Z axis so it hides behind the shapes.
  • The arrow is position at the edge on a shape is determined depending on a shape: radius for circle and trigonometrics for other shapes.

Now when using quadratic curve I need to reposition the arrow to the intersection point of the curve and a shape. With that point I can then use the same procedure to render the arrow because I can get the angle at certain point from QPainterPath.

However he biggest challenge is to detect this collision point. The only option I can think of is to use QPainterPath::intersected but for that to work it requires fill areas (i.e. making the curve with a width of at least 2) and I would still need to somehow extract the correct point from the result - not sure how yet.

I would appreciate any ideas on how I could go about this.

Resurrection
  • 3,916
  • 2
  • 34
  • 56
  • This might help: http://web.archive.org/web/20090521080353/http://cagd.cs.byu.edu/~557/text/ch7.pdf – dtech Oct 09 '15 at 07:24
  • Basically you want to find the intersection point of line and object's polygon in Qt? – Alexander Tyapkov Oct 09 '15 at 09:15
  • If I understood it correctly, you cannot do it with Qt. Either you have to write your own collision detection module or use side libraries. – Alexander Tyapkov Oct 09 '15 at 09:23
  • did you find a solution? – Bob Jan 14 '16 at 18:13
  • @Mikhail Unfortunately this is not possible without prohibitive amount of computation required for collision detection. Since I allow thousands of objects this was not feasible. The solution was to move the arrow from the edge of receiving object to about 60 % path (not exactly the middle but close to it) so it is easily distinguishable from those coming in the opposite direction but does not need any collision detection. Does not look too shabby either. :-) – Resurrection Jan 14 '16 at 19:56
  • this one seems to me useful [link](https://forum.qt.io/topic/16725/beginner-collision-detection-with-boundary-and-part-of-an-item/2), trying to implement with vectors. – Bob Jan 14 '16 at 20:22

0 Answers0