# Arc travel of a line in 3D space.

2 Ansichten (letzte 30 Tage)
Darren Marcelino am 22 Dez. 2022
Kommentiert: Darren Marcelino am 20 Jan. 2023
So I have a code that moves apoint in an arc throught a 3d space. I thought with my code that the line segment between the points would stay constant since the point just moves in an arc. I tested the arc travel of a line segment in a plane. the line segment would stay constant then.
How come when I try it in a 3d space the line segment length between my two points get smaller? is there a way to keep my line segment constant? am i calculating the travel of the point wrong?
for i=1:length(LowerTheta);
clf
L=9;
ax(i)=8*cosd(LowerTheta(i));
az(i)=8*sind(LowerTheta(i));
%to find beta the angle that the camber links actualyl travel
beta(i)=asind(az(i)/L);
ay(i)=L*cosd(beta(i));
a=[ax(i) ay(i) az(i)];
b=[0 0 0];
w(i)=norm(0-a);
plot3(ax(i),ay(i),az(i),'*r')
grid on
hold on
xlabel('X')
ylabel('y')
set(gca, 'YDir','reverse')
zlabel('z')
plot3(bx,by,bz,'*r')
length(i)=norm(a-b);
pause(.4)
end
Unrecognized function or variable 'LowerTheta'.
disp(length)
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Karim am 22 Dez. 2022
Hi, if I understand you correclty you want to verify the distance between two positions of the point and prefferbaly have it constant? Note that this distance will depend on the input angle (i.e. LowerTheta).
In the code below I modified your code a bit to work vectorized, I plotted the trajectory of the point and evaluate the distance between the consecutive positions.
Looking at your original code, I think the mistake is that you do not update point 'b'. You are always evaluating the length with respact to the origin (i.e. [0,0,0]).
L = 9;
% define some random angles, OP did not provide them
LowerTheta = linspace(0,2*pi,50);
% evaluate the position of the point
ax = 8*cos(LowerTheta);
az = 8*sin(LowerTheta);
ay = L*cosd(asin(az./L));
% create a figure of the trajectory of the point
figure
scatter3(ax(:),ay(:),az(:),'*r')
xlabel('X'); ylabel('Y'); zlabel('Z')
title('Point Trajectory')
grid on % merge the coordinates into a grid
a = [ax(:) ay(:) az(:)];
% now determine the distance between the consecutive points
SegLength = sqrt( sum( (a(1:end-1,:) - a(2:end,:)).^2 ,2 ))
SegLength = 49×1
1.0251 1.0251 1.0251 1.0251 1.0251 1.0251 1.0251 1.0251 1.0251 1.0251
##### 2 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Darren Marcelino am 20 Jan. 2023
I figured it out, best way for my application is to use Spherical coordiates. I had to do extra work(trig) to find azimuth and elevation, but spherical coordinated are best if your trying to keep the radius/length of a line constant.
https://www.mathworks.com/help/phased/ug/spherical-coordinates.html

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!