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 commentsProblem Recent Solvers20
Suggested Problems
-
Reverse the Words (not letters) of a String
440 Solvers
-
265 Solvers
-
282 Solvers
-
152 Solvers
-
446 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!