You are on page 1of 7

본론

2.3 세부 컴포넌트 기능 (Choosing 3 points and finding route


from their center to the restaurant)
This part of application consists of 1 major and 4 minor functions, used to display
map and plot route to the user chosen restaurant from central point.

In the first, map_graph – the main function here, is called in order to show map on the
figure. Prefabricated Sejong University campus map image was received from
https://www.openstreetmap.org. Obtained image is being read using MATLAB in-built
‘imread’ function, which stores it as MxNx3 array. Next we set the axes so that the
coordinates are displayed correctly on map. This can be done with use of the same
website as above.

Figure 2.3.1 Setting axes for map

GUI figure for this part consists of eight main elements (4 Push buttons, 3 static texts, and
1 axis):

Figure 2.3.2 Figure

When this figure is launched for the first time, buttons other than ‘Close’ and ‘Show
Central Point’ are disabled so the user cannot accidentally choose wrong option. Pressing
this button allows the user to mark three points on the map, which are the positions of
three people. This is done by using ‘ginputax’ from Pedro Teodoro from mathworks
community (https://www.mathworks.com/matlabcentral/fileexchange/39799-ginput-
funtion-to-be-used-in-guis) . ‘ginputax’ is advanced version of MATLAB standard function
‘ginput’, used to get position from plot. The main advantage of this is the fact that using
this function cursor will not crawl out of map (Figure 2.3.3). Position of these three points
is stored in n1, n2, n3 variables. These points form a triangle together, which is displayed
using MATLAB ‘plot’ function. Along with these lines, center of this triangle will appear on
the map.
Figure 2.3.3 a) Cursor without
‘ginputax’ function; b) cursor
with ‘ginputax’ function

In the next step, ‘Show Central Point’ button is disabled and button ‘Find Nearest
Building’ becomes available. Firstly, we need to load buildings data from predefined file
‘buildings.mat’, which consists of 6 buildings. In the next step, we delete 3 points forming
triangle. NearestBldFinder function is called then and its output is assigned to handles.bld.
After finding nearest building to the central point, name of the building is being written in
the figure and position of building is being displayed (Figure 2.3.4, Figure 2.3.5). ‘Find
nearest building’ button is being disabled, and user can click ‘Show way to the restaurant’
button from this moment.

Figure 2.3.4 Displaying name and position of the nearest building

1페이지
Figure 2.3.5 Name of the nearest building

After showing nearest building, user can finally find way to the restaurant. From
rest_name.mat we load name of the user chosen restaurant. Then, RestaurantRouteReader
function is called in order to find route to the restaurant. When route data is obtained,
‘plot’ function along with ‘pause’ is used in order to show “moving” route from building
to the restaurant. In the end, user can choose whether to return back to restaurant or to
close figure.

Figure 2.3.6 Plotting route to the restaurant

DataReader function is used for retrieving GPS data from txt. file. NMEA format for data
was chosen to be GGA (GPGGA or GNGGA). It was also decided to use decimal degree
(DD; ddd.ddddd) coordinate format since it is more understandable for users. Output of
this function is array structure consisting of latitude and longitude coordinates. The
algorithm is as follows: firstly, file is being read and data from first line is stored in the
buffer. Then it checks, whether it is EOF (End of file), or not. Next step is to be sure, that
we read right NMEA format, which is, as stated earlier, XXGGA (where XX may denote
either GN or GP) (Figure 2.3.8). If format is valid, we are ready to scan coordinates
(latitude and longitude). XXGGA gives coordinates only in degrees and decimal
minutes(ddd mm.mmmm), so we need to convert them to decimal degree as well (Figure
2.3.7). When first line is read and stored, steps from second are repeated again until we
reach end of the file. Finally, when data reading is finished, we write all acquired
coordinates to structure called ‘data’.

Figure 1.3.7 dddmm.mmm to ddd.ddddd conversion.

Figure 2.3.8 Check if data format is correct or not.

2페이지
Another important function is CenterFinder. It is utilized to find center of 3 points chosen
by user. It is not exact center, but rather centroid, which can be found using formula (1)
and (2):
p 1lat + p2lat + p 3lat
(1) C lat =
3

p 1lon + p 2lon + p3 lon


(2) C lon=
3
Where C is central point and p1, p2, p3 are coordinates of 3 points chosen by user,
respectively. Output is structure with the center coordinates.

Figure 2.3.9 User chooses position of 3 points (red) and CenterFinder function calculates center(centroid) of
final triangle

We use NearestBldFinder function in order to determine the closest campus building to


the central point (blue). Number of buildings was chosen to be 6 to simplify data
gathering. The distance from central point to each building is calculated first (Formula (3)).
Then, using MATLAB In-built function ‘min()’ we are able to find minimum distance from
central point. Comparing this value with distance to each building from central point, the
closest building to the center point can be found. It is also worth mentioning that
Command Window output display format was altered to ‘long’ in order to improve
calculations accuracy.

(3) √
D= {( Clon −Blon ) + ( Clat −Blat )
2 2
}

3페이지
Where D is distance between central point and particular building, C and B are
coordinates of center and building, respectively.

Figure 2.3.10 Finding nearest building to the center.

The last function in this part is RestaurantRouteReader, which has a purpose of reading
route from building to the restaurant, chosen by user before. It takes nearest building,
defined using NearestBldFinder function, and name of restaurant as input. It is
implemented using standard ‘switch’ expression. Firstly, nearest building name is checked,
and then, using restaurant name, route to this restaurant is determined (Route is being
read from prepared .txt files). Function returns ‘restaurant’ structure containing
coordinates of path to the restaurant.

Figure 2.3.11 Restaurant route reader

2.3 세부 컴포넌트 기능 (Displaying route from Dasangwan to


chosen restaurant)

4페이지
This part is devoted to plotting route from Dasangwan to the restaurant. After
clicking 안내 button on restaurant menu, map with route from Dasangwan to the
restaurant will be displayed. This is implemented using only PlotRestaurantRoute function.

Figure 2.3.1 User clicks '안내' button

Figure 2.3.2 Calling PlotRestaurantRoute function after clicking button

Figure 2.3.3 Route from Dasangwan to the restaurant

PlotRestaurantRoute begins from resetting previous axes in order to remove food image
from figure. Then, map data is loaded and map image is plotted on figure. In the next
step, RestaurantRouteReader is called to find way to the restaurant. It takes restaurant
name as an input. Final step is to plot route using MATLAB ‘plot’ function. ‘pause’ is used
as well, so line appears like “moving”.

5페이지
Figure 2.3.4 Part of PlotRestaurantRoute function

6페이지

You might also like