Clear Filters
Clear Filters

Perpendicular line to equation of motion

2 views (last 30 days)
Rose
Rose on 2 Mar 2020
Commented: Rose on 3 Mar 2020
Hi Guys,
I have this problem in which I need to find the closest point to the origin for a vector I want to extrapolate over time. The equation I'm looking at is the basic equation of motion: s=s0+v*t+1/2*a*t^2 for a object moving in time. Thus for a certain point in time, I have a location containing x,y,z coordinates, a velocity vector [vx,vy,vz],and an acceleration vector [ax,ay,az].
Then I want to extrapolate the vector over time saying that if these values remain the same. The goal of this all is to determine the smallest distance between the extrapolated path of the object and the origin (located at 0,0,0). I tried doing this with a while loop, arguing that as long as z>0 (the object is slowly going down), t=t+1 (with t in seconds). However, because the object is not moving that fast, the program take to long to run. (see attached code)
I expect this operation could be easily done with geometry and vector calculations, but I am not sure how to implent this. Any help on this?
while z_f>0
x_f(i)=x(3)+vx_n*t+1/2*ax*t^2;
y_f(i)=y(3)+vy_n*t+1/2*ay*t^2;
z_f(i)=z(3)+vz_n*t+1/2*az*t^2;
Dist(i)=sqrt(x_f(i)^2+y_f(i)^2+z_f(i)^2);
[value,idx]=min(Dist);
CPA(i)=value;
T_CPA(i)=time+idx;
i=i+1;
t=t+1;
end

Answers (1)

John D'Errico
John D'Errico on 2 Mar 2020
Edited: John D'Errico on 2 Mar 2020
Basic math will suffice. No need for anything sophisticated.
You have an initial location in space, in the form of a vector. I'll call it X. As well, you have an initial velocity vector, call it V. Finally, a constant acceleration vector. Call it A.
In each case, these are vectors of length 3, known values? Now, you want to project ahead to the future, to find the point in time when the (Euclidean) distance from the origin is the smallest?
You have observed yourself that the solution is just a simple quadratic polynomial function of time.
X(t) = X0 + V*t + A*t^2/2
Remember that X(t) is a vector valued function. Now, what value of t minimizes the distance to the origin? Actually, it is simpler (and equivalent) to minimize the square of the distance to the origin.
Since this is a forum about MATLAB, we can do the work in MATLAB. Let it do the thinking for us. I'll pick some arbitrary vectors.
X = [1 2 3];
V = [.3 .5 .2];
A = [-.1 -.1 -.1];
syms t
dist = sum((X + V*t + 1/2*A*t^2 - [0 0 0]).^2);
The squared distance will be a 4th degree polynomial in t. The minimum must arise at a root of the derivative, or at the initial time where t=0, since we do not care to extrapolate into the past.
tsol = vpa(solve(diff(dist,t) == 0))
tsol =
3.4105034014248128068919535788324
-3.6331325877833632056220131318383
10.222629186358550398730059553006
tsol(tsol < 0) = [];
subs(dist,t,[0;tsol])
ans =
14
21.448731404464740045684161633408
4.9320893860127826939956124355689
So the minimal distance for this set of initial conditions arises after a span of 10.2226... units of time. The distance realized at that time was approximately sqrt(4.932).
No loop needed. WTP?
  1 Comment
Rose
Rose on 3 Mar 2020
Hi John,
Tank you for your help, I think this is exactly what I need!
One question though, why would you use the squared euclidean distance instead of the standard euclidean distance (equal to the square root of the squared euclidean distance) to determine the minimum distance between the origin and the vector? You state that to determine the minimum we should take the square of the distance to the origin, but I do not see any squares in the equations above?

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!