wrong map position
I am using the map file generated by the hector slam in qt quick applicatino. Here when i click on the map location the x coordintates are accurate but the y value are not comming accurate. The forumula i'm using is:
onPressed: {
fnameFieldX.text = point1.x * resolution-map_origin.x
fnameFieldY.text = point1.y * resolution-map_origin.y
}
For example when i press at center i.e 0,0 location of popular turtlebot3 world map. The x,y data is comming as: 0.04,0.9
.
Here the orign is 10,10 and resolution is 0.05 acording to map.yaml file.
image: ./map.pgm
resolution: 0.050000
origin: [-10.000000, -10.000000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196
Asked by dinesh on 2021-08-07 13:39:39 UTC
Answers
If you look the gray area at the right bottom corner is -10,-10 and the center is also looks like 0,0 this coordinate system is cartesian coordinate system. In this system maps x values increase from left to right and and y values increase from bottom to top. Generally mobile and web application coordinate system is little bit different. In that type of applications origin point accepted left top point and y axis value is increase from top to bottom.
So that you can calculate your click position on the map with this formula
- x = click.x(px)*map_resolution(meter/px) + origin.x(meter)
- y = (map.height(px) - click.y(px))*map_resolution(meter/px) + origin.y(meter)
If we make a check - Our click position (200,184)(px) (this is center point on this map you can check it with paint or other app) our map size (384,384)(px) and origin (-10,-10)(meter) and resolution 0.05
- x (200*0.05) + (-10) = 0
- y = ((384-184)*0.05) + (-10) = 0
I hope that has been revealing
Asked by bekirbostanci on 2021-08-08 14:52:25 UTC
Comments
In this map 384x384 pixel and if you calculate your map dimensions 384x0.05 = 19.2 meter
Asked by bekirbostanci on 2021-08-07 16:31:46 UTC
What are the point.x and point.y values when you press the upper left corner? What are the point.x and point.y values when you press the bottom right corner?
Asked by bekirbostanci on 2021-08-08 03:19:56 UTC
Its 0,0 as expected. Their is no problem in pixel position as i confirmed. eg. If i click on bottom right corner the x and y coms as the height and widht of the image itself.
Asked by dinesh on 2021-08-08 07:10:48 UTC