How can I plot a 3D-plane in Matlab?

前端 未结 4 1891
你的背包
你的背包 2020-12-01 09:41

I would like to plot a plane using a vector that I calculated from 3 points where:

pointA = [0,0,0];
pointB = [-10,-20,10];
pointC = [10,20,10];

plane1 = cr         


        
4条回答
  •  悲&欢浪女
    2020-12-01 09:54

    I want to add to the answer given by Andrey Rubshtein, his code works perfectly well except at B=0. Here is the edited version of his code

    Below Code works when A is not 0

    normal = cross(pointA-pointB, pointA-pointC); 
    x = [pointA(1) pointB(1) pointC(1)];  
    y = [pointA(2) pointB(2) pointC(2)];
    z = [pointA(3) pointB(3) pointC(3)];  
    A = normal(1); B = normal(2); C = normal(3);
    D = -dot(normal,pointA);
    zLim = [min(z) max(z)];
    yLim = [min(y) max(y)];
    [Y,Z] = meshgrid(yLim,zLim);
    X = (C * Z + B * Y + D)/ (-A);
    reOrder = [1 2  4 3];
    figure();patch(X(reOrder),Y(reOrder),Z(reOrder),'r');
    grid on;
    alpha(0.3);
    

    Below Code works when C is not 0

    normal = cross(pointA-pointB, pointA-pointC); 
    x = [pointA(1) pointB(1) pointC(1)];  
    y = [pointA(2) pointB(2) pointC(2)];
    z = [pointA(3) pointB(3) pointC(3)];  
    A = normal(1); B = normal(2); C = normal(3);
    D = -dot(normal,pointA);
    xLim = [min(x) max(x)];
    yLim = [min(y) max(y)];
    [Y,X] = meshgrid(yLim,xLim);
    Z = (A * X + B * Y + D)/ (-C);
    reOrder = [1 2  4 3];
    figure();patch(X(reOrder),Y(reOrder),Z(reOrder),'r');
    grid on;
    alpha(0.3);
    

提交回复
热议问题