Best method for curved surfaces

So I have a ground that’s supposed to be, for the most part, curved.
How can I find the utmost y point of the ground at a given x?

The ground looks like so:

The function I have right now sort-of works, but seems
very inefficient. You input an x parameter, and the function loops
using hitTestPoint with a constant x and a y that increases until
it hits the ground. Then it returns that y value.

Is there a better way to do this?
This method seems like it would get slow.
Any help is appreciated. :slight_smile: