Jump to content
Sign in to follow this  
breadbox

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?

 

 

 

Image 455.png

Share this post


Link to post
Share on other sites

Hi bradon,

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);

int pt_add = addpoint(0, pos_pt);
int prim_01 = addprim(0, 'poly', pts[0], pts[1], pt_add);
int prim_02 = addprim(0, 'poly', pts[0], pt_add, pts[2]);

removeprim(0, i@primnum, 1);

 

divide_triangles.hiplc

Share this post


Link to post
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.

 

Edited by breadbox

Share this post


Link to post
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 );

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×