フィルターのクリア

Plot a changing angle over time

10 ビュー (過去 30 日間)
MarshMellow
MarshMellow 2019 年 9 月 8 日
コメント済み: MarshMellow 2019 年 9 月 9 日
Need help regarding the changing angle between 2 vectors of a moving object over time. The 2 vectors are namely the direction vector and the vector referencing to the origin. I am stuck here as i dont know how to proceed to plot the cos_theta over time. Also, i keep getting the dimension mismatch for my cos_theta. Kindly appreciate any help thanks!!
x_i=input('Enter the initial x location of the object: ');
y_i=input('Enter the initial y location of the object: ');
z_i=input('Enter the initial z location of the object: ');
x_f=input('Enter the final x location of the object: ');
y_f=input('Enter the final y location of the object: ');
z_f=input('Enter the final z location of the object: ');
Vel=input('Enter velocity of moving object: ');
N=input('points: ');
initial=[x_i;y_i;z_i];
final=[x_f;y_f;z_f];
direction=final-initial; %Direction vector
coord=[linspace(x_i,x_f,N);linspace(y_i,y_f,N);linspace(z_i,z_f,N)];
dist=sqrt((x_f-x_i).^2+(y_f-y_i).^2+(z_f-z_i).^2); %Distance between final and initial pos
Total_time=dist./Vel; %Total time required to travel
%STUCK FROM HERE ONWARDS
n=linspace(1,N,N);
t=linspace(0,Total_time,N);
cos_theta = dot(direction,coord(:,n))/(norm(direction)*norm(coord(:,n)));
plot(t, cos_theta);
  2 件のコメント
darova
darova 2019 年 9 月 8 日
Is that we talking about?
11Untitled.png
MarshMellow
MarshMellow 2019 年 9 月 9 日
Something like this but im looking for the angle between the red line (direction vector between 2 points) and one of the vector pointing towards the origin.

サインインしてコメントする。

採用された回答

David Hill
David Hill 2019 年 9 月 8 日
function angleOtime(initial,final,vel,n)
direction=final-initial;
dist=norm(direction);
velocity=(direction/dist).*vel;
t=linspace(0,dist/vel,n);
cos_theta = arrayfun(@(x)dot(direction,x*velocity+initial)/(norm(direction)*norm(x*velocity+initial)),t);
plot(t, cos_theta);
end
If I understood you correctly, the above function should work for you. Just input the initial point [xi,yi,zi], final point [xf,yf,zf], vel, and number of interval desired.
  1 件のコメント
MarshMellow
MarshMellow 2019 年 9 月 9 日
Thanks a lot! This is exactly what Im looking for! Im still a beginner at matlab and will study the function you provided!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by