Graph a plane spanned by 2 vectors

35 views (last 30 days)
Christian
Christian on 7 Jun 2012
Edited: Matt J on 22 Jun 2021
I'm having trouble doing this without errors. My code generally works when it's not trying to render vertical or horizontal planes. As of now, there's a workaround that stops it from trying to graph the problem planes, but I'd like to have it work in every case.
normal = cross (v1,v2);
origin = [0 0 0];
starts = zeros(3,3);
ends = [v1;v2;origin];
realdot = @(u,v)(u * transpose(v));
syms x y z
P = [x,y,z];
planefunction = realdot(normal, P);
zplane = solve(planefunction, z);
if(isempty(zplane) == 0)
ezmesh(zplane, [xmin, xmax, ymin, ymax]), hold on
else
plane = char(planefunction);
fprintf('The two vectors create the vertical/horizontal plane %s = 0\n', plane);
end
How can I create an expression that the ezmesh function can understand for those flat planes (i.e. x=0)?
I tried using the fill3 function to create a triangular surface with vertices at the origin and each of the vector endpoints, but I could never get that to work either.
Help please.
Thanks!

Answers (2)

Teja Muppirala
Teja Muppirala on 8 Jun 2012
The way you are calliing EZMESH inteprets the input as z = f(x,y). So you can't express things like the x=0 plane.
But what you are trying to do can easily be accomplished by using EZMESH to plot a parametric surface, like the following. This code plots the plane spanned by any v1 and v2. See the help for EZMESH.
v1 = randn(3,1);
v2 = randn(3,1);
figure;
hold on;
plot3([0 v1(1)],[0 v1(2)],[0 v1(3)],'k','linewidth',6);
plot3([0 v2(1)],[0 v2(2)],[0 v2(3)],'k','linewidth',6);
ezmesh(@(s,t)v1(1)*s+v2(1)*t,@(s,t)v1(2)*s+v2(2)*t,@(s,t)v1(3)*s+v2(3)*t)

Matt J
Matt J on 22 Jun 2021
Edited: Matt J on 22 Jun 2021
You can use the planarFit class methods from this File Exchange submission.
gtPlane=planarFit.groundtruth([],normal,dot(normal,origin) );
plot(gtPlane);

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!