Help to simulate 2D robots
-
I am a beginner, I ask you for help because I would like to create a 2d simulator of a 3-wheeled robot.
The environment where the robot moves is a 3-color .png image:
Red = obstacle, Black = lines to follow, White = clear space.
The sensors are cones (QShape) that move with the robot.
I need to determine the closest point to the apex of the cone when the shape of the cone overlaps the red color (the point is in the overlapping part).
In addition, I have to determine when certain points of the robot pass over black.
I don't know how to process the images to determine the data I need.
If you can give me some information, thank you.
Greetings -
I am a beginner, I ask you for help because I would like to create a 2d simulator of a 3-wheeled robot.
The environment where the robot moves is a 3-color .png image:
Red = obstacle, Black = lines to follow, White = clear space.
The sensors are cones (QShape) that move with the robot.
I need to determine the closest point to the apex of the cone when the shape of the cone overlaps the red color (the point is in the overlapping part).
In addition, I have to determine when certain points of the robot pass over black.
I don't know how to process the images to determine the data I need.
If you can give me some information, thank you.
Greetings -
Thank you for your reply.
I have already seen that document and I understand that if I have gods
QGraphicsItem I can determine the intersection with:QPainterPath intersectedPath = tem1-> shape () -> intersected (item2-> shape ());
I measure the distance between the points that make up the intersectedPath
with the vertex of the triangle and take the smaller one.
the triangle (Cone) of the sensors I create a QGraphicsItem also the points on the robot.
What I didn't understand is how I get a QGraphicsItem or a shape with the red and black colors of the image.
Greetings -
Thank you for your reply.
I have already seen that document and I understand that if I have gods
QGraphicsItem I can determine the intersection with:QPainterPath intersectedPath = tem1-> shape () -> intersected (item2-> shape ());
I measure the distance between the points that make up the intersectedPath
with the vertex of the triangle and take the smaller one.
the triangle (Cone) of the sensors I create a QGraphicsItem also the points on the robot.
What I didn't understand is how I get a QGraphicsItem or a shape with the red and black colors of the image.
Greetings@feri said in Help to simulate 2D robots:
What I didn't understand is how I get a QGraphicsItem or a shape with the red and black colors of the image.
Use a
QBrush
and fill your item with your desired color. For 2 colors you could split the item in 2 subsections with twoQPainters
(one with red brush, one with black) and fill them separately.