Arc travel of a line in 3D space.

2 visualizaciones (últimos 30 días)
Darren Marcelino
Darren Marcelino el 22 de Dic. de 2022
Comentada: Darren Marcelino el 20 de En. de 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)

Respuesta aceptada

Karim
Karim el 22 de Dic. de 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 comentarios
Darren Marcelino
Darren Marcelino el 22 de Dic. de 2022
Editada: Darren Marcelino el 22 de Dic. de 2022
I think my question is closer to this.
clc
close all
clear all
LowerTheta= 22:-2:-14;
figure;
for i=1:length(LowerTheta)
clf
%origin point is the origin
p0x=0;
p0y=0;
p0z=0;
p0=[p0x p0y p0z];
%% red point
p1x=17;
p1y=p0y;
p1z=p0z;
p1=[p1x p1y p1z];
plot3(p1x,p1y,p1z,'*r')
grid on
hold on
xlabel('X')
ylabel('y')
set(gca, 'YDir','reverse')
set(gca, 'XDir','reverse')
zlabel('z')
axis([-10 30 -5 25 -20 30]) ;%[ x y z]
%% cyan point
p2x=p0x;
p2y=9;
p2z= p0z;
p2=[p2x p2y p2z];
plot3(p2x,p2y,p2z,'*g')
% green point
p3x=p2x;
p3y=p2y;
p3z=p2z;
p3=[p3x p3y p3z];
plot3(p3x,p3y,p3z,'*g')
p4y(i)=17*cosd(LowerTheta(i));
p4z(i)=17*sind(LowerTheta(i));
p4x(i)= 17*cosd(LowerTheta(i));
p4=[p4x(i) p4y(i) p4z(i)];
ww(i)=norm(p4-p2);
Lowerx=[p1x,p4x(i)];
Lowery=[p1y,p4y(i)];
Lowerz=[p1y,p4z(i)];
plot3(Lowerx,Lowery,Lowerz,'b')
plot3(p4x(i),p4y(i),p4z(i),'*c')
alpha1=asind(17/20);
alpha=180-90-alpha1;
TAx=20*cos(alpha);
p7x(i)=p4x(i);
p7z(i)=p4z(i);
beta(i)=asind(p7z(i)/17);
p7y(i)=17*cosd(beta(i));
p7=[p7x(i) p7y(i) p7z(i)];
w(i)=norm(p2-p7);
plot3(p7x(i),p7y(i),p7z(i),'*c')% same point as p4
Lowerx2=[p2x,p7x(i)];
Lowery2=[p2y,p7y(i)];
Lowerz2=[p2z,p7z(i)];
plot3(Lowerx2,Lowery2,Lowerz2,'b')
w(i)=norm(p4-p3)% length line 1
v(i)=norm(p4-p1)%length line 2
pause(.1)
end
w = 18.2955
v = 17.0450
w = 1×2
18.2955 18.3752
v = 1×2
17.0450 17.0309
w = 1×3
18.2955 18.3752 18.4494
v = 1×3
17.0450 17.0309 17.0203
w = 1×4
18.2955 18.3752 18.4494 18.5175
v = 1×4
17.0450 17.0309 17.0203 17.0128
w = 1×5
18.2955 18.3752 18.4494 18.5175 18.5789
v = 1×5
17.0450 17.0309 17.0203 17.0128 17.0075
w = 1×6
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331
v = 1×6
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041
w = 1×7
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798
v = 1×7
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020
w = 1×8
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184
v = 1×8
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008
w = 1×9
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488
v = 1×9
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003
w = 1×10
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707
v = 1×10
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001
w = 1×11
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707 18.7839
v = 1×11
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001 17.0000
w = 1×12
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707 18.7839 18.7883
v = 1×12
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001 17.0000 17.0000
w = 1×13
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707 18.7839 18.7883 18.7839
v = 1×13
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001 17.0000 17.0000 17.0000
w = 1×14
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707 18.7839 18.7883 18.7839 18.7707
v = 1×14
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001 17.0000 17.0000 17.0000 17.0001
w = 1×15
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707 18.7839 18.7883 18.7839 18.7707 18.7488
v = 1×15
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001 17.0000 17.0000 17.0000 17.0001 17.0003
w = 1×16
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707 18.7839 18.7883 18.7839 18.7707 18.7488 18.7184
v = 1×16
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001 17.0000 17.0000 17.0000 17.0001 17.0003 17.0008
w = 1×17
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707 18.7839 18.7883 18.7839 18.7707 18.7488 18.7184 18.6798
v = 1×17
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001 17.0000 17.0000 17.0000 17.0001 17.0003 17.0008 17.0020
w = 1×18
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707 18.7839 18.7883 18.7839 18.7707 18.7488 18.7184 18.6798 18.6331
v = 1×18
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001 17.0000 17.0000 17.0000 17.0001 17.0003 17.0008 17.0020 17.0041
w = 1×19
18.2955 18.3752 18.4494 18.5175 18.5789 18.6331 18.6798 18.7184 18.7488 18.7707 18.7839 18.7883 18.7839 18.7707 18.7488 18.7184 18.6798 18.6331 18.5789
v = 1×19
17.0450 17.0309 17.0203 17.0128 17.0075 17.0041 17.0020 17.0008 17.0003 17.0001 17.0000 17.0000 17.0000 17.0001 17.0003 17.0008 17.0020 17.0041 17.0075
I want line segments 1 and 2 to stay constant thorught the travel. is it better to use spherical coordinates here and I define my own phi and theta? i again when I write the code so it is in 2d, my line segments do not chagne, but the moment "z direction" is added, my line segments start changing lengths.
Darren Marcelino
Darren Marcelino el 20 de En. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by