自定义室内地图以及路径规划


最近做到一个项目,设计到室内地图路径规划,其实一般的项目也很少设计到室内路径规划,室内也就那么点大。

但是上面怎么说我们就怎么做吧,或者是人性化,或者是多此一举的项目,既然写了就分享出来吧。


先说下大致思想流程吧,语言表达不是很好,有不懂的可以加我的qq24272779询问!

上图例子:

基本思路把上图建筑区域全部用坐标扣选出来,也就是不能走到的地方,蓝色区域和灰色区域。

坐标点以像素为单位。

扣选出来以后把整个图片地图分成由好多小方格组成的!

选择两个点,用A*算法求出需要经过非蓝色和灰色区域的最短路径。

(A*算法不懂的可以百度)。


代码:


//添加地图图片

 SKIndoorMapView *indoorMap = [[SKIndoorMapView alloc]initWithIndoorMapImageName:@"WHTerminalBD.png" Frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.view addSubview:indoorMap];


//长安选择起点和终点
#pragma mark - Zoom methods
-(void)longRequired:(UIGestureRecognizer*)gesture
{
    if (gesture.state == UIGestureRecognizerStateBegan)
    {
        if (Points.count == 0 || Points.count >= 2)
        {
            [Points removeAllObjects];
            for (UIView *view in [self.mapView subviews])
            {
                [view removeFromSuperview];
            }
            //坐标
            CGPoint touchPoint = [gesture locationInView:self.mapView];
            UIImage *Img = [UIImage 
  • 6
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是一个简单的基于Dijkstra算法的AGV路径规划算法的MATLAB代码,该算法可以接受自定义地图: ``` % AGV Path Planning Algorithm based on Dijkstra's Algorithm % Copyright (c) 2021, [Your Name] % All rights reserved. % Define the map map = [1 1 1 1 1 1; 1 0 0 0 0 1; 1 0 1 1 0 1; 1 0 0 1 0 1; 1 1 1 1 0 1; 1 1 1 1 1 1]; % Define the starting and ending points start = [2,2]; goal = [5,5]; % Define the cost of moving between cells cost = ones(size(map)); cost(map == 1) = Inf; % Initialize the distance and visited arrays distance = Inf(size(map)); visited = zeros(size(map)); % Set the distance of the starting point to zero distance(start(1), start(2)) = 0; % Initialize the path array path = zeros(size(map)); % Loop until the goal is reached or all nodes have been visited while ~isequal(visited, ones(size(map))) % Find the node with the smallest distance min_distance = Inf; for i = 1:size(map,1) for j = 1:size(map,2) if visited(i,j) == 0 && distance(i,j) <= min_distance min_distance = distance(i,j); current = [i,j]; end end end % Mark the current node as visited visited(current(1),current(2)) = 1; % Check if the goal has been reached if isequal(current, goal) break; end % Update the distances of neighboring nodes neighbors = get_neighbors(current, map); for i = 1:size(neighbors,1) neighbor = neighbors(i,:); alt_distance = distance(current(1),current(2)) + cost(neighbor(1),neighbor(2)); if alt_distance < distance(neighbor(1),neighbor(2)) distance(neighbor(1),neighbor(2)) = alt_distance; path(neighbor(1),neighbor(2)) = sub2ind(size(map),current(1),current(2)); end end end % Construct the path if isequal(current, goal) p = goal; while ~isequal(p, start) p = ind2sub(size(map),path(p(1),p(2))); path(p(1),p(2)) = Inf; end path(start(1),start(2)) = Inf; end % Plot the map and path figure(); imagesc(map); colormap(flipud(gray)); hold on; [x,y] = find(path == Inf); plot(y,x,'r','LineWidth',2); ``` 该算法使用Dijkstra算法计算从起点到终点的最短路径。在此过程中,我们遍历地图上的每个节点,记录到达每个节点时的最短距离,并使用路径数组记录路径。最后,我们使用路径数组构建路径并在地图上绘制出来。 您可以根据需要自定义地图,只需更改`map`数组即可。您还可以更改`cost`数组来定义移动各个节点的成本。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值