2
$\begingroup$

I am pretty new to blender and I spent a lot of hours on this problem, but I can't figure out a solution.

I have two points following each one a different curve. These curves should represent function-curves, where the x-axis of the curve is the time and the y-axis is the pressure. I would like the two points to move forward on the curves so that their value on the x-axis always remains the same and just the y-value varies between the two points.

In other words I would like the two points to move forward and always stay perfectly aligned the one over the other on the same vertical line, though following different curves.

When I try the path modifier, however, and set the same offset factor for each point on each path, the two points move at a different amount on the x axis and they are not exactly the one over the other anymore. I could use shapekeys and animate each frame separately, but maybe you could help me to find a quicker solution.

$\endgroup$
2
  • 2
    $\begingroup$ i think the follow path constraint is the wrong tool here. You should use drivers or geometry nodes for that task $\endgroup$ Commented Oct 8 at 10:39
  • 2
    $\begingroup$ The most straightforward solution to me is have them move together on the the X axis, and then have it pull up or down to match up with the curve. I don’t know how to do that though. $\endgroup$ Commented Oct 8 at 12:32

2 Answers 2

5
$\begingroup$

Solution with Geometry Nodes

You'll find the blend file at the very end.

Animation of the result

The only way I see how to do this is with geometry nodes, just as Gordon Brinkmann's answer. If you're new to Blender, this is probably not the best moment to dive into this. This is sort of visual programming, powerful but hard to grasp at first.

So here is a solution with geometry nodes. I've tried to make it as user-friendly as possible. You probably don't have to go into the nodes, you can simply use the modifier from the modifier tab. Here are the parameters you can tweak :

Modifier tab

  • Resolution : this is the number of points for one curve. It should be high so that it looks and behave continuous, not discrete.
  • X Position : the x-value you want to input to the curve/functions
  • Curve 1 : select which curve to use as curve 1
  • Curve 2 : select which curve to use as curve 2
  • Object 1 : select with curve to use as point for curve 1
  • Object 2 : select with curve to use as point for curve 2

Warnings

The modifier checks if the curves are functions in the mathematical sense : one x-value should only have one y-value. These warnings don't do anything besides warning you in the modifier tab. You can delete all the red-coded nodes inside the node tree if you don't want it.

In the nodes, I'm using the sign of the x-position of adjacent points. They either go from left to right or from right to left. If a point has the opposite sign, then it means the curve goes back on its steps and thus isn't a mathematical function.

Process

I'll explain briefly how it works, feel free to ask for precisions in comments. In summary we can flatten the curves on the x-axis, find a closest point and de-flatten the curve.

Geometry nodes for 1 set of curve and point

This is the tree for 1 curve and point. It is exactly the same for the other curve and point. First we set the resolution of the curve with the input the user has set. We need both to increase the resolution (number of points between the control points of the curve) and then resample it. This mean the curve goes from having just a few control points to having as many control points as the chosen resolution.

Note : Bézier curve should be easy to compute for the hardware, you could increase the resolution much more than 1024. Rule of thumb, if the curve covers an entire 1920x1080 render, you could set the resolution to 2x the width so around 4000. You'll have 2 points per pixels, probably enough even for fast-rising functions.

Then we can store for each point of the curve, what y-value it has, with an attribute. You can think of it as a variable, each point has a yPosition value we'll use later. Then, we set the y-scale to 0 to flatten the curve on the x-axis.

Then we can find the index of the closest point to the x-value the user has set. For that we need to temporarily convert the curve to a mesh and sample it.

We can now de-flatten the curve. We use the yPosition attribute to move the points back to their original y position.

At last, we retrieve the position of the curve at the corresponding x value (we use the index we found before with Sample Closest). We spawn the object 1 at this location.

Additionnal notes

I've put the 2 curves and 2 objects in separate collections, and hide these collections. So the result you see is only one object containing 2 curves and 2 objects.

There is a 3rd curve that isn't a function, if you want to test the warnings.

The initial geometry of the object isn't use at all. The modifier overrides totally the initial geometry.

Blend file

$\endgroup$
5
  • $\begingroup$ But I understand your setup correctly that you can set the points only at discreet positions so you need a high resolution? No way to use Bézier curves with only a few control points? $\endgroup$ Commented Oct 8 at 17:47
  • $\begingroup$ The input curve can have only 2 control points, but when sampling the curve it snaps to control points. So I need to adjust both the resolution and resample the curve. That's because I'm using Sample Nearest I think. With a Sample Curve you don't need to resample, resolution alone is enough. But I'm not sure it is easily done with that. $\endgroup$ Commented Oct 8 at 17:53
  • $\begingroup$ So but that's what I meant, if you want to follow the input curve more or less exactly you need a high resolution. You cannot directly follow the Bézier curve continuously. I see. That's what I thought, I wanted to do like that as well at first but didn't like to be limited to control points. $\endgroup$ Commented Oct 8 at 17:57
  • $\begingroup$ Yes at the moment to sample I need high resolution on the curve, so lots of control points at that point in the nodes. Note that Bézier curves aren't really continuous (they are $C^0$ but not $C^1$), so never truly possible to follow the curve continuously. Also note that you could go way higher than a resolution of 1024 without any real performance impact. Bézier curves should be cheap to compute I think. $\endgroup$ Commented Oct 8 at 18:02
  • $\begingroup$ Bézier curves have a resolution which you can set too, that's right. But you still can determine Y positions on X values between those resolution points with the Raytrace node in my answer. Technically you could do that with a resampled curve too by calculating be edge connecting the points before and after an intermediate X value, but I simply dismissed that. $\endgroup$ Commented Oct 8 at 18:46
4
$\begingroup$

One way to do this would be to use a Geometry Nodes with a Raycast node. To make this work though, the curves need to have faces. I do that by converting them with a Curve to Mesh node and a simple Curve Line as Profile Curve. Note that the line is extended in Y direction, not Z:

curve to mesh

Now I can use these meshes as Target Geometry for two Raycast nodes. As Ray Direction I set +Y by entering the vector (0, 1, 0). For the Source Position (i.e. from where rays are cast in +Y direction) I use a Combine XYZ node with an initial value of (0, -10, 0). The Y value must be chosen so that going from there into the +Y direction the rays can hit the curves within the given Ray Length (here: 100 m). Finally the Hit Position is used to place two points on the curves.

raycast

If you now animate the X value of the Combine XYZ node, the points will move along the curves sharing the same X location all the time while following the Y location of the curves:

animated x sweep

But be aware that when the X value goes further left than the curves or farther right, the Raycast node misses the curves and the points will move to (0, 0, 0).

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.