How to calculate proximity of corners to a point in a square

72 Views Asked by At

Forgive me in advance for not necessarily knowing how to ask this question: I would like to calculate the proximity to each of the four corners of a square given an arbitrary (single) input point P, but expressed as value between 0-1, so if the point P (x, y) was located at C for example, C's output value would be '1' and if it was located at A, C's value would be '0'. There should be a mix between the corners.

What are the necessary steps to achieve this? The context is that I'm building an application whereby the user inputs a location (the point) and I would like the outputs to be normalized as a list of values [0, 1, 0, 0] for example, representing [vA, vB, vC, vD] with B as the corner point. In this case coordinate P would be [-1, 1]. If the point is [0,0] the output would be [0.5, 0.5, 0.5, 0.5].

enter image description here

1

There are 1 best solutions below

1
On

I'd calculate the distance between P and a corner point, then divide this by the maximum possible length across the square (2$\sqrt{2}$) to get a percentage or decimal number, then subtract that from 100% for it to be an inverse of the distance.