I am looking for an efficient way to check if an object will cut a corner to get from point A to point B or prevent the object from moving from point A to point B if there is a diagonal unwalkable position in between.
What is known:
- Every point is a square of width and height 1
- Every point has a list of its 8 adjacent points
- A point can be either walkable or nonwalkable
Here are some examples (a
is the source, b
is the desination and X
is an unwalkable point):
aX
b
In the above case, a
cannot walk to be because there is an unwalkable point adjacent to both point a
and point b
...therefore, for this current case, b
becomes unwalkable from a
(ie, a
has to move downwards before proceeding to b
)
The following is a similar case, in the sense that a
cannot walk to b
:
aX
Xb
The way I am doing it at the moment is getting the set of orthogonally adjacent points of both point A
and point B
and intersecting these two sets. If there are no elements in the intersected result, then point A
can walk to point B
.
...and it works.
But is there a, maybe, more mathematical and efficient way of achieving this?