# Make Curve In VEX

## Recommended Posts

How can I make curve in VEX? In Documentation I found spline function but I do not understand how to use. I would like to make smooth blend-curve between many lines.

Thanks!

##### Share on other sites

Put all point positions into an array and make parameter "t" slide e.g. from 0 to 1 inside a for loop.

```int steps = chi('steps');
vector all_points[];
resize(all_points, npoints(0));

for (int i = 0; i < npoints(0); i++){
all_points[i] = point(0, "P", i);
}

for(int i = 0; i < steps; i++){
float slide = i / float(steps - 1);
vector pos = spline("catrom", slide, all_points);
}```

Also a simple function for interpolating 4 points to a curve by yourself would be:

```int steps = chi('steps');

vector pt0 = point(0, "P", 0);
vector pt1 = point(0, "P", 1);
vector pt2 = point(0, "P", 2);
vector pt3 = point(0, "P", 3);

for(int i = 0; i < steps; i++) {

float slide = i / float(steps - 1);
vector pos0 = lerp(pt0, pt1, slide);
vector pos1 = lerp(pt2, pt3, slide);
vector ipol = lerp(pos0, pos1, slide);

}```

Edited by konstantin magnus
• 7

##### Share on other sites

Thank you very much Konstantin and Petz! Your method work perfect!

##### Share on other sites

Konstantin would it be possible from your setup to include the first and last points as well and also smoothly close the curve?

##### Share on other sites
2 hours ago, patremblay said:

include the first and last points as well and also smoothly close the curve?

I dont think the spline()-function does this for cubic splines. You can read about it here: http://www.sidefx.com/docs/houdini/vex/functions/spline.html

But you could connect points to a curve and close it with an add-node and resample this to an 'interpolating curve' or a 'subdivision curve'.

Edited by konstantin magnus

##### Share on other sites

Thank you, this reminds me to look for simpler solutions first

##### Share on other sites

There are random existing curves, for instance. When applying a resample node, it adds points evenly. However, I am looking for a way to add points exponentially then add points with even distance.

Is that possible to do it procedurally?

##### Share on other sites

Hope it Helps.

PoI ODforce.hipnc

##### Share on other sites

Hi @tagosaku,

you can shift points by sampling positions from their respective curves with a channel ramp:

```float u = vertexprimindex(0, i@vtxnum) / float(primvertexcount(0, i@primnum) - 1);
v@P = primuv(0, 'P', i@primnum, chramp('shift', u));```

curve_density.hipnc

Edited by konstantin magnus
• 3
• 3

##### Share on other sites

Thank you so much, Konstatin M ! That's very smart and primuv seems to be very powerful. I can proceed my stuff from there.

Tesan, thanks, too. I will use it for different cases in future, too.

##### Share on other sites
On 4/3/2020 at 6:29 AM, konstantin magnus said:

Hi @tagosaku,

you can shift points by sampling positions from their respective curves with a channel ramp:

```
float u = vertexprimindex(0, i@vtxnum) / float(primvertexcount(0, i@primnum));
v@P = primuv(0, 'P', i@primnum, chramp('shift', u));```

well this trumps my curveu bias HDA royally !!!

• 1

## Create an account

Register a new account