Jump to content

Procedurally calculating angles between vectors using point couds


borbs727

Recommended Posts

Hey everyone,

 

I'm making a plexus and I'd like to get more control over how the lines are built.  Right now I have a min/max prim distance slider working as it should.  I'm having trouble with removing or adding lines based on the angles they're creating with nearby vectors.

 

I'm trying to learn VEX so I can maximize the performance, so if you have any helpful pointers in that regard that would be appreciated too!  I'd really like get away from the nested for loops I've been using.

 

float search_rad = chf("search_rad");
int max_points = chi("max_points");
float max_dist = chf("max_dist");
float min_dist = chf("min_dist");
float max_angle = chf("max_angle");
float min_angle = chf("min_angle");
int ratio = chi("ratio");

vector pos;

// Create arry variable to store founds points in
int foundPts[];

int near_ptnum;
int new_prim;

vector compareVector;

int handle = pcopen(0,"P", @P, search_rad, max_points);

int draw = 0;
float counter = 0;

while( pciterate(handle) ) 
{
    pcimport(handle, "P", pos);
    draw = 0;   
 
    if (@ptnum % ratio == 0) 
    { 
        if(distance(@P,pos) < max_dist) 
        {
            if(distance(@P,pos) > min_dist) 
            {
                pcimport(handle, "point.number", near_ptnum);
                
                if(counter == 0)
                {
                    compareVector = near_ptnum - @P; 
                    counter ++; 
                    draw = 1;
                }
                
                else
                {
                    // Get angle between 2 vectors
                    float get_angle ( vector v1; vector v2 )
                    {
                        return degrees ( acos( dot ( v1/length(v1), v2/length(v2) ) ) );
                    }

                    vector vn = near_ptnum - @P;
                    float vector_angle = get_angle( compareVector, vn );
                    
                    if(vector_angle > min_angle) 
                    {
                        if(vector_angle < max_angle)
                        {
                            if(vector_angle == 0)
                            {
                                draw == 0;
                            }
                            else 
                            {
                                draw = 1; 
                                // Create and set an attribute holding the base points
                                addpointattrib(0, 'angle', vector_angle);
                                setpointattrib(0, 'angle', near_ptnum, vector_angle);
                            }
                        }
                        
                    else draw = 0;
                    }
                }
                
                if(draw == 1)
                {
                    // Get number of near points
                    push(foundPts, near_ptnum);
                    
                    // Create and set an attribute holding the base points
                    addpointattrib(0, 'found_points', foundPts);
                    setpointattrib(0, 'found_points', @ptnum, foundPts);
                    
                    new_prim = addprim(@ptnum,"polyline");
            
                    addvertex(0,new_prim,@ptnum);
                    addvertex(0,new_prim,near_ptnum);
                }
            }
        }
    }
}

Problem:

I go into more detail within the file's sticky notes, but basically:

- I'm getting incorrect values for my angle attrs and I don't know why (see the 2nd image below)

- The angle attr values printed into the console don't match up with the corresponding viewport values from the font sop.

- I'd also like to know if storing the angle data on the point is a good idea, or should I store data on the prims?

 

The 1st image is a diagram showing the functionality that I'd like to get.  When I move the min angle slider up from say 0 degrees to 90 degress, the prims will delete in the order illustrated.  The code would first check the size of the angle, then it would delete (or just not make) the prim that contributes to the least amount of valid angles (valid angles = angles that fall within the min/max threshold).

 

 

File attached, thanks for taking a look!

od_procedurally_calc_vector_angles.hiplc

post-13135-0-31124600-1447278355_thumb.j

post-13135-0-35325700-1447278360_thumb.p

Edited by borbs727
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...