Problem 2219. Wayfinding 2 - traversing

This is the second part of a series of assignments about wayfinding. The final goal 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].

How many times does AB cross the boundary of area F?

For this second assignment in this series you have to calculate how many times we cross the boundary of a single area while going from A to B. Our path from A to B is a straight line. And the area boundary is a closed polygon consisting of a finite number of straight segments.

The inputs of the function WayfindingBoundaryCrossing(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 matrix F of columns with x- and y-coordinates, each column a subsequent node of the polygon boundary of the area. The last node is connected to the first.

 AB = [
   xA xB
   yA yB
 F = [
  [ x1 x2 ... xn ;
    y1 y2 ... yn ]

Your output n will be the number of times the line AB crosses the boundary of F. Note that AB may cross the boundary of F at a corner node of F.

Solution Stats

35.53% Correct | 64.47% Incorrect
Last Solution submitted on May 11, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers20

Suggested Problems

More from this Author31

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!