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.
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
Project Euler: Problem 6, Natural numbers, squares and sums.
762 Solvers
Get the length of a given vector
1210 Solvers
Compute a dot product of two vectors x and y
639 Solvers
Getting the row and column location from a matrix
189 Solvers
397 Solvers