# Tri Divide

## Recommended Posts

replacing a triangle by two new ones in VEX:

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

vector pos_1 = point(0, 'P', pts);
vector pos_2 = point(0, 'P', pts);
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.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×