Straight forward discrete trajectory toward a position in 2D, 3D, N-D

1 回表示 (過去 30 日間)
Gabe Hopper
Gabe Hopper 2017 年 11 月 9 日
編集済み: Gabe Hopper 2017 年 11 月 9 日
Dear all,
I'm trying to compute the trajectory of an object moving into a direction from a starting position 'pos' to a location 'loc'. This object is moving in a straight line. I am able to solve this in 2-D using sin and cos and multiple advices already posted here:
%Compute angular value in [0,2pi]:
alpha = atan2(loc(2) - pos(2), loc(1) - pos(1));
if(alpha < 0) alpha = alpha + 2 * pi; end
%Compute a step in the direction, with distance 'd':
pos(1) = pos(1) + d * cos(alpha);
pos(2) = pos(2) + d * sin(alpha);
However, in 3-D, i'm running in more trouble, I assume I should be using two angles and perform the step, ie:
%Get angular value in [0, 2pi]
alpha(1) = atan2(loc(2) - pos(2), loc(1) - pos(1));
alpha(2) = atan2(loc(3) - pos(3), loc(1) - pos(1));
if(any(alpha < 0)) %stay in [0, 2*pi]
alpha(alpha < 0) = alpha(alpha < 0) + 2 * pi;
end
%Compute trajectory
pos(1) = pos(1) + d * cos(alpha(1)) * cos(alpha(2));
pos(2) = pos(2) + d * sin(alpha(1)) * cos(alpha(2));
pos(3) = pos(3) + d * sin(alpha(2));
However, it doesn't work and I cannot figure out why? I assume there is something wrong with the angular values. I am also very interested in generalizing in N-D (N > 3) with a focus on both precision and efficiency.
Thank you

回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by