# Tri Divide

## Recommended Posts

What's the best way to divide a triangle like this (see image) so that the hypotenuse is bisected.  Is there a poly operator that will do this?  or a VEX method?

##### Share on other sites

replacing a triangle by two new ones in VEX:

```int pts[] = primpoints(0, i@primnum);

vector pos_1 = point(0, 'P', pts[1]);
vector pos_2 = point(0, 'P', pts[2]);
vector pos_pt = avg(pos_1, pos_2);

removeprim(0, i@primnum, 1);```

divide_triangles.hiplc

##### Share on other sites

Nice solution but it's not dividing on the correct edge.

I'm trying to do the bisection from the longest edge(hypotenuse) to the vertex adjacent it. so that it will make a new right angle triangle basically.

point numbers on each triangle may also be in random order 0,1,2 or 2,0,1 or 1,0,2 etc so it makes this a little tricky to find the right edge.

##### Share on other sites

Hi,

You can measure the edge lengths and split the largest one:

```int pts [ ] = primpoints ( 0, @primnum );

vector p0 = point ( 0, "P", pts [ 0 ] );
vector p1 = point ( 0, "P", pts [ 1 ] );
vector p2 = point ( 0, "P", pts [ 2 ] );

vector pos [ ] = array ( p0, p1, p2 );

float dists [ ] = array ( );
append ( dists, distance2 ( p0, p1 ) );
append ( dists, distance2 ( p1, p2 ) );
append ( dists, distance2 ( p2, p0 ) );

int sortedindices [ ] = argsort ( dists );
int pt0 = sortedindices [ -1 ];
int pt1 = ( 1 + sortedindices [ -1 ] ) % 3;
int pt2 = ( 2 + sortedindices [ -1 ] ) % 3;

vector center = avg ( pos [ pt0 ], pos [ pt1 ] );

int ptcenter = addpoint ( 0, center );

addprim ( 0, "poly", pts [ pt2 ], pts [ pt0 ], ptcenter );
addprim ( 0, "poly", pts [ pt2 ], ptcenter, pts [ pt1 ] );

removeprim ( 0, @primnum, 1 );```

• 1

Awesome! thanks.

## Create an account

Register a new account