3D plotting, Vector Length error

조회 수: 8 (최근 30일)
Cedrick Levesque-Baker
Cedrick Levesque-Baker 2016년 1월 31일
댓글: Star Strider 2016년 1월 31일
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);

채택된 답변

Star Strider
Star Strider 2016년 1월 31일
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
Cedrick Levesque-Baker
Cedrick Levesque-Baker 2016년 1월 31일
Hi!
thanks for the fast reply, however I am not sure what I should write instead of the "???".
All I am trying to do is to draw a straight line from (r+l2; 0 ; -r) to (r+l2; 0 ; r)
What would you write? Also I cannot simply joint the 2 coordinates together, it has to be an equation.
thanks again
Star Strider
Star Strider 2016년 1월 31일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by