MATLAB Answers

Create random paths between two known points in 3D

20 views (last 30 days)
Mauro Tramis
Mauro Tramis on 21 Mar 2020
Commented: Image Analyst on 22 Mar 2020
I'm trying to create a series of random paths between two known points and represent them on a 3d plot.
The goal is to start from a point with known coordinates and create different paths, randomly, in order to reach another point with known coordinates; after the creation of this random paths I need to represent them in a 3d plot using only one figure, in order to compare trajectories. I already found different solutions for the 2D case, but for converting them to 3D I'm stuck. Can anyone help me?
Thanks in advance

  4 Comments

Show 1 older comment
Image Analyst
Image Analyst on 22 Mar 2020
I still don't see how our solutions below do not apply to your new description. My code does create a path that is not straight and does not overlap. And it allows you to specify a starting and ending point. So I don't know what else to do, unless you want some prescribed shape like a perfect parabola or a sine wave or whatever.
To represent several plots in the same figure, you can use subplot() and plot3().
Mauro Tramis
Mauro Tramis on 22 Mar 2020
Your response was for a 2D case, not a 3D. I am not dealing with signals and noises, my goal is to obtain a trajectory between two known points (known coordinates) and the plots should be like they represent a motion (like in the picture below). The purpose to use different initial points is to observe the behaviour of all different trajectories
Image Analyst
Image Analyst on 22 Mar 2020
My response was a demo for one signal, like x. You'd then apply that concept to y and z also to get all 3 coordinate vectors varying.
If you have vectors for x, y, and z for every purple curve, then why don't you just call rand() to add a tiny bit of noise to it and get the noisy path?

Sign in to comment.

Answers (2)

KSSV
KSSV on 21 Mar 2020
A = [0,0,0] ;
B = [1,1,1] ;
N = 10 ;
x = (B(1)-A(1)).*rand(N) + A(1);
y = (B(2)-A(2)).*rand(N) + A(2);
z = (B(3)-A(3)).*rand(N) + A(3);
X = [A(1)*ones(N,1) x B(1)*ones(N,1)] ;
Y = [A(2)*ones(N,1) y B(2)*ones(N,1)] ;
Z = [A(3)*ones(N,1) z B(3)*ones(N,1)] ;
plot3(X',Y',Z')

  1 Comment

Mauro Tramis
Mauro Tramis on 22 Mar 2020
thanks for your answer, but i wrote wrongly the problem I needed to implement. I added a comment that describe the real problem

Sign in to comment.


Image Analyst
Image Analyst on 21 Mar 2020
What I would do is to do something they do in the movie industry to create textures. It's called Perlin Noise. Google it. It's used to give very natural looking paths and surfaces, like mountains, clouds, water, stucco, wood, etc. Much more natural looking paths than the harsh, erratic paths you'd get simply by calling rand() and adding that noise to your signals.
Basically the way Perlin noise works is you take a very few locations (say 5) on your path (you can start with any existing path or even just a line along the x axis if you want) and add some noise to those few locations. Then you interpolate the other y to go through those locations. This gives you the large scale noise/deviations. Now you take another set of more locations, say 10. Then you add noise to those locations but the noise has lower amplitude than the prior iteration. Then interpolate again. Then just iterate a bunch of times decreasing the spacing between the noise points and decreasing their amplitude. So with each iteration you are adding finer and finer noise (smaller and more detailed). I wrote a demo for you that I think does that and I've attached the demo, perlin_noise.m. I also pin down the end points so that you start and end at the same locations, which is what you said you need. It produces plots such as the one below:
What you could do is use this to create 3 signals: one for x, one for y, and one for z. This will give a smoother, more natural path than if you just simply used rand() to add noise to your signals.
Adapt the code as needed, like build into a function, get rid of fancy plots, or whatever you need.

  1 Comment

Mauro Tramis
Mauro Tramis on 22 Mar 2020
thanks for your answer, but i wrote wrongly the problem I needed to implement. I added a comment that describe the real problem

Sign in to comment.

Sign in to answer this question.