Clear Filters
Clear Filters

Add surface based on two vectors in 3D plot

2 views (last 30 days)
In the code below, my aim is to mark the span spanned by the vectors x1 and x2. So I need to add a 2D surface in the 3D plot indicting this span which needs to visually contain the two vectors - so that I can give a sense of what a span is to the students. I tried this with the mesh function but apparently something is wrong. Is my approach wrong? How can I draw this surface?
t = [0 0 0]';
x1 = [1 2 1]';
x2 = [3 1 1]';
y = [3 3 4]';
X = [x1 x2];
B_hat = inv(X'*X)*X'*y;
plot3([t(1) x1(1)],[t(2) x1(2)],[t(3) x1(3)])
hold on
plot3([t(1) x2(1)],[t(2) x2(2)],[t(3) x2(3)])
axis([-1 5 -1 5 -1 5])
grid on
hold on
x1_fit = min(x1):1:max(x1);
x2_fit = min(x2):1:max(x2);
[x1_FIT,x2_FIT] = meshgrid(x1_fit,x2_fit);
y_FIT = B_hat(1)*x1_FIT + B_hat(2)*x2_FIT;
mesh(x1_FIT,x2_FIT,y_FIT)

Accepted Answer

jonas
jonas on 6 Oct 2018
Edited: jonas on 6 Oct 2018
It's not trivial to make a triangular surface from three points in space, at least not from the mesh function. I would probably just use a patch.
patch('xdata',[t(1) x1(1) x2(1)],'ydata',[t(2) x1(2) x2(2)],'zdata',[t(3) x1(3) x2(3)])

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!