in reply to Positioning in relation to trend line

It strongly depends on your notion of "ok" ;-)

The last line, in the very least, gives me headaches. Do you really want to return 7 references from a subroutine and remember what they are and in which order?

I'd suggest the usage of a hash ref instead:

return { metadata => $hashref, above => { x => ..., y => ..., }, below => { x => ..., y => ..., }, on => { ... }, };

As for the mathematics involved I didn't see a flaw. But you should test it nevertheless, with small sets of selected data.