Inverse Bilinear Interpolation?

后端 未结 8 1526
礼貌的吻别
礼貌的吻别 2020-12-12 14:14

I have four 2d points, p0 = (x0,y0), p1 = (x1,y1), etc. that form a quadrilateral. In my case, the quad is not rectangular, but it should at least be convex.



        
8条回答
  •  甜味超标
    2020-12-12 14:41

    Some of the responses have slightly misinterpreted your question. ie. they are assuming you are given the value of an unknown interpolated function, rather than an interpolated position p(x,y) inside the quad that you want to find the (s,t) coordinates of. This is a simpler problem and there is guaranteed to be a solution that is the intersection of two straight lines through the quad.

    One of the lines will cut through the segments p0p1 and p2p3, the other will cut through p0p2 and p1p3, similar to the axis-aligned case. These lines are uniquely defined by the position of p(x,y), and will obviously intersect at this point.

    Considering just the line that cuts through p0p1 and p2p3, we can imagine a family of such lines, for each different s-value we choose, each cutting the quad at a different width. If we fix an s-value, we can find the two endpoints by setting t=0 and t=1.

    So first assume the line has the form: y = a0*x + b0

    Then we know two endpoints of this line, if we fix a given s value. They are:

    (1-s)p0 + (s)p1

    (1-s)p2 + (s)p3

    Given these two end points, we can determine the family of lines by plugging them into the equation for the line, and solving for a0 and b0 as functions of s. Setting an s-value gives the formula for a specific line. All we need now is to figure out which line in this family hits our point p(x,y). Simply plugging the coordinates of p(x,y) into our line formula, we can then solve for the target value of s.

    The corresponding approach can be done to find t as well.

提交回复
热议问题