# Selecting primitive based on angle

## Recommended Posts

Hello,

I am trying to select two primitives (105 - 106 from the image attached) based on the angle but I am not sure how. I have tried the group and delete but I can't get it to work. Can anyone please help? Since the primitive number changes based on an external attribute (height), I can't just select these two and group them.

##### Share on other sites

Hi,

You can first group the edges using a Point Wrangle:

```float getAngleBetweenVectors ( vector v0; vector v1 )
{
vector v0n = normalize ( v0 );
vector v1n = normalize ( v1 );
return atan2 ( length ( cross ( v0n, v1n ) ), dot ( v0n, v1n ) );
}

int pts [ ] = neighbours ( 0, @ptnum );
foreach ( int pt; pts )
{
if ( @ptnum < pt )
continue;

int prs [ ] = { };

int firsthedge = pointhedge ( 0, @ptnum, pt );
int count = hedge_equivcount ( 0, firsthedge );
if ( count == 2 )
{
int hedge = firsthedge;

do
{
int pr = hedge_prim ( 0, hedge );
if ( pr != -1 && find ( prs, pr ) < 0 )
append ( prs, pr );

hedge = hedge_nextequiv ( 0, hedge );
}
while ( hedge != firsthedge );

vector n0 = primuv ( 0, "N", prs [ 0 ], 0.5 );
vector n1 = primuv ( 0, "N", prs [ 1 ], 0.5 );

float angle = getAngleBetweenVectors ( n0, n1 );
if ( angle >= radians ( ch("minangle") ) )
setedgegroup ( 0, chs("vex_selectiongroup"), @ptnum, pt, 1 );
}
}```

Then convert this edge group into a primitive group using a Primitive Wrangle after setting the Group parameter to the resulting edge group:

`i@group_newprims = 1;`

##### Share on other sites

Hey Thanks,

I will try this out.  I am still new to programming in VEX and this is good to run through line by line. Hopefully I am able to follow through.

Thanks,

##### Share on other sites

If you have an attribute, you can group using that attrib

if(@attrib>x){

i@group_groupcustomname=1;

}

##### Share on other sites

• 2 weeks later...

Great. Thanks a lot. This helps.

## 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.

×
×