Bossbar progress depending on distance between player and target point [1.21.4]

For example, there are points A and B. Using a datapack, I need to make it so that as the player moves toward point B, the bossbar slowly fills up to 100. At the same time, if the player moves forward but then turns back, the progress should be reset. My knowledge is limited to very basic commands, and I have to learn a lot on the fly. I can use some workarounds to display progress when the player enters a certain area, but it's still a workaround, and not a very good one at that. If I want to make the boss bar fill smoothly and dynamically, I need to be able to work with mathematical functions and, moreover, make the game calculate the distance of the player from the current position to a given point B. I have no idea how to put all this together in a data pack, let alone how to write such a complex function.

Where do I even start? If anyone can help with this, I'd be very grateful.

Continue to help post