In the previous post, I have mentioned the problem that arises with the implementation of the Bezier curve – it can go outside of the shape. This time I have tried to fix this flaw.
Before starting to write any code, I did some research on the Collision Detection. Turns out it is a tricky part. I found out that up to this day, there is no such algorithm that could detect collision for all the shapes including the concave ones. For the beggining, I could assume that all the shapes are convex but later on this will have to be fixed too.
As for the collision detection algorithm, I have decided to go with dyn4j – Java Collision Detection and Physics Engine library which already has collision detection algorithms. One of them is SAT which stands for Separating Axis Theorem. It states that if we can find a gap or separation between two objects then they must not be touching.
The way that I have decided to approach this task was to create a convex shape out of spawn points and check for every point of the line whether it is not colliding with the shape. It if is, that Bezier curve should be re-generated.
Here is the result of SAT implementation:




This raised another issue for the futher development of the project. I will need to find a way to transform any set of vertices into convex shapes as the SAT algorithm does not support concave shapes. Because the first piece is concave, for now, I will leave it as it is.