I'm working on a project that generates a series of quadratic bezier curves and connects them together, maintaining slope from the end of one segment to the beginning of the next to make the transition smooth. The problem is that while the path is smooth, it tends to go off screen frequently.
The way this is done currently:
P0 = new Point(0, gapStart);
P2 = new Point(wallWidth, gapEnd);
P1 = getAnchorPoint();
where:
GapStart is the P2.y of the previous curve
wallWidth is a constant
gapEnd is the one and only random aspect of the cave generation It's the Y value that the curve will end at.
The getAnchorPoint function takes points 0 and 2 and generates an anchor point so that the slope at the beginning of this segment is the same as the end of the previous segment.
So the main question is, what values can gapEnd be to ensure that the next curve has a gapEnd that won't send the curve off the screen?
In other words, how do I determine the min and max values of gapEnd so that the next curve is safe?
In addition, it's important that these values don't box the following curve in to being impossible: i.e. they cannot allow for the next curve to not have a possible solution that would allow for continued curve generation.