20 views (last 30 days)

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

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')

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.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/512092-create-random-paths-between-two-known-points-in-3d#comment_813521

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/512092-create-random-paths-between-two-known-points-in-3d#comment_813521

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/512092-create-random-paths-between-two-known-points-in-3d#comment_813548

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/512092-create-random-paths-between-two-known-points-in-3d#comment_813548

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/512092-create-random-paths-between-two-known-points-in-3d#comment_813618

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/512092-create-random-paths-between-two-known-points-in-3d#comment_813618

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/512092-create-random-paths-between-two-known-points-in-3d#comment_813649

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/512092-create-random-paths-between-two-known-points-in-3d#comment_813649

Sign in to comment.