PDA

View Full Version : Check a point inside or outside a road?



kstking
15th October 2007, 14:35
Please see my Road picture, I draw it by QCanvas and use canvasview to show it. I have used : DrawLine , drawrect of QCanvas, and drawcubicbezier of QPainter to draw it.
And now! i have a point. This point can be in anywhere on canvasview. How do i check it inside or outside a road?
--> I thinked about using color to fill the road. And i will check color at position of point. If color at point same color of road => i will say this point inside the road!!!--> is that OK?if it ok! how can i get color at position of point? how can i fill color for road. It not a polygon.

--> OR using point matrix, any point inside the road will have value = 1. and outside have value = 0. But ! it hard to create this matrix with the value.

--> OR using this algorithm : "check a point inside or outside the polygon". This method can use for one part of road. But at confluence or more...It not a polygon.

>>what else?

Brandybuck
15th October 2007, 19:48
Using QGraphicsView framework (Qt4), there are several ways to determine this. Looking at your image, it seems that your items can have have nicely defined QPainterPath shapes. So you can use QGraphicsItem::contains(). There are other ways as well, such as QGraphicsScene::itemAt().

QGraphicsView is soooo much better than QCanvas, you may want to upgrade to Qt4 if you can.