How to generate randomly curved and twisted strings in 3D?
SeedRandom[1];
Graphics3D[{RandomColor[], JoinForm["Round"], CapForm["Round"],
AbsoluteThickness[3], BSplineCurve@#} & /@ RandomReal[{-10, 10}, {40, 10, 3}]]
Replace BSplineCurve@#
with Tube @ BSplineCurve@#
to get:
Update: Minimal modification of your code:
SeedRandom[123]
stringPack = ParametricPlot3D[randomStrings[s], {s, -20, 20},
PlotPoints -> 5, MaxRecursion -> 1] /.
Line[x_] :> {Hue @ RandomReal[], Thick, BSplineCurve[x]};
Show[stringPack, 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}]
SeedRandom[123]
stringPack = ParametricPlot3D[randomStrings[s], {s, -20, 20},
PlotPoints -> 3, MaxRecursion -> 1] /.
Line[x_] :> {RandomColor[], Tube @ BSplineCurve[x, SplineClosed -> True]};
Show[stringPack, Axes -> True, Ticks -> None,
AxesStyle -> Opacity[0.25], AxesOrigin -> {0, 0, 0},
SphericalRegion -> True, Method -> {"RotationControl" -> "Globe"},
ImageSize -> {700, 700}]
Play with PlotPoints
, MaxRecursion
and SplineDegree
below to explore various shapes:
SeedRandom[123]
stringPack =
ParametricPlot3D[randomStrings[s], {s, -20, 20}, PlotPoints -> 2,
MaxRecursion -> 2] /. Line[x_] :>
{RandomColor[], Tube@BSplineCurve[x, SplineClosed -> True, SplineDegree -> 2]};
Here is an attempt where you can specify the curvature and torsion.
The start point is chosen at random around the origin. The direction is also random.
With these data the Frenet-Serret formula is integrated by the following function:
randcurve[curvature_, torsion_] :=
Module[{ta, no, r, bi, tors, curv, inir, s, t},
eq = {ta'[s] == curv no[s], no'[s] == -curv ta[s] + tors bi[s],
bi'[s] == -tors no[s], r'[s] == ta[s], r[0] == inir,
ta[0] == inita , no[0] == {0, 1, 0},
bi[0] == {0, 0, 1}} /. {tors -> torsion RandomReal[],
curv -> curvature RandomReal[],
inir -> 0.3 RandomReal[{-1, 1}, 3],
inita -> ((t = RandomReal[{-1, 1}, 3])/Norm[t])};
r /. NDSolve[eq, {ta, no, bi, r}, {s, 0, 5}][[1]]
]
You can the make a table of random curves and plot them. Here I choose a curvature and torsion of 2. You may play with these parameters as well as the parameters used inside the function:
curves[s_] = Table[randcurve[2, 2][s], 20];
ParametricPlot3D[curves[s], {s, 0, 5},
PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]