Jump to content
Sign in to follow this  
Human_vX

How would one get xyzdist of surface based on range of vector directions

Recommended Posts

I hope to get the nearest position on a surface or line that is somewhere along the inverse normal, searching in a range of angles (a cone if you will).

If this can be done in vex that'd be ideal (I've messed around sop loops and group stuff but that as expected gets very slow).

Too aid with the question there is an expertly drawn diagram.

whatdoexamplepaint.png

Share this post


Link to post
Share on other sites

Hi,

You can fire rays for each given point within a cone in the opposite direction of the point normal:

image.thumb.png.842b689e639b846abed6eb5ac4b51c65.png

Here is the VEX code:

int numrays = chi("numrays");
float maxangle = radians ( ch("maxangle") );
float maxdist = ch("maxdist");
int visualize = chi("visualize");

vector phit = 0;
vector uvhit = 0;
float nearestdist = 1e32;
vector nearestp = @P;

for ( int i = 0; i < numrays; ++i )
{
    vector2 u = rand ( i + 4523.4376 + @ptnum + ( @ptnum + 1 ) * 54.21 );
    vector dir = sample_direction_cone ( -@N, maxangle, u );
    
    if ( visualize )
    {
        int pt = addpoint ( 0, @P );
        setpointattrib ( 0, "N", pt, dir );
    }
    
    int pr = intersect ( 1, @P, dir * maxdist, phit, uvhit );
    if ( pr != -1 )
    {
        float dsq = distance2 ( phit, @P );
        if ( dsq < nearestdist )
        {
            nearestdist = dsq;
            nearestp = phit;
        }
    }
    
    if ( visualize )
    {
        int pt = addpoint ( 0, phit );
        setpointattrib ( 0, "P", pt, phit );
    }
}

@P = nearestp;

 

  • Like 2

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
Sign in to follow this  

×