Jump to content
dolexd

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. :(

 

Thank you for your help.

primitiveSelect.thumb.PNG.7923dac916cd5608ad0029b4c77e37a7.PNG

Share this post


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

LiWosxB.png

Share this post


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

×