# How to modify line so that each point is lower than previous?

Let's say you have a spline, indexes go from top to bottom:

I want to make each point in the line lower than the previous, so that line always goes down, and never goes up. I made this node setup, which looks at previous point and lower current point if it is higher than previous one:

This is works for that line:

But not for that, because 2 points in a row is higher:

How to make it work for every possible line?

• yes, just use animation nodes ;) Oct 18, 2022 at 14:05
• this [1]: i.sstatic.net/k5sP3.png works, but i think this is not what you want? Oct 18, 2022 at 14:22
• No, @Chris, the curve is created already (by shortest path), now I want to edit it Oct 18, 2022 at 19:34

Unfortunately, there are no loops in Geometry Nodes...

Even with Accumulate Field you will not be able to achieve a solution here.

But with the following tricks you can achieve the goal:

# Blender <= 3.3

• First, capture the lowest position on the Z-axis as well as the extent on the Y-axis (or X-axis, depending on how your line is oriented).

• Then create a grid (2x2 points) which corresponds to the length of your curve.

• Transform this grid so that it starts at $$0$$ on the Y-axis, and instantiate it at each point.

This will give you the following strange looking result:

• Then combine the lowest Z-position with the X/Y-positions of each point, and use that as the Source Position for a raycast.

This raycast should point up to the grids and give you back as Hit Position the position you are looking for.

(Blender <=3.3)

# Blender 3.4+

With Blender version 3.4 the node Points of Curve was added, which returns the index of a point based on a given weighting.

For this, however, the curve must be duplicated. As weighting the Z-position is passed here. If the index of the point is higher than the spline index, an infinitely large value is used as weighting:

The whole thing again slightly modified and the direct passing of the final position:

And here is another modification, same concept, but with shortened curves:

(Blender 3.4+)

• Good job! I was trying raycast, but was raycasting to the left (previous points) which were extruded, the logic wasn't quite right... As for Accumulate Field node, it doesn't work because you can't compare Accumulated input with output to store back in the field... I was thinking about sorting, but raycasting will definitely be more performant. Oct 21, 2022 at 15:25
• Very neat! IMHO, the economy of the method is quite pretty :) Oct 23, 2022 at 17:05

Here's a solution using multiple stages to determine the minimum for all points:

This problem can't be solved locally (looking at just the next/previous points). For each point N it needs to compute the minimum of all the points 1 to N-1. Naively this would require a loop, but it can be done a bit more elegantly with a divide-and-conquer strategy in O(log(N)) time.

You already have the first step, finding the minimum between a point and the next. If you scale that up by a factor of 2 you can clamp up to a distance of 2 points, then 4, 8, 16, etc. That's because the minimum of the union of two point sets is the same as the lesser of the minima of both sets (duh). We can successively combine larger sets and avoid computing the same minima over and over.

The file handles up to 64 points atm. Just add more stages at the bottom of the tower if necessary.

• WHERE ARE WE GOING TO GET LOOPS IN GEONODES?! Sadly copy-pasting nodes is the way to go in many cases... In this case I think I'll figure something out in a moment, but still life would be much easier with loops... Oct 21, 2022 at 13:19
• When* - my grammar is bad when I'm angry Oct 21, 2022 at 13:28
• @MarkusvonBroady We want loops! We want loops! We want loops! We... ;-) Oct 21, 2022 at 15:13