Jump to content
Sign in to follow this  
jonidunno

Orient away from object

Recommended Posts

Hello,
I'm trying to wrap my head around this... how could I have the orient of nearby points (possibly with a falloff) point avoid (point away from) a nearby object?

My setup right now consists of copied points on a surface and would love them to directional rotate away from the sphere as it gets close to them... here is a scene file if anyone wants to take a stab!

Capture.thumb.PNG.96e66e86590eb98d45547e245ef5b479.PNG

 

pointAway01.hiplc

Share this post


Link to post
Share on other sites

newton's law and try to use this it works
 

function float Kernel(vector r ; float h){
    float q = length(r);
    q /= h;
    float factor =  1.0f / (PI  * h * h * h );

    
    if( q>0 && q<=1){
        float right =  1.0f - 1.5f  * (q * q) * (1.0f - q/ 2.0f) ;    
        return factor * right;
    }
    if(q >1 && q <=2 )
    {
        float left = factor / 4.0f;
        float right = pow(2.0f - q , 3);
        return left*right;
    }
    
    if(q>2)
    {
        return 0;
    }
    return 0;
}


function vector GradKernel(vector r; float h){
    float q = length(r);
    q /= h;
    vector dir = normalize(r);
    float factor =  1.0f / (PI  * h * h * h );
    vector retgrad = set(0,0,0);
    
    if( q<=1){
        retgrad = dir * (factor / h) * (-3.0 * q + 2.25f * q*q);
    }
    
    if( q<2){
        retgrad = dir * (-0.75f * (factor / h) * pow((2.0f - q),2) );
    }
    
    return retgrad;

}

float h = chf("h");
@P.y = Kernel(@P, h);

@N = GradKernel(@P, h);


 

NewtonsLaw.hiplc

news.jpg

Edited by Librarian
  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites
1 hour ago, Librarian said:

newton's law and try to use this it works
 


function float Kernel(vector r ; float h){
    float q = length(r);
    q /= h;
    float factor =  1.0f / (PI  * h * h * h );

    
    if( q>0 && q<=1){
        float right =  1.0f - 1.5f  * (q * q) * (1.0f - q/ 2.0f) ;    
        return factor * right;
    }
    if(q >1 && q <=2 )
    {
        float left = factor / 4.0f;
        float right = pow(2.0f - q , 3);
        return left*right;
    }
    
    if(q>2)
    {
        return 0;
    }
    return 0;
}


function vector GradKernel(vector r; float h){
    float q = length(r);
    q /= h;
    vector dir = normalize(r);
    float factor =  1.0f / (PI  * h * h * h );
    vector retgrad = set(0,0,0);
    
    if( q<=1){
        retgrad = dir * (factor / h) * (-3.0 * q + 2.25f * q*q);
    }
    
    if( q<2){
        retgrad = dir * (-0.75f * (factor / h) * pow((2.0f - q),2) );
    }
    
    return retgrad;

}

float h = chf("h");
@P.y = Kernel(@P, h);

@N = GradKernel(@P, h);


 

NewtonsLaw.hiplc

news.jpg

 

Thanks! I will take a look appreciate you taking to the time to look.

 

 

Share this post


Link to post
Share on other sites

Hi jon,

this is how you could map distance and direction towards a surface into an orient attribute:

float dist_min = chf('min_distance');
float dist_max = chf('max_distance');
float angle_max = chf('max_angle');

vector pos = minpos(1, v@P);
float dist = distance(pos, v@P);
vector dir = normalize(pos - v@P);

float mask = 1.0 - smooth(dist_min, dist_max, dist);
float angle = radians(angle_max) * mask;
vector axis = normalize(cross(dir, v@N));

p@orient = quaternion(angle, axis);

image.png.7f8a7ad600c5ced2fa88f36b9cceb87b.png 

orient_away.hiplc

  • Thanks 1

Share this post


Link to post
Share on other sites
On 9/10/2021 at 1:38 AM, konstantin magnus said:

Hi jon,

this is how you could map distance and direction towards a surface into an orient attribute:


float dist_min = chf('min_distance');
float dist_max = chf('max_distance');
float angle_max = chf('max_angle');

vector pos = minpos(1, v@P);
float dist = distance(pos, v@P);
vector dir = normalize(pos - v@P);

float mask = 1.0 - smooth(dist_min, dist_max, dist);
float angle = radians(angle_max) * mask;
vector axis = normalize(cross(dir, v@N));

p@orient = quaternion(angle, axis);

image.png.7f8a7ad600c5ced2fa88f36b9cceb87b.png 

orient_away.hiplc

Hey Konstantin, 

Appreciate it!  

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  

×