I'm looking to create AI that elegantly rounds corners. To compute the path around a corner I have a set of 2d points start
and end
that exist exclusively as 90 degree angle pairs like in the image below.
Each point is either in the "north", "south", "east", or "west" most portion of the ellipse, and I can extrapolate the a
and b
values for the major and minor axes of the ellipse along these points.
The simulation is played on a grid, so the ellipse will never be rotated -- the major and minor axes will lie parallel to the x and y axes.
Moving the point along an ellipse by an angle is simple:
x = x + (a * math.cos(angle)) # where a is major axis
y = y + (b * math.cos(angle)) # where b is minor axis
However, I want to control the speed at which the AI traverses across the arc on the ellipse between the two points and eventually have them stop at the end
position.
Ultimately, I need to compute the following:
- The
remaining_distance
betweenstart
andend
along the ellipse - The new location of a point after moving
distance
across the ellipse
Questions:
- Are there common tools/solutions for computing the above?
- Are there better or more common solutions for this problem in AI, gamedev, or other practices? I saw Bezier curves came up in my search, for example.
Thanks!
Meta:
I found similar questions asking for this problem on the stack exchange, but none really seemed to fit my use case or answered the question by offering language-specific non-python solutions.
I chose to ask here rather than the mathematics stack exchange, because I imagine there may be other solutions for the same problem more commonplace in gamedev and other programming projects.