3d plot with x value being constant

im trying to plot a point on a 3d plot but i keep coming up with the error
Error using plot3
Vectors must be the same length.
Error in threed_suspension (line 50)
plot3(Lowerx,Lowery,Lowerz,'b')
I dont know how to keep p5x constant while p5y and p5z a changing variable.
p5y(i)= RL*cosd(LowerTheta(i));
p5z(i)=RL*sind(LowerTheta(i)); %parallel
z=size(LowerTheta);
p5x= p1x*z;
Lowerx=[p1x,p5x];
Lowery=[p1y,p5y(i)];
Lowerz=[p1y,p5z(i)];
plot3(Lowerx,Lowery,Lowerz,'b')
plot3(p5x,p5y,p5z,'*r')

 采纳的回答

p5x= p1x*ones(z);

4 个评论

im still getting the same error.
here is my entire code:
%% 3d plot
clc
close all
clear all
RL=12;
LowerTheta= 22:-2:-14;
for i=1:length(LowerTheta)
%p1 Lower back mounting point
p1x=0;
p1y=0;
p1z=0;
plot3(p1x,p1y,p1z,'*r')
grid on
hold on
xlabel('x')
ylabel('y')
set(gca, 'YDir','reverse')
zlabel('z')
%p2 upper back mounting point
p2x= p1x;
p2y= p1y;
p2z= 5;%vertical distance in inches
plot3(p2x,p2y,p2z,'*r')
%p3 lower front mounting point
p3x=10;%horizontal distance between lower mounts
p3y=p1y;
p3z= p1z;
plot3(p3x,p3y,p3z,'*r')
%p4 upper front mounting point
p4x=p3x;%dist between upper mounts
p4y=p2y;%
p4z=p2z;%height
plot3(p4x,p4y,p4z,'*r')
%p5 lower arm member
p5y(i)= RL*cosd(LowerTheta(i));
p5z(i)=RL*sind(LowerTheta(i)); %parallel
z=size(LowerTheta);
p5x= p1x*ones(z);
Lowerx=[p1x,p5x];
Lowery=[p1y,p5y(i)];
Lowerz=[p1y,p5z(i)];
plot3(Lowerx,Lowery,Lowerz,'b')
plot3(p5x,p5y,p5z,'*r')
%p6 upper arm member
p6x= p2x;
p6y(i)= RL*cosd(LowerTheta(i));
p6z(i)=RL*sind(LowerTheta(i)); %parallel
plot3(p5x,p5y,p5z,'*r')
end
so ive got it to plot the length i want, but now im having trouble making go through each itteration.
%% 3d plot
clc
close all
clear all
RL=12;
LowerTheta= 22:-2:-14;
for i=1:length(LowerTheta)
clf
%p1 Lower back mounting point
p1x=0;
p1y=0;
p1z=0;
plot3(p1x,p1y,p1z,'*r')
grid on
hold on
xlabel('x')
ylabel('y')
set(gca, 'YDir','reverse')
zlabel('z')
%p2 upper back mounting point
p2x= p1x;
p2y= p1y;
p2z= 5;%vertical distance in inches
plot3(p2x,p2y,p2z,'*r')
%p3 lower front mounting point
p3x=10;%horizontal distance between lower mounts
p3y=p1y;
p3z= p1z;
plot3(p3x,p3y,p3z,'*r')
%p4 upper front mounting point
p4x=p3x;%dist between upper mounts
p4y=p2y;%
p4z=p2z;%height
plot3(p4x,p4y,p4z,'*r')
%p5 lower arm member
p5y(i)= RL*cosd(LowerTheta(i));
p5z(i)=RL*sind(LowerTheta(i)); %parallel
z=size(LowerTheta);
p5x= repmat(p1x,1,length(p5y));
Lowerx=[p1x,p5x(i)];
Lowery=[p1y,p5y(i)];
Lowerz=[p1y,p5z(i)];
plot3(Lowerx,Lowery,Lowerz,'b')
plot3(p5x,p5y,p5z,'*r')
%p6 upper arm member
p6x= p2x;
p6y(i)= RL*cosd(LowerTheta(i));
p6z(i)=RL*sind(LowerTheta(i)); %parallel
plot3(p5x,p5y,p5z,'*r')
end
Did you try this?
%p5 lower arm member
p5y(i)= RL*cosd(LowerTheta(i));
p5z(i)=RL*sind(LowerTheta(i)); %parallel
p5x(i) = p1x;
Lowerx=[p1x,p5x(i)];
Lowery=[p1y,p5y(i)];
Lowerz=[p1y,p5z(i)];
I'm not really sure what you want to do, but if you need p5x to be constant, just assign it value just like on y and z component.
I ended up figuring that spherical coordinates are easier to manipulate and keep stuff constant. i rewrote my code using spherical coordinates. i found it easier. i had to do extra trig to figure out angles but i found that if you are trying to keep a length constant, one end of it is pinned. (360 freedom of movement) , and the other end is moving in the 3d space, spehrical coordinates are best to use.
https://www.mathworks.com/help/phased/ug/spherical-coordinates.html

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by