# Houdini VEX

From bernie's

## Contents

## 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[0]);
vector b = point(0,"P",pp[1]);
vector c = point(0,"P",pp[2]);
//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[0],x[1],x[2],0,y[0],y[1],y[2],0,z[0],z[1],z[2],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'))
{
addprimattrib(0,'hash', 0, 'int');
}
//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[0] = @ptnum;
sortPoints[1] = neighbours[i];
sortPoints[2] = neighbours[j];
sortPoints = sort(sortPoints);
//create triangle
int prim = addprim(0,'poly');
addvertex(0,prim,sortPoints[0]);
addvertex(0,prim,sortPoints[1]);
addvertex(0,prim,sortPoints[2]);
//generate a 'hash' of the triangle prim, so we can remove duplicates later on
//for points 1,3,0 it will be hash(013) --> 67429030
int rhash = random_ihash(atoi(itoa(sortPoints[0])+itoa(sortPoints[1])+itoa(sortPoints[2])));
setprimattrib(0, 'hash', prim, rhash, 'set');
}
}
}
```