Problem 2220. Wayfinding 3 - passed areas
This is the third part of a series of assignments about wayfinding. The final goal of this series is to be able to calculate the fastest route through a terrain of areas with different properties. The assignments will build on top of each other, gradually increasing the complexity, but guiding you stepwise towards the final goal. You can re-use code from preceding assignments to save some work. See [1] [2] .
Which areas are traversed?
For this third assignment in this series you have to calculate which areas are traversed and in which order, while going from A to B. Our path from A to B is a straight line. And the area boundaries are closed polygons consisting of a finite number of straight segments.
In this assignments, the areas do not overlap. If an area is crossed twice, it is listed twice in the returned vector. And if AB crosses first for example area F2, then F3, and then F2 again, the output vector should contain [ ... 2 3 2 ... ]. Simple.
The inputs of the function WayfindingPassed(AB,F) are a matrix AB of two columns, each with x-y coordinates, of our straight path from A (1st column) to B (2nd column), and a cell array F of 2-D matrices with columns with x- and y-coordinates, each column a subsequent node of the polygon boundary of the area. The last node is implicitly connected to the first. The index of each area, to be referred to in the output vector, is equal to its position in the cell array F.
AB = [ xA xB yA yB ]
F = { [ x11 x12 ... x1n ; y11 y12 ... y1n ] [ x21 x22 ... x2n ; y21 y22 ... y2n ] }
Your output v will contain the indices in F of the crossed areas, in the correct order. In the example above, the correct answer is [ 3 4 4 1 1]. Crossing means 'being present in that area', so if A, the start, is in area 3, it is considered as 'crossed'. If you pass the same area multiple times, and leave it in between, each event is listed.
Solution Stats
Problem Comments
-
4 Comments
Apparently, there was a problem with my test suite. Unfortunately, the test-suite checker in the cody problem entrance form is not working at this moment. So I found out too late.
does the test suite clear the previous data? I get troubles in my computer if I do not clear previous polygons before testing last one.
please consider breaking the testsuite into multiple tests to avoid the "clear F" issue (and to make debugging simpler)
The problem's figure is missing. We can imagine one line segment crossing several simple polygons, which can intersect on edges or vertices. The order that we must return is the order in which each polygon is entered. If the same polygon is entered twice, it must appear two times at the output.
Solution Comments
Show commentsProblem Recent Solvers13
Suggested Problems
-
6120 Solvers
-
233 Solvers
-
293 Solvers
-
37 Solvers
-
Find last zero for each column
554 Solvers
More from this Author31
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!