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

前端 未结 4 1879
你的背包
你的背包 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 10:02

    Here's what I came up with:

    function [x, y, z] = plane_surf(normal, dist, size)
    
    normal = normal / norm(normal);
    center = normal * dist;
    
    tangents = null(normal') * size;
    
    res(1,1,:) = center + tangents * [-1;-1]; 
    res(1,2,:) = center + tangents * [-1;1]; 
    res(2,2,:) = center + tangents * [1;1]; 
    res(2,1,:) = center + tangents * [1;-1];
    
    x = squeeze(res(:,:,1));
    y = squeeze(res(:,:,2));
    z = squeeze(res(:,:,3));
    
    end
    

    Which you would use as:

    normal = cross(pointA-pointB, pointA-pointC);
    dist = dot(normal, pointA)
    
    [x, y, z] = plane_surf(normal, dist, 30);
    surf(x, y, z);
    

    Which plots a square of side length 60 on the plane in question

提交回复
热议问题