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
Problem Comments
-
2 Comments
I guess that in the case
AB = [ -4 -4 ; 6 -8 ];
F = [
-4 4 4 -4
2 2 -4 -4
];
AB do not cross the boundary
The problem's figure is missing again. We can imagine any simple polygon and a line segment.
Solution Comments
Show commentsGroup

Indexing III
- 23 Problems
- 44 Finishers
- expand intervals vol.3
- remove single elements
- return row and column indices given 2 values which define a range
- expand intervals vol.2
- compress sequence into intervals
- expand intervals
- Max Change in Consecutive Elements
- remove single elements
- Back to basics - mean of corner elements of a matrix
- Time Expansion
- Three...is a magic number.
- counting groups!
- Largest territory
- Replace pattern 0 1 0 and 1 0 1
- Find the index of n in magic(n)
- Sum of odd numbers in a matrix
- return row and column indices given 2 values which define a range
- Another colon problem
- How unique?
- Finding neighbors of [-1:1] in a matrix....
- Find the maximum two numbers of every column of a matrix
- Index one element in each vector of an array along a given dimension
- Tridiagonal
- Index of a Rational number
- Sort numbers by outside digits
Problem Recent Solvers20
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!