# Houdini VEX

## Hanging wire (parabola/catanery) ```//takes points and creates hanging 'wire' points between said points, using the catenery formula. Use in a detail wrangle

float curve = ch('curve_factor');                        // > 0, gets close to a flat line when you go above 5
int rez = chi('rez');                                    //number of points to create between given points (assumes the points are at uniform-ish distances)
rez+=1;
for(int i=1;i<npoints(0);i++){
vector a = point(0,'P',i-1);
vector b = point(0,'P',i);
for(int j=1;j<rez;j++){
float lerpV = j*1.0/rez;                         // ( 0 < lerpV < 1 )
vector mix = lerp(a,b,lerpV);
mix.y = mix.y + curve * cosh((lerpV-.5)/curve);
mix.y -= curve * cosh(-.5/curve);
setpointattrib(0,'sort',newpoint,j+(i-1)*rez);   //we'll use this variable later to sort points if we want to add line prims
}
setpointattrib(0,'sort',i,i*rez);                    //same as above, add ordered variable
}
```

## Torus / Helix (Toroidal Helical Coil) ```float t = 1.0*@elemnum/@numelem ;

float completion = ch('completion') * 2 * \$PI;
float coils = ch('coils');

float u = t * completion * coils ;
float v = t * completion ;

float x = cos(v)*(R+r*cos(u));
float y = sin(v)*(R+r*cos(u));
float z = r * sin(u);

@P = set(x,y,z);
```

## List of things to Read

```* Jake rice primUvs / split / greeble: https://github.com/jakericedesigns/Poly-Splitting-Blog
```

## Get primitive angles Calculates the minimum angle (sharp) of each triangle

```//if each prim = triangle

//get the 3 prim points
int pp[] = primpoints(0,@primnum);

//grab their positions
vector a = point(0,"P",pp);
vector b = point(0,"P",pp);
vector c = point(0,"P",pp);

//get the vectors to calculate angle
vector ab = b-a;
vector ac = c-a;
vector cb = b-c;

//get angles from law of cosines: arccos(Ab.Ac) where Ab and Ac are normalized vectors
float angleA = degrees(acos(dot(normalize(ab),normalize(ac))));
float angleB = degrees(acos(dot(normalize(-ab),normalize(-cb))));
float angleC = 180-angleA-angleB;

//@angleC = degrees(acos(dot(normalize(-ac),normalize(cb))));
//@angletotal = @angleA+@angleB+@angleC; // <-- should always be 180!

@minAngle = min(angleA,min(angleB,angleC));
```

## Oriented bounding box matrix transform

Applying https://vimeo.com/214584753 with wrangle: rotates points with given perpendicular vectors expects oriented BB from 'box' as a second input ```vector p0 = point(1,"P",0);
vector p3 = point(1,"P",3);
vector p4 = point(1,"P",4);

vector x = normalize(p3-p0);
vector z = normalize(p4-p0);
vector y = cross(x,z);

matrix m = set(x,x,x,0,y,y,y,0,z,z,z,0,0,0,0,0);
@P = invert (m)*@P;
```

## Plexus like effect Full copypastable code on http://pastebin.com/raw/nB9GLeiZ

Trails can be done with the entagma tutorial: http://www.entagma.com/creating-geometry-with-vex/

```//create an attribute on prims that will store the unique hash so we can remove duplicates later on
if(!hasprimattrib(0,'hash'))
{
}

//fetch the neighbours in an array
int neighbours[] = nearpoints(0, @P, ch('radius'), (chi('neighbours')+1) )[1:];
int neighbourCount = len(neighbours);

//only create triangles if there's more than one neighbour
if (neighbourCount > 1)
{
//for each neighbour, create all possible triangles with current point (ie for 'a' and b,c,d => abc abd acd)
for(int i=0;i<neighbourCount;i++)
{
for(int j=i+1;j<neighbourCount;j++)
{
//create an array with the 3 current points to create a triangle
int sortPoints[];
sortPoints = @ptnum;
sortPoints = neighbours[i];
sortPoints = neighbours[j];
sortPoints = sort(sortPoints);

//create triangle