# How to add noise to these random straight lines in 3D?

Here's a code that draws a pack of random straight lines in 3D:

Corde[s_, x0_, y0_, z0_, u_, phi_] := {
x0 + s Sqrt[1 - u^2] Cos[phi],
y0 + s Sqrt[1 - u^2] Sin[phi],
z0 + s u
}

x0[n_] := RandomReal[{-10, 10}];
y0[n_] := RandomReal[{-10, 10}];
z0[n_] := RandomReal[{-10, 10}];
u0[n_] := RandomReal[{-1, 1}];
phi0[n_] := RandomReal[{0, 2 Pi}];

Cordes[s_] := Table[
Corde[s, x0[n], y0[n], z0[n], u0[n], phi0[n]], {n, 1, 10}]

Enchevetrement =
ParametricPlot3D[Evaluate@Cordes[s], {s, -20, 20}, PlotPoints -> 2];

Show[Enchevetrement,
PlotRange -> {{-10, 10}, {-10, 10}, {-10, 10}},
Axes -> True,
Ticks -> None,
AxesStyle -> Opacity[0.25],
AxesOrigin -> {0, 0, 0},
SphericalRegion -> True,
Method -> {"RotationControl" -> "Globe"},
ImageSize -> {700, 700}
]


Preview: I would like to make them looking like some kind of natural random walks by adding noise to the lines. The result should be smooth looking (no discontinuities, the curves should stay smooth). The randomness resolution should be an option to increase the paths complexity.

In other words: each straight line should get some random wavy noise.

Take note that I'm using Mathematica 7.0, and I can't upgrade the machine to a newer version of Mathematica. So the code modifications should stay close to the original code, with just a few new simple functions. Nothing fancy.

EDIT: Using kglr's code below, I get what appears to be closed curves, with a pesky straight line as shown below: I need to get rid of these long straight lines...

• try replacing BSplineCurve[RandomReal[{-a, a}, 3] + # & /@ x] with BSplineCurve[RandomReal[{-a, a}, 3] + # & /@ x, SplineClosed -> False]?
– kglr
Nov 30, 2020 at 17:41
• @kglr, I tried this option and it does nothing! The straight line is still there.
– Cham
Nov 30, 2020 at 17:49
• can you try BSplineCurve[Rest@Most[RandomReal[{-a, a}, 3] + # & /@ x]]?
– kglr
Nov 30, 2020 at 17:57
• can you post the output from SeedRandom; ParametricPlot3D[Evaluate@Corde[s, x0[n], y0[n], z0[n], u0[n], phi0[n]], {s, -20, 20}, PlotPoints -> 20][]?
– kglr
Nov 30, 2020 at 21:19

Perhaps

a = 1; pp = 50;

SeedRandom
Enchevetrement =  ParametricPlot3D[Evaluate@Cordes[s], {s, -20, 20},
PlotPoints -> pp, MaxRecursion -> 1];

Show[Enchevetrement /. Line[x_] :> BSplineCurve[RandomReal[{-a, a}, 3] + # & /@ x],
PlotRange -> {{-10, 10}, {-10, 10}, {-10, 10}}, Axes -> True,
Ticks -> None, AxesStyle -> Opacity[0.25], AxesOrigin -> {0, 0, 0},
SphericalRegion -> True, Method -> {"RotationControl" -> "Globe"},
ImageSize -> {700, 700}] Play with a and pp to control the amplitude and frequency to get various shapes: For example, with pp = 200 and a = .3 we get Use a = 1; pp = 200; and replace BSplineCurve[RandomReal[{-a, a}, 3] + # & /@ x] with BSplineCurve[({Abs@#, ##2} & @@ RandomReal[{-a, a}, 3]) + # & /@ x] to prevent bending backward in x direction: • That's very nice! Please, could you elaborate on the #&/@x ? I don't understand this part. Also, on my system, I get a long straight line added to the random noisy lines, like a closing line. I'm unable to get rid of it yet.
– Cham
Nov 30, 2020 at 17:17
• @Cham, the pure function  foo = RandomReal[{-a, a}, 3] + # & (which could be defined alternatively as foo[arg_]:=RandomReal[{-a,a},3}+ arg) is Mapped (/@) on the list x (which is a list of triples).
– kglr
Nov 30, 2020 at 17:25
• Re "long straight line added to the random noisy lines", it may be version/os related. If you update your question with a picture showing the problem, may be someone with version 7 may be able identify a solution.
– kglr
Nov 30, 2020 at 17:28
• Oh no ! This is weird! I get the straight lines if I use Axes -> False, or Axes -> None. Using Axes -> True removes the issue !!
– Cham
Nov 30, 2020 at 22:05
• If I leave the option Axes -> True, but translate out the axes, the issue is back again ! This is odd. Looks like a bug to me.
– Cham
Nov 30, 2020 at 22:14