This is a rephrased question after I gained a better understanding of the problem.
I have an X,Y plane with one point in each quadrant. Each point represents a value, it is a function result for which (x,y) is input. I want to calculate the outcome for a particular point within the quadrilateral based on the known values of the quadrilateral's corners.
I learned (after being pointed in the right direction) there is a method for doing this on squares (with only horizontal and vertical sides) called bilinear interpolation. Great. I can just about grasp this and I think I would be able to map this into computer code.
I also learned there is a way to do this for arbitrary quadrilaterals by first mapping the quadrilateral to a square. This method, as described here however is over my head. I do not have the mathematic base to follow it and convert it to computer code.
I also learned about the existence of a mathematical code library for Microsoft .NET named Math.NET Numerics which looked promising. It has support for interpolation but unfortunately I could not find anything that seemed to match my problem.
I feel I have most of the parts of the puzzle yet I did not manage to put it all together. My goal is a formula I can enter 4 coordinates into with their values, the coordinates of my unknown value, and get a result value. I do not mind having to perform multiple steps to achieve this, it just gets hard when I encounter vector notation that I do not know how to map to code using straight +-*/ arithmetic.
This turned into some serious rubber-ducking. I found a way that works for me here:
It is about triangles but it works just the same for quadrilaterals.
I had this idea before but could not convert it into a calculation. The idea is that the closer a neighboring point is, the more "weight" it should contribute to the outcome of the requested point value. Weight is the reciprocal value of the distance to the requested point.
So, for points p1, p2, p3 and p4 in Q1, Q2, Q3 and Q4 respectively, we have d1, d2, d3 and d4 for the distances of these points to the origin. Then the weights for the four reference points are w1=1/d1, w2=1/d2, w3=1/d3 and w4=1/d4. Let's call the values of the reference points v1, v2, v3 and v4. The calculated value of any point p within the bounds of the quadrilateral is:
(v1 * w1 + v2 * w2 + v3 * w3 + v4 * w4) / (w1 + w2 + w3 + w4)
This produces pretty nice continuous results, which can be visualized by filling a plane with grey dots (all RGB color components are set to the point value and we make sure that we assign values to reference points ranging from 0 to 255, 0 being black and 255 being white).
An example with these reference values (x, y, v)
results in this image (which ranges from -100 to +100 in both the x and y directions):
And we can see this works. p1 is black, the others are white. Anything in between nicely expresses the pull strength of all points. The middle is relatively pale because we have 3 points pulling towards white and only one pulling towards black.
This example is for a square to make it easily verifiable with the eye but it isn't more difficult for any other shape or even number of reference points.
If we recreate the image for this larger quadrilateral:
we get an image that looks to be just one grey color because the image is only a small part of the quadrilateral and values do not vary that much withing that area:
But if we flood-fill the image with some random colors we can see the attracting reference points at work again:
I am satisfied with this result. The purpose is not to be exact but to produce setpoints for an actuator based on a limited number of calibration measurements. It will be verified whether the predicted values are close enough to the real values by doing some more measurements. Then it is to be determined how many reference points are needed to calibrate the device sufficiently (the more reference points, the more accurate but we do not want to waste time on calibration by being more accurate than necessary).