Bend polyline with VEX expression preserving length

   598   3   0
User Avatar
Member
342 posts
Joined: Dec. 2014
Offline
I'm sure there's a way to do this but the math is eluding me right now. I'd like to bend polylines in Y with a ramp, to simulate drooping from gravity (without running a sim) but I need to preserve their length.

float u = vertexcurveparam(0, i@vtxnum);
float b = chramp('bend', u);
float mask = b * chf('scale');

v@P.y -= mask;

Ideas?
User Avatar
Member
342 posts
Joined: Dec. 2014
Offline
Here I can kind of fake it by multiplying the bend by the dot product of the direction of the lines and an up vector (getting the direction angle as @dir upstream) this keeps downward facing lines from stretching

float u = vertexcurveparam(0, i@vtxnum);
float a = primintrinsic(0, 'measuredperimeter', i@primnum);
float r = fit01(rand(@primnum), 0.5, 1.5);
float b = chramp('bend', u);
vector up = {0, 1, 0};
float d = fit01(dot(up, v@dir), 1, 0);

float mask = b * chf('scale') * a * a * d;

v@P.y -= mask;
User Avatar
Member
169 posts
Joined: Aug. 2017
Offline
float droop_amount = chf("droop_amount");     
float tension = chf("tension");            
int use_ramp = chi("use_ramp");              
float axis_blend = chf("axis_blend");      
int preserve_length = chi("preserve_length");


int prims[] = pointprims(0, @ptnum);
if (len(prims) == 0) return; 
int prim = prims[0]; 

int vtx = vertexindex(0, prim, @ptnum);
int count = primvertexcount(0, prim);


float t = float(vtx) / max(count - 1, 1);


if (use_ramp) {
    t = chramp("droop_ramp", t);
}


vector axis_dir = normalize(lerp({1,0,0}, {0,0,1}, axis_blend));


float arch = pow(t * (1.0 - t), tension);
float dy = -arch * droop_amount;

@P.y += dy;

/*
if (preserve_length) {
    float stretch = 1.0 + abs(dy) * 0.05;
    vector center = getbbox_center(0);
    vector dir = normalize(@P - center);
    @P = center + dir * length(@P - center) * stretch;
}
*/
Conservation of Momentum
User Avatar
Member
342 posts
Joined: Dec. 2014
Offline
Interesting approach, thanks for this
  • Quick Links