Does relative velocity vector lie on the line?

Hello everyone! I am new to matlab and would like some assistance. For two particles A and B with given position and constant velocity vectors, I would like to show in matlab whether their relative velocity vector (V_A - V_B) lies on the line joining them.

2 Comments

You mean to say want to plot them?
Cassy A
Cassy A on 19 Jun 2017
Edited: Cassy A on 19 Jun 2017
Nope. Just true or false would be fine. :)

Sign in to comment.

Answers (2)

define a vector between the two points and check if the cross product of the delta velocity and the connection vector is 0. so if
ra = [xa,ya,za]
rb = [xb,yb,zb]
% va and vb being the velocities
test = cross(ra-rb,va-vb)
if ~test % check if all are zero
disp('same direction')
end
EDIT: As Jan Simon pointed out, you may get precision problems, so
if all(abs(test))<eps % or any other threshold
disp('same direction')
end
Jan
Jan on 19 Jun 2017
Edited: Jan on 19 Jun 2017
Do you want to calculate the angle between the connection of the 2 points and the relative velocity? Then:
u = A - B;
v = vA - vB;
a = atan2(norm(cross(u,v)), dot(u,v));
Now check if the result a is below a certain limit. You cannot expect it to be exactly 0.0 or 180.0 due to the limited precision of the floating point values. Perhaps this is a smart limit:
limit = 10 * eps(max([A(:); B(:); vA(:); vB(:); u(:); v(:)])
isParallel = abs(a) < limit || abs(a) - 180 < limit;
But there is not "best" definition of the limit.
See https://www.mathworks.com/matlabcentral/answers/101590-how-can-i-determine-the-angle-between-two-vectors-in-matlab for a discussion, why atan2 is more accurare than acos or asin or the corresponding cross and dotr product methods only.

6 Comments

Sorry if this sounds dumb. I know I can define position vector as (2,3,4) for x,y,z coordinates respectively. But doing it for velocity vector confuses me. How do I represent a velocity vector with a certain magnitude and direction?
@Cassy A: Representing a velocity works exactly as for positions or accelerations as a vector with 3 elements for the velocities in x, y, and z direction:
A = [2,3,4]; % Position vector of A and B
B = [6,7,8];
vA = [0.1, 2, 17]; % Velocity of A and B in x,y,z direction
vB = [-12, 4, 21.2];
vA has the length: norm(vA) and the direction: vA ./ norm(vA).
The problem with the accuracy can occur e.g., if the magnitude of the velocities is 10^14 times larger then the magnitude of the relative or absolute positions.
So I've got a body-fixed frame of reference x,y,z with its origin at the position of particle A. Therefore,
A = [0, 0, 0];
Since the constant velocity vector of A is directed along x axis, for a magnitude of 3,
vA = [3, 0, 0];
Let's assume the position of particle B as
B = [18, -7.5, -20]
From B's coordinates, is it possible to get R, theta and phi (where R is the distance between the particles, theta is the azimuth angle and phi is the elevation angle)?
Finally, how do I define vB so that it too has a magnitude of 3 but is directed along some path that meets the x axis?
Let me mention, that the problem has lost the connection to Matlab now.
Of course you can get R, theta and phi:
R = norm(A - B); % or sqrt(sum((A - B) .^ 2))
theta = atan(B(2) / B(1));
phi = asin(B(3) / R);
"vB so that it too has a magnitude of 3 but is directed along some path that meets the x axis"? What is "some path that meets"? A vector with length 3 and "meets x axis" might mean:
vB = [3,0,0]
Please ask WikiPedia for the basics of trigonometrie.
I have to say that, if you created the plots in your posts using Matlab, then I am very impressed with your Matlab graphics skills (especially the second 3D one). If not, I would be curious about how you did create them.
It appears that you are dealing with a problem that, in missile guidance terms, would be referred to as 'line-of-sight' guidance. The basic idea is that if the 'line-of-sight' vector (the apparent position of B as seen by A) stays constant then the two 'particles' are on a collision course. You may want to search for 'line of sight (or 'LOS') guidance' for more information. It is actually regulating the relative velocity of one object as 'seen' by the other (LOS rate) to zero that will result in a collision course.
Jan and Julian have provided good answers that should point you in the right direction on the Matlab coding side.
Cassy A
Cassy A on 20 Jun 2017
Edited: Cassy A on 20 Jun 2017
Hey! I used a program called GeoGebra. It's fun to play with :)
Thank you for all the help though. You guys are great! :)

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 19 Jun 2017

Edited:

on 20 Jun 2017

Community Treasure Hunt

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

Start Hunting!