# Generate trajectories with same tangent in a specific point

13 views (last 30 days)
chef13 on 28 Feb 2017
Commented: John D'Errico on 28 Feb 2017
Hi,
I want to simulate the movements of 3 robots/agents in space and I would like to generate 3 different trajectories which have one constraint: in a certain time T the all the trajectories must have the same tangent.
I want something like in the following picture: Thanks a lot.

John D'Errico on 28 Feb 2017
Edited: John D'Errico on 28 Feb 2017
I'm not going to do your homework, as this probably is a piece of your student project.
But if your goal is simply to generate three random trajectories with the desired property, then it is trivial to do.
1. Generate three completely random trajectories.
2. Compute the desired tangent at time t for each trajectory.
3. Rotate trajectories 2 and 3 in the plane so the tangent lines line up with tangent 1.
Done.
Will the result be a completely "uniform" sampling of all possible trajectories, subject to the constraint? By the word uniform, I mean that of all possible trajectories that fit your constraint, they will not all be equally likely.
So the set I've shown you how to generate will not be truly uniform. But then you did not ask for that, and this solution will not be a poor one at all in terms of sampling, nor difficult to do.
A truly uniformly sampled set of trajectories would be fairly difficult to generate. If you insisted on that, I'd suggest that you might start from time t, and then work forwards and backwards. To rigorously ensure uniformity in probability even then would be quite difficult, and I'd suggest not worth the extra effort.

chef13 on 28 Feb 2017
Hi thanks a lot for your answer and not it is not part of a student project but of my PhD research. And I didn't want you to do everything for me of course, I just wanted to be pointed in the right direction. I know how to generate a random (smooth) trajectory but the problem was the tangent constraint.
So what I did is to fit a polynomial to some points and constraining the derivative of the polynomial in a certain point to be equal to 0.
It is pretty easy, but it saved me some work.
And, if you try the following:
% point you want your functions to pass
p1 = [1 1];
p2 = [1 3];
% First function
x1 = linspace(0,4);
y1 = linspace(0,4);
p = polyfix(x1,y1,degreePoly,p1(1),p1(2),,);
% p = [-0.0767 0.8290 -1.4277 1.6755];
figure
plot(x1,polyval(p,x1))
xlim([0 3])
ylim([0 3])
grid on
hold on
% Second function
x2 = linspace(0,4);
y2 = linspace(0,4);
p = polyfix(x2,y2,degreePoly,,,,)
% p = [0.4984 -2.7132 3.9312 1.2836];
plot(x2,polyval(p,x2))
xlim([0 3])
ylim([0 3])
grid on
If you don't have the polyfix function and you don't want to download it you can try the same code commenting the polyfix lines:
p = polyfix(x1,y1,degreePoly,p1(1),p1(2),,);
p = polyfix(x2,y2,degreePoly,p2(1),p2(1),,);
And uncommenting the lines:
% p = [-0.0767 0.8290 -1.4277 1.6755];
% p = [0.4984 -2.7132 3.9312 1.2836];
You will get this: Now I will use this polynomial as a position (x,y) over time of my robots and I think I should be done. The x of the polynomial will be also the time, in this way I am sure that the robots will arrive in the 0-derivative point at the same time.
What do you think? Does it make sense? Thanks again.
John D'Errico on 28 Feb 2017
No. I don't use polyfix. (Why should I? It can be done in one line of code using lsqlin. And my own spline tools have more capability.)
Next, you never said you wanted a zero slope, just that the tangents needed to be the same.
"all the trajectories must have the same tangent."
Which is it? Zero slope, or parallel curves?
Do I like what you did? Not really, because I don't really like polynomial fits, even though I provided polyfitn on the FEX. :)
You are essentially restricting the set of trajectories to the set of polynomials in the plane that have a zero slope at that point. I talked about the problem with uniformity but this is not a uniform sampling of curves.
Hey, I'm not being any easier on you than I would were I on your thesis committee, and I expect they should be as demanding.
So my questions are
1. What is a clear definition of a "trajectory"? Should it be possible for a trajectory to cross itself? Could a closed curve such as a circle qualify as a trajectory?
2. Do you really want the slope to be zero at some fixed point?