Linear interpolation of three 3D points in 3D space

后端 未结 4 1945
一整个雨季
一整个雨季 2021-01-07 04:00

I have three 3D points like p1(x1,y1,z1), p2(x2,y2,z2), p3(x3,y3,z3). I have another point, but I know only x, y

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-07 04:13

    This is to support both MBo's and Konstantin's answers. Please don't accept this question, but one of the others.

    This is how you would implement a solution in MATLAB:

    %// Your known 3 points
    p1 = [ 1 10  0]';
    p2 = [-1 10 10]';
    p3 = [ 0  0 10]';
    
    %// your 4th target point
    p4 = [0 5  NaN]';
    
    %// Difference matrix/vector
    A = [p2-p1  p3-p1];
    b = p4-p1;
    
    %// Compute solution
    p4(end) = p1(end) + A(3,:)*(A(1:2,:)\b(1:2));
    

    Now, in C++, the mere fact of including the relevant eigen libraries blows up the executable size rather spectacularly. What eigen is capable of is complete overkill for this simple 2x2 system.

    So I wouldn't go as far as resort to eigen, unless you have tons of other linear algebra things to do. It is a simple 2x2 system, which is easy enough to solve by hand.

    Just KISS it; see DanielKO's answer :)

提交回复
热议问题