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
3192 Solvers
757 Solvers
282 Solvers
distance to a straight line (2D) given any 2 distinct points on this straight line
32 Solvers
Integer sequence - 2 : Kolakoski sequence
89 Solvers