Customize indoor map and Path Planning and indoor Planning

Source: Internet
Author: User

Customize indoor map and Path Planning and indoor Planning


Recently, we have implemented a project to design the indoor map path planning. In fact, the general project is rarely designed to design the indoor path planning, and the interior is so big.

But let's do it as we said above, or it's a user-friendly project. If you write it, share it with you.


Let's talk about the general idea process first. The language is not very good. If you don't understand it, add my qq24272779 to ask!

Example:

The basic idea is to select all the building areas with coordinates, that is, the areas that cannot be reached, the blue area and the gray area.

Coordinates are measured in pixels.

After the selection, the entire image map is divided into a lot of small squares!

Select two points and use the * algorithm to find the shortest path that needs to go through non-blue and gray areas.

(A * Baidu is not familiar with algorithms ).


Code:


// Add a map image

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


// Changan selects the start and end points
# 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];} // coordinate CGPoint touchPoint = [gesture locationInView: self. mapView]; UIImage * Img = [UIImage imageNamed: @ "startPoint"]; UIImageView * imgView = [[UIImageView alloc] initWithImage: Img]; [imgView setFrame: CGRectMake (touchPoint. x-(Img. size. width/(self. zoomScale * 2), touchPoint. y-(Img. size. width/(self. zoomScale), Img. size. width/self. zoomScale, Img. size. height/self. zoomScale)]; [self. mapView addSubview: imgView]; [Points addObject: NSStringFromCGPoint (touchPoint)];} else if (Points. count = 1) {// coordinate CGPoint touchPoint = [gesture locationInView: self. mapView]; UIImage * Img = [UIImage imageNamed: @ "endPoint"]; UIImageView * imgView = [[UIImageView alloc] initWithImage: Img]; [imgView setFrame: CGRectMake (touchPoint. x-(Img. size. width/(self. zoomScale * 2), touchPoint. y-(Img. size. width/(self. zoomScale), Img. size. width/self. zoomScale, Img. size. height/self. zoomScale)]; [self. mapView addSubview: imgView]; [Points addObject: NSStringFromCGPoint (touchPoint)]; [self RoadRecevied: Points] ;}}

# Pragma path-(void) RoadRecevied :( NSMutableArray *) Arr {/* Path Planning */AStar * astar = [[AStar alloc] init]; data = [astar findPath: CGPointFromString (Arr [0]). x curY: CGPointFromString (Arr [0]). y aimX: CGPointFromString (Arr [1]). x aimY: CGPointFromString (Arr [1]). y];/* size -- same as UIGraphicsBeginImageContext opaque-transparent switch. If the image is completely transparent, set YES to optimize the storage of Bitmap. Scale -- Scaling Factor */uigraphicsbeginimagecontextwittions (CGSizeMake (320,480), NO, [UIScreen mainScreen]. scale); UIBezierPath * path = [UIBezierPath bezierPath]; [[UIColor redColor] setStroke]; [path setLineWidth: 0.5]; [path setLineJoinStyle: callback]; [path setLineCapStyle: kCGLineCapRound]; BOOL isfirst = YES; if (data & [data count]> 0) {for (id obj in data) {if (isfirst) {isfirst = NO; [path moveToPoint: CGPointMake ([obj id_col], [obj id_row])]; // set the start path point} [path addLineToPoint: CGPointMake ([obj id_col], [obj id_row])] ;}} [path stroke]; UIImage * img = histogram (); UIGraphicsEndImageContext (); UIImageView * imgV = [[UIImageView alloc] initWithImage: img]; [_ mapView addSubview: imgV]; [self setNeedsDisplay];}

// Here let's see how to select the blue area and the gray non-Path Planning area.

<Pre name = "code" class = "objc">-(bool) checkMap :( int) col row :( int) row {CGPoint point = CGPointMake (col, row ); /* 180,150,150,150,150,135,120,135,120,145,195,150, 45, 95,125,120,110,140,110,160, 100,165,125, 65,125,270,140,270,140,280, 95, 85,280, 85,260, 95,260, 150,170,170,170,170,260,150,260, 10,310 security check area, 60,280,150,290,150,275,180,275,180,305,150,305,150,360,170,360,170,390,200,405,200,475,150,475,150,380, 180,350,220,250,220,370,180,380 rest area * // * 10,145, 60,170, 310,150,380,150,420,190,425,150,480, 0,480 left gray 230,0, 320,0, 320,480,230,480 right gray */NSString * obstacle00 = @ ", 45, 18, 18,,"; NSString * obstacle01 = @ ", 10, 50, 180,150,150,150,150,135,120,135,120,145,195,150, 95,125,120,110,140,110,160, 100,165,125, 65,125,270,140,270,140,280 "; NSString * obstacle02 = @" 85,280, 85,260, 95 "; NSString * obstacle03 =, 95,260 "; NSString * obstacle04 = @" 150,170,170,170,170,260,150,260 "; NSString * obstacle05 = @" 10,310, 60,280,150,290,150,275,180,275,180,305,150,305,150,360,170,360,170,390,200,405,200,475,150,475,150,380 "; NSString * obstacle06 = @" 180,350,220,250,220,370,180,380 "; UIBezierPath * path00 = [Utils failed: obstacle00]; UIBezierPath * path01 = [Utils failed: obstacle01]; required * path02 = [Utils failed: obstacle02]; UIBezierPath * path03 = [Utils failed: obstacle03]; UIBezierPath * path04 = [Utils failed: obstacle04]; UIBezierPath * path05 = [Utils failed: obstacle05]; UIBezierPath * path06 = [Utils failed: obstacle06]; // NSString * str110 = @ "10,145, 65,170, 65,280, 10,310,150,385,150,423,190,425,190,475,230,475,230, 5,200, 5,200, 45,150, 45,150, 75"; if (CGPathContainsPoint (path00.CGPath, NULL, point, false )) {return NO;} else if (CGPathContainsPoint (path01.CGPath, NULL, point, false) {return NO;} else if (CGPathContainsPoint (path02.CGPath, NULL, point, false )) {return NO;} else if (CGPathContainsPoint (path03.CGPath, NULL, point, false) {return NO;} else if (CGPathContainsPoint (path04.CGPath, NULL, point, false )) {return NO;} else if (CGPathContainsPoint (path05.CGPath, NULL, point, false) {return NO;} else if (CGPathContainsPoint (path06.CGPath, NULL, point, false )) {return NO;} return YES ;}

 


Let's take a look at the final effect!






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.