Jump to content

Tri Divide


breadbox

Recommended Posts

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

Link to comment
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
Link to comment
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
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...