Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 2220. Wayfinding 3 - passed areas

Created by J-G van der Toorn

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.

Problem Group

Solution Statistics

2 correct solutions 8 incorrect solutions
Last solution submitted on Sep 30, 2014

Problem Comments