breadbox Posted November 2, 2021 Share Posted November 2, 2021 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? Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted November 2, 2021 Share Posted November 2, 2021 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 Quote Link to comment Share on other sites More sharing options...
breadbox Posted November 2, 2021 Author Share Posted November 2, 2021 (edited) 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 November 2, 2021 by breadbox Quote Link to comment Share on other sites More sharing options...
animatrix Posted November 3, 2021 Share Posted November 3, 2021 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 Quote Link to comment Share on other sites More sharing options...
breadbox Posted November 3, 2021 Author Share Posted November 3, 2021 Awesome! thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.