3D plotting, Vector Length error
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Cedrick Levesque-Baker
am 31 Jan. 2016
Kommentiert: Star Strider
am 31 Jan. 2016
Hi,
I am trying to draw a 3d shape, using equations. To do so, I use logical indexing.
I am able to do it in 2D, but not in 3d, I always get the vector length error and I do not understand why. All I am trying to do is to try a straight line from at y=0 from z=-r to z=r. If I can figure out the vector error, I will be able to move on and make more complicated things.
Thanks for your help.
clear all;
clc;
%TJoint Winding w/o radius
%The idea is to experiment with matlab
%Obtains the values
D = 'What is the diameter of the t joint? ';
D = input(D);
l1 = 'What is the length 1 of the t joint? ';
l1 = input(l1);
l2 = 'What is the length 2 of the t joint? ';
l2 = input(l2);
'Thank you, we are now processing the Filament winding of your T-Joint. Please wait ';
%Defining Graph size
x = -D/2:((D/2)+l2);
y = -l1/2 :l1/2;
z = -D/2: D/2;
%Variable Definition
r = D/2;
%Winding step one
x(z >= -r, z <= r ) = r+l2;
y(z >= -r, z <= r )= 0 ;
plot3(x,y,z);
%Axis Labeling
xlabel('X Axis','FontSize',14);
ylabel('Y Axis','FontSize',14);
zlabel('Z Axis','FontSize',14);
title('Tjoint winding w/o radii','FontSize',14);
0 Kommentare
Akzeptierte Antwort
Star Strider
am 31 Jan. 2016
You need to do the same to z as you did to x and y:
x(z >= -r, z <= r ) = r+l2;
y(z >= -r, z <= r )= 0 ;
z(z >= -r, z <= r ) = ???;
The same conditions have to apply to all vectors for them to be of equivalent length, and for that matter, for them to have corresponding values at each point. I’m not sure what you want z to be, so I will leave that to you to define.
2 Kommentare
Star Strider
am 31 Jan. 2016
My pleasure.
That is actually much easier.
See if this does what you want:
D = 15; % Create Data
l2 = 2; % Create Data
r = D/2;
x = [r+l2 r+l2];
y = [0 0];
z = [-r +r];
figure(1)
plot3(x, y, z)
grid on
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!