Hi, I have a grid of points that I want to put lines on, but as the x axis increases on the grid, I want the lines to become increasingly complex while maintaining the same length. To get this complexity I would like them to be divided randomly and angled randomly at an increasingly random variable range. So as the x axis increases on the grid, I would like the lines to have more divisions, and I would like the angles they are rotated at in the x y and z axis at each division to have an increasingly random variable so they go from more straight, to more chaotic and all over the place. I have a physical model but I’m having a hard time replicating this effect in grasshopper. Attached is a picture of the model in profile for reference.
What you are looking for is an attractor script.
The further right you go, the larger the domain of the random numbers are used to generate the trees.
could you divide the line randomly and then point the remaining section in a random direction somehow?
Here an example, it is more an idea of what to do with transformation. It is just Grasshopper components + one C# doing transform “addition” from there
The best will be to use a custom method with C#, python, … growing a line with a factor of deviation. It is quite simple to program.
random movement.gh (11.5 KB)
And that component is in Pufferfish now in the Transform tab.
Here is a more good script using C# and some methods. You just have to poulate whatever you want with lines. The length (L) control the total length (Loutput = L * (number of segments +1)) of the ouput curve
You can define for each point a maximum angle of deviation (in radians), you can also define the number of segments for each curve.
It is surely better to make the preview with curve and then adding meshes and colors …
private void RunScript(List<Line> lst_lines, List<double> lst_factors, List<int> lst_segmentsNumber, int seed, ref object A)
{
//Random growth of lines
if (lst_lines == null || lst_lines.Count <= 0) return;
if (lst_factors == null || lst_factors.Count <= 0) return;
if (lst_segmentsNumber == null || lst_segmentsNumber.Count <= 0) return;
//Fill the list if not enough parameters
if (lst_factors.Count < lst_lines.Count)
{
int n = lst_factors.Count;
for (int i = n ; i < lst_lines.Count; i++)
{
lst_factors.Add(lst_factors[n - 1]);
}
}
//Fill the list if not enough parameters
if (lst_segmentsNumber.Count < lst_lines.Count)
{
int m = lst_segmentsNumber.Count;
for (int i = m ; i < lst_lines.Count; i++)
{
lst_segmentsNumber.Add(lst_segmentsNumber[m - 1]);
}
}
//Output DataTree of lines
DataTree<Line> dt_linesCurved = new DataTree<Line>();
Random rnd = new Random(seed);
for (int i = 0; i < lst_lines.Count; i++)
{
List<Line> lst_linesCurved = RandomGrowthLine(lst_lines[i], lst_factors[i], lst_segmentsNumber[i], rnd);
dt_linesCurved.AddRange(lst_linesCurved, new GH_Path(i));
}
A = dt_linesCurved;
}
// <Custom additional code>
/// <summary>
/// Growth randomly a line adding lines rotated randomly to the end of the line
///Each added line will have the same length
///Laurent Delrieu 07/02/2020
/// </summary>
/// <param name="arg_line">Initial line</param>
/// <param name="arg_factor">Max angle (radians) of rotation</param>
/// <param name="arg_segmentsNumber">Number of segments added</param>
/// <param name="arg_rnd">Random function</param>
/// <returns>List of line touching each other</returns>
public List<Line> RandomGrowthLine(Line arg_line, double arg_factor, int arg_segmentsNumber, Random arg_rnd)
{
List<Line> lines_out = new List<Line>();
lines_out.Add(arg_line);
for (int i = 0; i < arg_segmentsNumber ; i++)
{
Line new_line = GetRandomLine(lines_out[lines_out.Count - 1], arg_factor, arg_rnd);
lines_out.Add(new_line);
}
return lines_out;
}
/// <summary>
/// Growth randomly a line adding a line rotated randomly to the end of the line
/// Returned line as the same line as previous
///Laurent Delrieu 07/02/2020
/// <summary>
/// <param name="arg_line">Initial Line</param>
/// <param name="arg_factor">Max angle (radians) of rotation</param>
/// <param name="arg_rnd">Random function</param>
/// <returns>New Line</returns>
public Line GetRandomLine(Line arg_line, double arg_factor, Random arg_rnd)
{
Line line = new Line(arg_line.From, arg_line.To);
line.Transform(Transform.Translation(line.Direction));
Vector3d direction = arg_line.Direction;
Vector3d perpandicular = Vector3d.CrossProduct(Vector3d.XAxis, direction);
if (perpandicular.Length < 1e-12)
{
perpandicular = Vector3d.CrossProduct(Vector3d.YAxis, direction);
}
double angle = arg_rnd.NextDouble() * arg_factor;
line.Transform(Transform.Rotation(angle, perpandicular, line.From));
double rollAngle = arg_rnd.NextDouble() * Math.PI * 2;
line.Transform(Transform.Rotation(rollAngle, arg_line.Direction, line.From));
return line;
}
randow_growth_line_LEGACY.gh (25.0 KB)