Recently achieved a project, design to indoor map path planning, in fact, the general project is rarely designed to indoor path planning, indoor is so big.
But the above how to say we do it, or is humane, or is the superfluous project, since the write to share it.
First of all, the idea of the flow of ideas, language is not very good, have not understand can add my qq24272779 inquiry!
Example:
The basic idea is to select all the building areas in the coordinates, that is, the areas that cannot be reached, the blue area and the gray area.
Sitting punctuation is measured in pixels.
After the selection, the whole picture map is divided into a lot of small squares!
Select two points and use a A * algorithm to find the shortest path that needs to go through the non-blue and gray areas.
(A * algorithm can not understand Baidu).
Code:
Add a map picture
Skindoormapview *indoormap = [[Skindoormapview alloc]initwithindoormapimagename:@ ' whterminalbd.png ' Frame: CGRectMake (0, 0, Screen_width, screen_height)]; [Self.view Addsubview:indoormap];
Changan Select Start and end point
#pragma mark-zoom methods-(void) longrequired: (uigesturerecognizer*) gesture{if (gesture.state = = Uigesturerecognizer Statebegan) {if (Points.count = = 0 | | Points.count >= 2) {[Points removeallobjects]; For (UIView *view in [Self.mapview subviews]) {[View Removefromsuperview]; }//coordinates 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--with uigraphicsbeginimagecontext opaque-transparent switch, if the graphic is not transparent at all, set to Yes to optimize the storage of the bitmap. scale-– Scaling Factor */Uigraphicsbeginimagecontextwithoptions (Cgsizemake (480), NO, [UIScreen Mainscreen].scale); Uibezierpath *path = [Uibezierpath Bezierpath]; [[Uicolor Redcolor] setstroke]; [Path setlinewidth:0.5]; [Path Setlinejoinstyle:kcglinejoinround]; [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 starting path of the point} [path Addlinetopoint:cgpoint make ([obj ID_col], [obj Id_row]); }} [path stroke]; UIImage *img =uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); Uiimageview *IMGV = [[Uiimageview alloc]initwithimage:img]; [_mapview ADDSUBVIEW:IMGV]; [Self setneedsdisplay];}
Here, let's see how to pick the blue area and the grey non-path planning area.
<pre name= "code" class= "OBJC" >-(BOOL) Checkmap: (int) col row: (int) row{Cgpoint point = Cgpointmake (col, Row); /* 150,45,180,45,180,70,150,70 Duty 200,10,225,10,225,50,180,50,180,45,200,45 Unknown area 160 , 75,180,75,180,150,150,150,150,135,120,135,120,145,195,150,95,125,120,110,140,110,160,95 parcel packing area 100,165,125, 65, 125,270,140,270,140,280,85,280,85,260,95,260, terminal 150,170,170,170,170,260,150,260 Security Area 10,310,60,28 0,150,290,150,275,180,275,180,305,150,305,150,360,170,360,170,390,200,405,200,475,150,475,150,380 seating area */* 180,350,220,250,220,370,180,380 Unknown Area 0,0,200,0,200,45,150,45,150,75,10,145,60,170,70,28010,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 = @ "1 50,45,180,45,180,70,150,70 "; NSString *obstacle01 = @ "200,10,225,10,225,50,180,50,180,45,200,45"; NSString *obstacle02 = @ "160,75,180,75,180,150,150,150,150,135,120,135,120,145,195,150,95,125,120,110,140,110,160,95 "; NSString *obstacle03 = @ "100,165,125,65,125,270,140,270,140,280,85,280,85,260,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 bezierpathfromcoordinatestring:obstacle00]; Uibezierpath *path01 = [Utils bezierpathfromcoordinatestring:obstacle01]; Uibezierpath *path02 = [Utils bezierpathfromcoordinatestring:obstacle02]; Uibezierpath *path03 = [Utils bezierpathfromcoordinatestring:obstacle03]; Uibezierpath *path04 = [Utils bezierpathfromcoordinatestring:obstacle04]; Uibezierpath *path05 = [Utils bezierpathfromcoordinatestring:obstacle05]; Uibezierpath *path06 = [Utils bezierpathfromcoordinatestring: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!
Custom interior maps and path planning